| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Feb | ||||||
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | ||||||
Chapter 2, 2.7
JPanel panel1 = new JPanel()
panell.setBackground(Color.white)
JPanel panel1 = new JPanel()
panell.setBackground(Color.white)
1. Write the integer values of red, green, and blue for the following RGB colors:
-red:(255,0,0), green: (0,255,0), blue(0,0,255)
2. Describe the roles and responsibilities of a frame, a panel, and a layout manager in a GUI application.
-The frame is just a rectangular box, a window, for panels to place in. A panel is a flat, rectangular area suitable for displaying other objects such as geometric shapes and images. A layout manager is object that we use to control the layout of multiple panels, the order of these panels.
3.Where are panels displayed when a border layout is used to control their placement in a window?
-Five areas, the north, south, west, east, and center of the frame.
4. Write a code segment that would be used to set the layout for adding panels to a 5-by-5 grid in a window. You may assume that the panel’s content pane is named pane.
-import javax.swing.*;
import java.awt.*;
public class GUIWindow{
public static void main(String[] args){
JFrame the GUI = new JFrame();
the GUI.setTitle(“Fourth GUI Program”)
theGUI.setSize(300,200)
theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
JPanel panel1 = new JPanel()
panel1.setBackground(Color.white)
JPanel panel2 = new JPanel()
panel2.setBackground(Color.black)
JPanel panel3 = new JPanel()
panel3.setBackground(Color.white)
JPanel panel4 = new JPanel()
panel4.setBackground(Color.black)
JPanel panel5 = new JPanel()
panel5.setBackground(Color.white)
JPanel panel6 = new JPanel()
panel6.setBackground(Color.black)
JPanel panel7 = new JPanel()
panel7.setBackground(Color.white)
JPanel panel8 = new JPanel()
panel8.setBackground(Color.black)
JPanel panel9 = new JPanel()
panel9.setBackground(Color.white)
JPanel panel10 = new JPanel()
panel10.setBackground(Color.black)
JPanel panel11 = new JPanel()
panel11.setBackground(Color.white)
JPanel panel12 = new JPanel()
panel12.setBackground(Color.black)
JPanel panel13 = new JPanel()
panel13.setBackground(Color.white)
JPanel panel14 = new JPanel()
panel14.setBackground(Color.black)
JPanel panel15 = new JPanel()
panel15.setBackground(Color.white)
JPanel panel16 = new JPanel()
panel16.setBackground(Color.black)
JPanel panel17 = new JPanel()
panel17.setBackground(Color.white)
JPanel panel18 = new JPanel()
panel18.setBackground(Color.black)
JPanel panel19 = new JPanel()
panel19.setBackground(Color.white)
JPanel panel20 = new JPanel()
panel20.setBackground(Color.black)
JPanel panel21 = new JPanel()
panel21.setBackground(Color.white)
JPanel panel22 = new JPanel()
panel22.setBackground(Color.black)
JPanel panel23 = new JPanel()
panel23.setBackground(Color.white)
JPanel panel24 = new JPanel()
panel24.setBackground(Color.black)
JPanel panel25 = new JPanel()
panel25.setBackground(Color.white)
JPanel panel1 = new JPanel()
Container pane = theGUI.getContentPane()
pane.setLayout(new GridLayout(5,5))
pane.add(pane1)
pane.add(pane2)
pane.add(pane3)
pane.add(pane4)
pane.add(pane5)
pane.add(pane6)
pane.add(pane7)
pane.add(pane8)
pane.add(pane9)
pane.add(pane10)
pane.add(pane11)
pane.add(pane12)
pane.add(pane13)
pane.add(pane14)
pane.add(pane15)
pane.add(pane16)
pane.add(pane17)
pane.add(pane18)
pane.add(pane19)
pane.add(pane20)
pane.add(pane21)
pane.add(pane22)
pane.add(pane23)
pane.add(pane24)
pane.add(pane25)
theGUIsetVisible(true);
}
}