Java Reference
In-Depth Information
3. A component is an onscreen item such as a button or text field. A frame is differ-
ent from other components because it is a first-class citizen of the user's operating
system. Frames hold other components inside them.
4. Some properties of frames are size , location , and title . The following code
creates a frame and sets these properties:
JFrame frame = new JFrame();
frame.setSize(new Dimension(400, 300));
frame.setLocation(new Point(20, 10));
frame.setTitle("My favorite frame");
frame.setVisible(true);
5. (a) JTextArea
(b) JOptionPane
(c) JLabel
(d) JButton
(e) JTextField
6. JButton b1 = new JButton("Click me");
b1.setBackground(Color.GREEN);
JButton b2 = new JButton("Do not touch!");
b2.setBackground(Color.YELLOW);
7. (a) GridLayout
(b) FlowLayout
(c) BorderLayout
8. (a) frame.setLayout(new GridLayout(3, 2));
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
frame.add(b5);
(b) frame.setLayout(new FlowLayout());
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
frame.add(b5);
(c) frame.setLayout(new BorderLayout());
frame.add(b1, BorderLayout.NORTH);
frame.add(b2, BorderLayout.WEST);
frame.add(b3, BorderLayout.CENTER);
frame.add(b4, BorderLayout.EAST);
frame.add(b5, BorderLayout.SOUTH);
Search WWH ::




Custom Search