Java Reference
In-Depth Information
Here's the code for the outline of the FontDialog class:
// Class to define a dialog to choose a font
import java.awt.*;
import javax.swing.*;
public class FontDialog extends JDialog {
// Constructor
public FontDialog(SketcherFrame window) {
// Code to initialize the data members...
// Code to create buttons and the button panel...
// Code to create the data input panel...
// Code to create font choice and add it to the input panel...
// Code to create font size choice and add it to the input panel...
// Code to create font style checkboxes and add them to the input panel...
// ...and then some!
}
private Font font;
// Currently selected font
}
Directory "Sketcher 5 displaying a font dialog"
You add more data members shortly, but at least you know you need the one that is shown here. You can
initialize the font member from the font that is stored in the SketcherFrame object:
public FontDialog(SketcherFrame window) {
// Call the base constructor to create a modal dialog
super(window, "Font Selection", true);
font = window.getFont(); // Get the current font
// Plus the code for the rest of the constructor...
}
Directory "Sketcher 5 displaying a font dialog"
You call the base class constructor and pass the window object to it as the parent. The second argument is
the title for the dialog, and the third argument determines that the dialog is modal. The getFont() method
returns the font stored in the window object, so this is the default setting the first time you open the dialog.
Search WWH ::




Custom Search