Java Reference
In-Depth Information
Figure 12.13
Create a GUI that looks similar to this Calculator window.
Lab 12.2: The Instant Message Window
This lab is the beginning of a project that you will work on throughout
the remainder of this topic: You will write an instant messaging program.
Instant messaging has become a very popular Internet application
because it enables you to “talk” to someone by sending messages back
and forth that are instantly read by the receiver. This project will use
Swing, and you will create the GUI portion of the program first.
Write a class named InstantMessageFrame. Have it extend the JFrame
class.
1. Add a constructor that contains a single parameter of type String to
represent the title bar of the JFrame. Within the constructor, pass the
String parameter up to the parent JFrame constructor that takes in a
String.
2. Within the constructor, use the setDefaultCloseOperation() method
so that your JFrame will cause the program to exit when the user
closes the JFrame.
3. Add a main() method within your InstantMessageFrame class.
Within main(), instantiate a new InstantMessageFrame object, pass-
ing in “My IM Program” for the title bar.
4. Within main(), set the size of your window to be 220 pixels wide by
450 pixels high.
5. Within main(), invoke setVisible() to make your window visible on
the screen.
6. Save, compile, and run your InstantMessageFrame program.
You should see a JFrame that is 220 pixels wide by 450 pixels high.
Your program should exit when you close the JFrame.
Search WWH ::




Custom Search