|
| 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 | +} |
0 commit comments