Java Reference
In-Depth Information
18 messagePanel1.setCentered( true );
19
20 setLayout( new GridLayout( 2 , 2 ));
21 add(messagePanel1);
22 add(messagePanel2);
23 add(messagePanel3);
24 add(messagePanel4);
25 }
26
27 public static void main(String[] args) {
28 TestMessagePanel frame = new TestMessagePanel();
29 frame.setSize( 300 , 200 );
30 frame.setTitle( "TestMessagePanel" );
31 frame.setLocationRelativeTo( null ); // Center the frame
32 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33 frame.setVisible( true );
34 }
35 }
add message panel
javax.swing.JPanel
The get and set methods for these
data fields are provided in the class, but
omitted in the UML diagram for brevity.
MessagePanel
-xCoordinate: int
-yCoordinate: int
-centered: boolean
The x -coordinate for the message.
The y -coordinate for the message.
Specifies whether the message is displayed centered.
The message to be displayed.
The interval to move the message in the panel.
-message: String
-interval: int
+MessagePanel()
+MessagePanel(message: String)
Constructs a default message panel.
Constructs a message panel with a specified string.
+moveLeft(): void
Moves the message to the left.
Moves the message to the right.
+moveRight(): void
+moveUp(): void
+moveDown(): void
Moves the message up.
Moves the message down.
F IGURE 13.18 MessagePanel displays a message on the panel.
F IGURE 13.19 TestMessagePanel uses MessagePanel to display four message panels.
The rest of this section explains how to implement the MessagePanel class. Since you can
use the class without knowing how it is implemented, you may skip the implementation if
you wish.
skip implementation?
 
Search WWH ::




Custom Search