In java swing applications, windows are instances of the
JFrame class. In
this lab you will write a program that creates a JFrame and adds user interface
components including menus, buttons, text areas, check boxes, and radio buttons. When
you have completed all the exercises, your program should open a window that looks
like the sample solution shown below:
Add code to the main method to create and display an empty Order Placement window. It should have "Order Placement" in the title bar, and the rest of the window should be empty. You will need to use the JFrame constructor method that takes a String (specified in quotation marks) as a parameter.
You will need to set the frame's size to something reasonable and
set its visibility to
true so it will show up on the screen. This
is accomplished by sending
To make the close box work, send a
message, passing a parameter to indicate what should happen when the
window closes. You should supply the
You should now be able to test your code and see a window open on the screen.
JMenuBarobject using the default (no parameter) constructor for JMenuBars. Create a
JMenuobject for a "File" menu using the JMenu constructor that takes a String parameter for the menu name. Use the
addmethod to add the file menu to the menu bar. Finally, use the
setJMenuBarmethod to set your JFrame object's menu bar to the one you created. Now test your code.
JMenuItemfor a "Quit" item using the JMenuItem constructor that takes a String parameter for the menu item. Use the
addmethod of the
JMenuclass to add the Quit item to your File menu. Test your code.
setLocationmethods that all user interface components inherit from the
addmessage to add the component to the frame.
setSelectedmessage, passing the parameter value
ButtonGroup. Create a
ButtonGroupobject and send it
addmessages to add the two radio buttons to the group.
JScrollPane. Surprisingly, there is no
addmethod in the JScrollPane class. To put the text area in the scroll pane, you pass it to the JScrollPane constructor. Then add only the scroll pane (not the text area) to the frame.