import javax.swing.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; public class Sample6 extends JFrame implements ActionListener{ // inherit JFrame /** * Constructor sets up the window */ public Sample6() { // // setup the frames banner/title bar // super("Sample 6"); // call JFrame's constructor and give it a title setSize(500,400); // set the width of the window to 400 pixels, height to 300. // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // exit the whole program when this frame is closed addWindowListener(new WindowAdapter() { // Quit the application public void windowClosing(WindowEvent e) { System.exit(0); } }); // // add a button to popup the dialog box // JButton button = new JButton("Press this button"); button.addActionListener(this); getContentPane().add(button); } /** * * this method responds to the OK and Cancel buttons, if it is the ok * button it will display the contents of the textfields on the screen. */ public void actionPerformed(ActionEvent event){ if(event.getSource() instanceof JButton) { // is this a button? Dialog6 dialog = new Dialog6(this); dialog.setVisible(true); } } /*********************************************************************** * * Main routine, Note, this routine can be in any class. */ public static void main(String[] arguments){ Sample6 fr = new Sample6(); // create the sample6 frame fr.setVisible(true); // allow it to be seen } }