Intermediate Java

Week 1 Review Questions

What does GUI stand for?
Graphical User Interface
What is JFrame?
A JFrame is the object that represents a window on the screen.
Where do Swing components reside?
Swing Components go on the JFrame window.
How can you make a button look like a Windows button?
You need to adjust the look on the button (which looks like a Java button on my computer) by using the "setLookandFeel" method of the UIManager object classes in the javax.swing package.
How do you get a button to do something specific when the user clicks it?
You need to tell the button that you are listening for something to happen to the button (an event)- i.e. you need to implement a listener interface, called an ActionListener. Do this by adding "implements ActionListener" to the name of the GUI class as you define it.
In the main method of the GUI class, you need to add the Event-type Listener to the button, so the button knows you are interested in hearing about button events.
You need to write a method in your GUI class that tells what will happen when the event occurs.
When the event happens, the button will call the method in your Action Listener, by sending the event as the argument to the method.
What is event-handling?
Event handling is the calling of the method that uses the event as an argument. You define a method in your GUI class that uses an event as an argument. (For example, the clicking of a button may be an event, or the pressing of a key.) The method describes what happens when the event occurs. When the key is pressed, let's say, the event is sent to the method as an argument, and the method plays out its activities. You can have several different event handlers - one for each different event.
How do you add widgets to the JFrame?
You create your widget, and then you add it to one of the five sections of the contentPane of your JFrame. ( using the code frame.getContentPane().add(BorderLayout.SOUTH ( or NORTH,EAST WEST, CENTER), widgetName);
What does the listener interface allow you to do?
The listener interface lets you tell any widget that could trigger an event that you are interested in its event, and want to know about it.
Can you draw a .gif directly on to a widget?
Yes.
What is a purpose of inner classes?
Inner classes let you handle two or more different events in different ways. One outer class can have several inner classes. Several inner classes can share the same interface, and each can implement the interface differently from the others.
True or false: an inner class instance must be tied to an outer class instance?
True