TIJ-3rd-edition-html, 14: Creating Windows & Applets

45 terms by lghrants 

Create a new folder

Advertisement Upgrade to remove ads

Title: Thinking in Java, 3rd ed. Revision 4.0 Author: Bruce Eckel

The original goal of the GUI library in Java 1.0 was to allow the programmer to build a GUI that looks good on all platforms. That goal was not achieved. Instead, the Java 1.0 _____ _____ _____ produced a GUI that looked equally mediocre on all systems.

Abstract Windowing Toolkit (AWT)

The Java 1.0 AWT situation improved with the introduction of the Java 1.1 AWT _____ _____, which takes a much clearer, object-oriented approach, along with the addition of JavaBeans, a component programming model that is orented toward the easy creation of visual programming environments.

The Java 1.0 AWT Event Model

Java 2 (JDK 1.2) finished the transformation away from the old Java 1.0 AWT by essentially replacing everything with Java Foundation Classes (JFC), the GUI portion of which is called _____.

Swing

This rich set of easy-to-use, easy-to-understand JavaBeans can be dragged and dropped (as well as hand programmed) to create a Java GUI that you can (finally) be satisfied with. What is it?

The Java Foundation Classes GUI portion, Swing

Java has the ability to create _____, which are little programs that run inside a web browser.

Applets

Programming within an _____ is so restrictive that it's often referred to as being "inside the sandbox", since you always have someone--that is, the Java run-time security system--watching over you.

An applet

Java applets are built using an application framework. You inherit from the class _____ and override the appropriate methods.

The JApplet class

One of the four basic methods you'll override in the javax.swing.JApplet class is _____, which is automatically called to perform first-time initialization of the applet, including component layout.

javax.swing.JApplet.init()

One of the four basic methods you'll override in the javax.swing.JApplet class is _____, which is called every time the applet moves into sight on the web browser to allow the applet to start up its normal operations (especially those that are shut off by stop()).

javax.swing.JApplet.start()

One of the four basic methods you'll override in the javax.swing.JApplet class is _____, which is called every time the applet moves out of sight on the web browser to allow the applet to shut off expensive operations. Its also called right before destroy().

javax.swing.JApplet.stop()

One of the four basic methods you'll override in the javax.swing.JApplet class is _____, which is called when the applet is being unloaded from the page to perform final release of resources when the applet is no longer used.

javax.swing.JApplet.destroy()

Note that applets are not required to have a _____ function. You put any startup code into init().

main()

To create an applet that can be run from the console command line, you simply add a _____ method to your applet that builds an instance of the applet inside a JFrame.

main()

When you draw an applet to a JFrame, you must call it's _____ method, or you won't see anything on the screen.

javax.swing.JFrame.setVisible()

The javax.swing.JFrame's default close behavior is to do nothing, so if you don't call the _____ method and define a close action, the application won't close.

javax.swing.JFrame.setDefaultCloseOperation()

What can you pass to the javax.swing.JFrame.setDefaultCloseOperation() method to have your application exit when the close button is clicked?

javax.swing.JFrame.EXIT_ON_CLOSE

Making a button is quite simple: you just call the _____ constructor with the label you want on the button.

javax.swing.JButton

Before any elements are placed on the a content pane, it can be given a _____ _____, which is a definition for the way a pane implicitly decides where to place controls on the form.

A layout manager

To register your interest in when a button is pressed, you call the javax.swing.JButton's _____ method to attach an java.awt.event.ActionListener.

javax.swing.JButton.addActionListener()

The javax.swing.JButton.addActionListener() method expects one argument that is an object that implements the _____ interface, which contains a single method called actionPerformed().

java.awt.event.ActionListener

The java.awt.event.ActionListener interface defines a method actionPerformed() that takes one argument, of type _____, which contains all the information about the event and where it came from.

java.awt.event.ActionEvent

Which javax.swing component captures user-input text, in a single line?

javax.swing.JTextField

Which javax.swing component is like a JTextField, but allows for multi-line input?

javax.swing.JTextArea

To enable scroll capability for a javax.swing.JTextArea that grows too large to fit inside a JFrame, you wrap it in a _____.

javax.swing.JScrollPane

The way components are placed on a form is controlled not by absolute positioning but by a _____ _____ that decides how the components lie based on the order that you add() them.

A layout manager

The javax.swing.JApplet, JFrame, JWindow, and JDialog can all produce a java.awt.Container with the _____ method that can contain and display java.awt.Components.

getContentPane()

In java.awt.Container there's a method called _____ that allows you to choose a different layout manager.

java.awt.Container.setLayout

Java applets use a default layout manager: the _____. Without any other instruction, this takes whatever you add() and places it in the center, stretching the object all the way out to the edges.

java.awt.BorderLayout

Which Java layout manager "flows" components onto the form, from left to right until the top space is full, then moves down a row and continues flowing.

java.awt.FlowLayout

Which Java layout manager allows you to build a table of components where, as you add them, they are placed left-to-right and top-to-bottom in the grid?

java.awt.GridLayout

In the java.awt.GridLayout constructor you specify the number of _____ and _____ you need, and these are laid out in equal proportions.

You specify the number of columns and rows

Which Java layout manager provides you with tremendous control in deciding exactly how the regions of your window will lay themselves out and reformat themselves when the window is resized, but is also the most complicated layout manager and as such is quite difficult to understand?

java.awt.GridBagLayout

It is possible to position graphical components absolutely by doing what two things?

Set a null layout manager for your java.awt.Container, with setLayout(null), and call setBounds() or reshape() for each component, passing a bounding rectangle in pixel coords.

Because people had so much trouble understanding and working with java.awt.GridBagLayout, Swing also includes _____, which gives you many of the benefits of GridBagLayout without the complexity.

javax.swing.BoxLayout

Which Swing layout manager allows you to control the placement of components either vertically or horizontally, and to control the space between the components using something called "struts and glue."

javax.swing.BoxLayout

The constructor for javax.swing.BoxLayout is a bit different than the other layout managers--you provide the _____ that is to be controlled by the BoxLayout manager as the first argument, and the _____ of the layout as the second.

java.awt.Container first, and the direction of the layout second (BoxLayout.X_AXIS/Y_AXIS)

To simplify usage of javax.swing.BoxLayout, there's a special container called _____ that uses it as it's native layout manager.

javax.swing.Box

Once you have created a javax.swing.Box object, you use it by passing it as the second argument when adding components to the _____ _____.

The content pane.

When using javax.swing.BoxLayout, you add space (measured in pixels) between components by using _____.

Struts

Struts separate components by a fixed amount, but _____ is the opposite; it separates components by as much as possible. Thus it's more of a "spring" (the design on which this was based was called "springs and struts," so the choice of term is a bit mysterious).

Glue

A strut works in one direction, but a _____ _____ fixes the spacing between components in both directions.

A rigid area

You should be aware that _____ _____ are a bit controversial. Since they use absolute values, some people feel that they cause more trouble than they are worth.

Rigid areas

In the Swing event model, a component can initiate (a.k.a. "_____") and event; each type of which is represented by a distinct class/

It can "fire" an event

When a Swing event is fired, it is received by one or more "_____", which act on that event.

Listeners

To prevent you from having to implement ALL the methods of a particular listener interface, some (but not all) of the Swing listener interfaces that have more than one method are provided with _____.

Adapters (each of which provides you with default empty methods for each of the interface methods)

Please allow access to your computer’s microphone to use Voice Recording.

Having trouble? Click here for help.

We can’t access your microphone!

Click the icon above to update your browser permissions above and try again

Example:

Reload the page to try again!

Reload

Press Cmd-0 to reset your zoom

Press Ctrl-0 to reset your zoom

It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

Please upgrade Flash or install Chrome
to use Voice Recording.

For more help, see our troubleshooting page.

Your microphone is muted

For help fixing this issue, see this FAQ.

Star this term

You can study starred terms together

NEW! Voice Recording

Create Set