1 // File: GridLayout2.java 2 3 import java.applet.Applet; 4 import java.awt.*; 5 import java.awt.event.*; 6 7 public class GridLayout2 extends Applet 8 { 9 private Button showFrame; 10 private TextField status; 11 private Label label; 12 private TextArea address; 13 MsgFrame msgFrame; 14 String FrameTitle = "Message Frame"; 15 16 public void init() 17 { 18 setLayout(new GridLayout(2,2,20,20)); 19 showFrame = new Button("Show Frame"); 20 showFrame.addActionListener(new ButtonHandler2(this)); 21 22 status = new TextField(5); 23 label = new Label("Another example of GridLayout"); 24 String add = "Northeast Parallel Architectures Center (NPAC) \n" 25 + "111 College Place, \n" + "Syracuse, NY 13244-4100"; 26 27 address = new TextArea(add,4,35); 28 address.setEditable(false); 29 add(showFrame); 30 add(status); 31 add(label); 32 add(address); 33 } 34 35 } 36 class ButtonHandler2 implements ActionListener 37 { 38 GridLayout2 grid; 39 public ButtonHandler2(GridLayout2 g) 40 { grid = g; } 41 42 public void actionPerformed(ActionEvent e) 43 { 44 grid.msgFrame = new MsgFrame(grid.FrameTitle); 45 } 46 } 47 48 49 class MsgFrame extends Frame implements ActionListener 50 { 51 MsgFrame (String title) 52 { 53 super(title); 54 Button okButton = new Button("OK"); 55 okButton.addActionListener(this); 56 setLayout(new FlowLayout()); 57 add(okButton); 58 setSize(200,70); 59 setVisible(true); 60 } 61 62 public void actionPerformed(ActionEvent e) 63 { 64 setVisible(false); 65 } 66 } 67