Skip to content

Commit 96c4232

Browse files
committed
Chapter 14 exercise progress
1 parent 8d5dd69 commit 96c4232

File tree

18 files changed

+1142
-19
lines changed

18 files changed

+1142
-19
lines changed

Chapter14/exercises/14.10/GUI.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Filename: GUI.java
3+
*
4+
* Description: 14.10 - Create the following GUI. You do not have to provide
5+
* any functionality.
6+
*
7+
* Created: 19/01/16 00:54:26
8+
* Revision: none
9+
*
10+
* @Author: Siidney Watson - siidney.watson@gmail.com
11+
* @Version: 1.0
12+
*
13+
* =====================================================================================
14+
*/
15+
import java.awt.BorderLayout;
16+
17+
import javax.swing.JFrame;
18+
import javax.swing.JPanel;
19+
import javax.swing.JCheckBox;
20+
import javax.swing.JButton;
21+
import javax.swing.JComboBox;
22+
import javax.swing.BoxLayout;
23+
24+
public class GUI extends JFrame{
25+
private static final String[] names = {
26+
"Red", "Green", "Blue", "Purple", "Greenish"};
27+
28+
// CONSTRUCTOR
29+
public GUI(){
30+
super("Exercise 14.10");
31+
32+
setLayout(new BorderLayout(5, 5));
33+
34+
JPanel center = new JPanel();
35+
JPanel bottom = new JPanel();
36+
37+
add(new JComboBox(names), BorderLayout.NORTH);
38+
39+
center.add(new JCheckBox("Background"));
40+
center.add(new JCheckBox("Foreground"));
41+
42+
add(center, BorderLayout.CENTER);
43+
44+
bottom.add(new JButton("Ok"));
45+
bottom.add(new JButton("Cancel"));
46+
47+
add(bottom, BorderLayout.SOUTH);
48+
}
49+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Filename: GUIDemo.java
3+
*
4+
* Description: 14.10 - GUIDemo
5+
*
6+
* Created: 19/01/16 00:54:15
7+
* Revision: none
8+
*
9+
* @Author: Siidney Watson - siidney.watson@gmail.com
10+
* @Version: 1.0
11+
*
12+
* =====================================================================================
13+
*/
14+
import javax.swing.JFrame;
15+
16+
public class GUIDemo{
17+
public static void main(String[] args){
18+
GUI gui = new GUI();
19+
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20+
gui.setSize(400, 125);
21+
gui.setVisible(true);
22+
}
23+
}

Chapter14/exercises/14.11/GUI.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Filename: GUI.java
3+
*
4+
* Description: 14.11 - Create the following GUI. You do not have to provide
5+
* any functionality.
6+
*
7+
* Created: 23/01/16 19:18:38
8+
* Revision: none
9+
*
10+
* @Author: Siidney Watson - siidney.watson@gmail.com
11+
* @Version: 1.0
12+
*
13+
* =====================================================================================
14+
*/
15+
import java.awt.GridLayout;
16+
import java.awt.GridBagLayout;
17+
import java.awt.GridBagConstraints;
18+
19+
import javax.swing.JFrame;
20+
import javax.swing.JPanel;
21+
import javax.swing.JLabel;
22+
import javax.swing.JButton;
23+
import javax.swing.JCheckBox;
24+
import javax.swing.JTextArea;
25+
import javax.swing.JRadioButton;
26+
import javax.swing.ButtonGroup;
27+
import javax.swing.JComboBox;
28+
29+
public class GUI extends JFrame{
30+
// CONSTRUCTOR
31+
public GUI(){
32+
super("Exercise 14.11");
33+
34+
JPanel container = new JPanel();
35+
JPanel innerContainer = new JPanel(new GridBagLayout());
36+
JPanel buttonGrid = new JPanel(new GridLayout(4, 1, 0, 10));
37+
JPanel centralGrid = new JPanel(new GridLayout(1, 5, 0, 0));
38+
JPanel checkBoxGrid = new JPanel(new GridLayout(3, 1, 0, 0));
39+
JPanel radioBtnGrid = new JPanel(new GridLayout(3, 1, 0, 0));
40+
41+
ButtonGroup radioGroup = new ButtonGroup();
42+
43+
GridBagConstraints c = new GridBagConstraints();
44+
45+
c.fill = GridBagConstraints.HORIZONTAL;
46+
47+
// ROW 1
48+
c.gridx = 0;
49+
c.gridy = 0;
50+
51+
innerContainer.add(new JLabel("Printer: MyPrinter"), c);
52+
53+
// ROW 2
54+
c.gridx = 0;
55+
c.gridy = 1;
56+
57+
checkBoxGrid.add(new JCheckBox("Image"));
58+
checkBoxGrid.add(new JCheckBox("Text"));
59+
checkBoxGrid.add(new JCheckBox("Code"));
60+
61+
JRadioButton radioSelection = new JRadioButton("Selection");
62+
JRadioButton radioAll = new JRadioButton("All");
63+
JRadioButton radioApplet = new JRadioButton("Applet");
64+
65+
radioGroup.add(radioSelection);
66+
radioGroup.add(radioAll);
67+
radioGroup.add(radioApplet);
68+
69+
radioBtnGrid.add(radioSelection);
70+
radioBtnGrid.add(radioAll);
71+
radioBtnGrid.add(radioApplet);
72+
73+
centralGrid.add(new JTextArea());
74+
centralGrid.add(checkBoxGrid);
75+
centralGrid.add(new JTextArea());
76+
centralGrid.add(radioBtnGrid);
77+
centralGrid.add(new JTextArea());
78+
79+
innerContainer.add(centralGrid, c);
80+
81+
// ROW 3
82+
String names[] = {"High", "Medium", "Low"};
83+
JPanel bottom = new JPanel();
84+
85+
c.gridx = 0;
86+
c.gridy = 2;
87+
bottom.add(new JLabel("Print Quality:"));
88+
89+
bottom.add(new JComboBox(names));
90+
91+
bottom.add(new JCheckBox("Print to File"));
92+
93+
innerContainer.add(bottom, c);
94+
95+
container.add(innerContainer);
96+
97+
// COL 2
98+
buttonGrid.add(new JButton("OK"), c);
99+
buttonGrid.add(new JButton("Cancel"), c);
100+
buttonGrid.add(new JButton("Setup..."), c);
101+
buttonGrid.add(new JButton("Help"), c);
102+
103+
container.add(buttonGrid);
104+
105+
add(container);
106+
}
107+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Filename: GUIDemo.java
3+
*
4+
* Description: 14.11 - GUI demo
5+
*
6+
* Created: 23/01/16 19:18:27
7+
* Revision: none
8+
*
9+
* @Author: Siidney Watson - siidney.watson@gmail.com
10+
* @Version: 1.0
11+
*
12+
* =====================================================================================
13+
*/
14+
import javax.swing.JFrame;
15+
16+
public class GUIDemo{
17+
public static void main(String[] args){
18+
GUI gui = new GUI();
19+
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20+
gui.setSize(700, 200);
21+
gui.setVisible(true);
22+
}
23+
}

Chapter14/exercises/14.8/GUI.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
*
1313
* =====================================================================================
1414
*/
15-
import java.awt.BorderLayout;
15+
import java.awt.GridLayout;
16+
import java.awt.Dimension;
1617

1718
import javax.swing.JFrame;
19+
import javax.swing.JPanel;
1820
import javax.swing.Box;
1921
import javax.swing.JButton;
2022
import javax.swing.JLabel;
@@ -26,28 +28,41 @@ public class GUI extends JFrame{
2628
public GUI(){
2729
super("Exercise 14.8");
2830

29-
setLayout(new BorderLayout(15, 15));
31+
JPanel container = new JPanel();
3032

3133
Box leftBox = Box.createVerticalBox();
32-
Box centerBox = Box.createHorizontalBox();
34+
Box centerBox = Box.createVerticalBox();
35+
Box innerCenter1 = Box.createHorizontalBox();
36+
Box innerCenter2 = Box.createHorizontalBox();
3337
Box rightBox = Box.createVerticalBox();
3438

35-
// LEFT PANEL
36-
leftBox.createVerticalGlue();
37-
leftBox.add(new JCheckBox("Snap to Border"));
39+
JPanel rightGrid = new JPanel(new GridLayout(3, 1, 0, 10));
40+
41+
// LEFT
42+
leftBox.add(new JCheckBox("Snap to Grid"));
3843
leftBox.add(new JCheckBox("Show Grid"));
39-
add(leftBox, BorderLayout.WEST);
40-
// CENTER PANEL
41-
centerBox.add(new JLabel("X: "));
42-
centerBox.add(new JTextField(5));
43-
centerBox.add(new JLabel("Y: "));
44-
centerBox.add(new JTextField(5));
45-
add(centerBox, BorderLayout.CENTER);
46-
// RIGHT PANEL
47-
rightBox.add(new JButton("Ok"));
48-
rightBox.add(new JButton("Cancel"));
49-
rightBox.add(new JButton("Help"));
50-
add(rightBox, BorderLayout.EAST);
44+
45+
// CENTER
46+
innerCenter1.add(new JLabel("X: "));
47+
innerCenter1.add(new JTextField(3));
48+
innerCenter2.add(new JLabel("Y: "));
49+
innerCenter2.add(new JTextField(3));
50+
51+
centerBox.add(innerCenter1);
52+
centerBox.add(Box.createRigidArea(new Dimension(0, 10)));
53+
centerBox.add(innerCenter2);
54+
55+
// RIGHT
56+
rightGrid.add(new JButton("Ok"));
57+
rightGrid.add(new JButton("Cancel"));
58+
rightGrid.add(new JButton("Help"));
59+
rightBox.add(rightGrid);
60+
61+
container.add(leftBox);
62+
container.add(Box.createRigidArea(new Dimension(10, 0)));
63+
container.add(centerBox);
64+
container.add(Box.createRigidArea(new Dimension(10, 0)));
65+
container.add(rightBox);
66+
add(container);
5167
}
5268
}
53-

Chapter14/exercises/14.9/GUI.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Filename: GUI.java
3+
*
4+
* Description: 14.9 - Create the following GUI. You do not have to provide
5+
* any functionality.
6+
*
7+
* Created: 19/01/16 00:34:42
8+
* Revision: none
9+
*
10+
* @Author: Siidney Watson - siidney.watson@gmail.com
11+
* @Version: 1.0
12+
*
13+
* =====================================================================================
14+
*/
15+
import java.awt.GridLayout;
16+
17+
import javax.swing.JFrame;
18+
import javax.swing.JPanel;
19+
import javax.swing.JButton;
20+
import javax.swing.JTextField;
21+
import javax.swing.BoxLayout;
22+
23+
public class GUI extends JFrame{
24+
private static final String[] names = {
25+
"7", "8", "9", "/",
26+
"4", "5", "6", "*",
27+
"1", "2", "3", "-",
28+
"0", ".", "=", "+"};
29+
30+
// CONSTRUCTOR
31+
public GUI(){
32+
super("Exercise 14.9");
33+
34+
JPanel container = new JPanel();
35+
JPanel topGrid = new JPanel(new GridLayout(1, 1));
36+
JPanel bottomGrid = new JPanel(new GridLayout(4, 4, 3, 3));
37+
38+
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
39+
40+
topGrid.add(new JTextField(10));
41+
42+
// add buttons
43+
for(int i=0; i<names.length; i++){
44+
bottomGrid.add(new JButton(names[i]));
45+
}
46+
47+
container.add(topGrid);
48+
container.add(bottomGrid);
49+
50+
add(container);
51+
}
52+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Filename: GUIDemo.java
3+
*
4+
* Description: 14.9 - GUIDemo
5+
*
6+
* Created: 19/01/16 00:33:35
7+
* Revision: none
8+
*
9+
* @Author: Siidney Watson - siidney.watson@gmail.com
10+
* @Version: 1.0
11+
*
12+
* =====================================================================================
13+
*/
14+
import javax.swing.JFrame;
15+
16+
public class GUIDemo{
17+
public static void main(String[] args){
18+
GUI gui = new GUI();
19+
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20+
gui.setSize(250, 250);
21+
gui.setVisible(true);
22+
}
23+
}

0 commit comments

Comments
 (0)