/* InClassGUI5.java CIS 160 2014-10-30 David Klick Example of GUI with BorderLayout which has one panel in the center and a panel with a GridLayout to the east. This was done as a request in class. */ import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class InClassGUI5 extends JApplet { // These text fields were made global because normally // you would want access between methods, but in this case // they could be local inside createAndShowGUI() since they // are not used after being cretaed and added to the GUI. private JTextField txt1 = new JTextField("Michael"); private JTextField txt2 = new JTextField("Anna"); private JTextField txt3 = new JTextField("Raf"); // This is where the applet will start execution. public void init() { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } public void createAndShowGUI() { // Create containers. JPanel pnlCenter = new JPanel(); JPanel pnlEast = new JPanel(); // Set layout managers. setLayout(new BorderLayout()); pnlCenter.setLayout(new BorderLayout()); pnlEast.setLayout(new GridLayout(3, 1)); // Create one more widget. JButton btn = new JButton("Opielowski"); // Add widgets to subcontainers (panels). pnlCenter.add(btn, BorderLayout.CENTER); pnlEast.add(txt1); pnlEast.add(txt2); pnlEast.add(txt3); // Add subcontainers (panels) to applet. add(pnlCenter, BorderLayout.CENTER); add(pnlEast, BorderLayout.EAST); } }