Down and Dirty with GridBagLayout: Using one GridBagLayout and 13 buttons only, create the following GUI.
Modeling the Real World: Using any combination of JPanels and layout managers, pick a household appliance and replicate its interface.
Assimilating Your Knowledge: Changing nothing in the following code except to implement the createGUI() method, create an application that starts up looking like figure 12-44 and when stretched horizontally looks like figure 12-45. Notice that in figure 12-45 only the text fields were stretched.
Figure 12-44: Exercise3: Default Size
Figure 12-45: Exercise3: Stretched Horizontally
1 package chap12.exercises; 2 import java.awt.*; 3 import javax.swing.*; 4 5 public class Exercise3 extends JFrame{ 6 7 public Exercise3(){ 8 super("Exercise3"); 9 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 10 createGUI(); 11 } 12 13 public void createGUI(){ 14 //enter code here. Change no other part of this file. 15 } 16 17 public static void main(String[] arg) { 18 JFrame frame = new Exercise3(); 19 frame.pack(); 20 frame.setVisible(true); 21 } 22 }
Exploring a new Layout Manager: Investigate BoxLayout and write a small application that uses it.