|
Learning objectives:After completing this project, you should be able to:
Items in red are learning objectives for this part of the project. |
Group work
| BasicGUIObjects report
| Time limit
|
BasicGUIObjects. BasicGUIObjectsReport.txt, placing it in the docs subfolder of your BasicGUIObjects project. BasicGUIObjectsReport.txt file. You will use it to record your answers to the questions in all of the parts of this exercise. Start the report with an appropriate title, your names, the date, and a heading to indicate the beginning of Part 1.BasicGUIObjects project, calling the module BasicGUIObjects, spelled just like that. BasicGUIObjects project to your new CVS module. JFrame ClassJFrame class. Add the necessary import statement so that the project compiles. BasicGUIObjects extends JFrame. What is the inheritance hierarchy of the JFrame class (Use JDK Help)? main method, declare and initialize a new BasicGUIObjects object called mainFrame. This is the last change that you should make to the main method for Part 1 of this exercise. mainFrame object has many methods, including setVisible, setDefaultCloseOperation, setTitle, setSize, setLocation, and getContentPane. Where are those five methods defined? BasicGUIObjects constructor with no parameters. CSSE 120 Acrobat Project -- Winter 2003-2004 Version". // Estimated height in pixels of the title bar
public static final int TITLE_BAR_HEIGHT = 20;
// Height in pixels of the panel with the add controls
public static final int ADD_PANEL_HEIGHT = 40;
// Height in pixels of the panel with the exit button
public static final int EXIT_PANEL_HEIGHT = 40;
// Number of supported types of Acrobats
public static final int ACROBAT_TYPES = 5;
// Total height in pixels of the application's window
public static final int FRAME_HEIGHT =
TITLE_BAR_HEIGHT
+ ADD_PANEL_HEIGHT
// + ACROBAT_TYPES * AcrobatPanel.ACROBAT_PANEL_HEIGHT
+ EXIT_PANEL_HEIGHT
+ ( ACROBAT_TYPES + 3 ) * ( new FlowLayout() ).getVgap();
// Width in pixels of the application's window
public static final int FRAME_WIDTH = 450;
FRAME_HEIGHT, and the width to FRAME_WIDTH.Container ClassContainer object import statement. In earlier versions of Java, the AWT classes were used exclusively for GUI applications. The Swing classes were added in Java 2 SDK 1.2. They provide improved portability and greater functionality. In general, if a Swing class can do what you need, you should use it. Only use AWT classes for things that don't have Swing counterparts.Color class has public fields red and RED. Either one will work. Note that the window will be sort of ugly for now, but it will look better by the time you're finished. JButton ClassJButton object called exitButton. Initialize it with the String "Exit".exitButton to the content pane.pane.setLayout(new FlowLayout( ));
Container to which you're adding it?Add Acrobat". JLabel ClassJLabel object. Initialize it with the String "Acrobat Name:".JLabel object to the content pane.JTextField ClassJTextField object. Initialize it to have 10 columns.JTextField object to the content pane.JPanel ClassAddPanel that extends the JPanel class.BasicGUIObjects class, create a new AddPanel object and add it to the content pane. AddPanel class a constructor with no parameters.AddPanel constructor:
this.setPreferredSize(
new Dimension(
BasicGUIObjects.FRAME_WIDTH,
BasicGUIObjects.ADD_PANEL_HEIGHT
)
);
AddPanel constructor. Instead of adding the objects to the content pane (which is not visible in the AddPanel constructor), add them to the AddPanel object (i.e. instead of pane.add use this.add). If necessary, rearrange statements so that the label appears to the left of the text field, which then appears to the left of the button. ACROBAT_NAME_LENGTH with the value 10, and use it to control the size of the text field. AcrobatPanel that extends the JPanel class. Give it a constructor with a String parameter called theLabel. ACROBAT_PANEL_HEIGHT with the value 100. this.setPreferredSize(
new Dimension( BasicGUIObjects.FRAME_WIDTH, ACROBAT_PANEL_HEIGHT)
);
setSize instead of setPreferredSize? Isn't that annoying? JLabel object. Initialize it with theLabel, and add it to the panel.AcrobatPanel object with the label: "BasicAcrobat Objects". Add it to the content pane between the AddPanel object and the exit button. Do the same for DoublingAcrobat, ProudAcrobat, AcrobatWithBuddy, and Choreographer objects. Uncomment the line in the middle of the definition of the constant FRAME_HEIGHT. FlowLayout defaults to centering objects left-to-right within the container. Change the AcrobatPanel class so that it left justifies it's objects:
this.setLayout( new FlowLayout( FlowLayout.LEFT ));
BasicGUIObjects1.