Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

29 Cards in this Set

  • Front
  • Back

What's the difference between procedural programming and event-driven programming?

Procedural Programs: Program runs from top to bottom of code.

Event Driven Programs: Program responds to user controls with objects such as text fields, buttons, menus etc. Via mouse/keyboard.

What's the difference between "heavyweight" components of the JDK1.0/1.1 versions and the "lightweight" Swing components of Java 1.2?

1.0/1.1: Lowest common denominator components that were supported by all OS's Java would run on at the time. Heavyweight because of how heavily they depended on the platform to render windows components on the screen. Different look and feel on each platform.

1.2: Swing package: more components, improved and more powerful. Lightweight for relying much less on the underlying OS. They do much more on their own rather than making calls to the OS to do it for them. They look and behave the same way across all OS's.

Concept of container object, what it is used for, and some examples of container objects in the Swing library.

To hold components such as buttons, labels, textfields etc. We need to hold them in a container object. Three examples include:

JWindow: Container that can be displayed anywhere on the desktop. No title bar, window-management buttons, or trimmings associated with a JFrame.

JFrame: Top level window with a title and border.

JPanel: General purpose container for lightweight components.

See Java Docs tutorials on in depth info on these

Concept of component objects, what they are used for and some examples we have used

Components are to be interacted with by the user running the program. Examples Include:

JButton: Self Explanatory
JRadioButton: This is too
JOptionPane: So is this!
JScrollBar: I bet this is a scroll bar

Basic Anatomy of the Swing JFrame Object

From Top to bottom

Title Bar: Where one might find the title
JRootPane: Holds contents of the JFrame
JLayeredPane: holds any MenuBar object and can sit on top of a JRootPane
ContentPane: Sits on JRootPane and holds components

How to create a JFrame object of a given size and set its title bar text.

import javax.swing.*;

public class Whatever

public static void main(String[] args){

JFrame frame1 = new Jframe("I've been Framed!");






Difference between JFrame and JPanel

JFrame: Commonly used for stand alone applications. Needs inner frames for different operations/purposes
JPanel: General purpose container, more commonly for more complex operations/applications. One Panel can hold many operations.

How to add JButtons to JFrame or JPanel

//Make Button

JButton redBtn = new JButton("Red");

//Add Button

What is an anonymous component object, and how might we add one to a container?

A component without being identified with a variable
this.add(new JLabel("text"));

How do you size and centre a JFrame in the middle of the monitor?

this.setSize(x, y);


How the screen co-ordinate system works, and how it is used to position objects on the monitor?

(0,0) starts at the top left and to the right and down from there.

How does the RGB 24 bit color model work to create different colors?

Each color is represented by 8 bits (R,G,B)

What is a memory leak, and how is Java set up to avoid them?

Triggered from Garths C class
A memory leak is when memory is not freed after an object is no longer in use.

Java is set up to avoid this with it's Java Memory Management. Its Garbage Collection thread looks for objects no longer in use and frees the memory

How does one ensure that one closes a JFrame, so it does not stay in memory?


What is a layout manager, and what is it used for?

Layout managers arrange and position components within the frame/panel

What are the benefits of using a layout manager to position components within a container?

Looks ok on different resolutions and resizing,

How do you create a layout manager object and assign it to a container object?

this.setLayout(new GridLayout());

Three examples of layout managers we have used in class code and describe how each one arranges components in a container

Flowlayout: Arranged from left to right and top to bottom
BorderLayout: Divides container into five zones: NORTH, SOUTH, EAST, WEST and CENTER

GridLayout: Specify grid of rows and columns, components will fill a row before starting the next one

How does the event delegation model work with components in the Swing classes of Java?

It means the component itself is not responsible for handling an event, and it is instead to an event handler.

What is the difference between a source object and an event handler?

The source is a component or container that is being changed or interacted with, the event handler is the object that waits for that interaction to occur and creates the action based on how the event is defined.

What exactly is an event in Java and how does it originate?

The event is an object that is created when the user does something like press a JButton.

What is a listener, and what does it do?

An object that gets assigned to a component to define and handle events.

Event Object examples, namely ActionEvent, MouseEvent, ChangeEvent, KeyEvent

ActionEvent: Jbutton press, radioButton selection

MouseEvent: Mouse push, release

ChangeEvent: Changes in components (text in box changed etc.) ???

KeyEvent: Key Presses/Combinations

How does one register a listener for a component, such as a JButton, JTextField, JSlider, JMenu, JPanel or JFrame?

MaryPoppins btnListener = new MaryPoppins();

private class MaryPoppins implements ActionListener


public void actionPerformed(ActionEvent ev)



What is an adapter class and how is it useful to the coder?

Stolen from Dan Maclam without permission:Adapter is a pattern that provides default (often empty) implementation of interface or abstract class. For example MouseAdapter provides empty implementation of MouseListener interface.

What is an inner class used for, and how do we avoid scope problems when using inner classes as event handlers?

I think we only used them for ActionListeners in our examples. To avoid scope problems, just declare in classwide scope in the outer class.

Explain the three coding options for handling events: using the host class, writing an inner class, or using an anonymous inner class

Is there really anything else here to explain?

What is the difference between how JRadioButtons work as compared to JCheckBoxes

Radio buttons are mutually exclusive and need a button group, while you can select more than one check box.

What is logical grouping of JRadioButtons, and what is it used for?

It is to make sure that JRadioButtons are mutually exclusive and only one can be selected