//////////////////////////// // // // popUp.class // // // // Handles the pop-up // // dialog boxes for the // // javaCalc applet. // // // // CPS406 Fall '98 // // // // Matthew Narrell // // // //////////////////////////// import java.awt.*; import java.awt.event.*; public class popUp{ ///////////////////////////////////////////////////////////////////////////// // // Dialog Titles, and Error Messages. // ///////////////////////////////////////////////////////////////////////////// protected static String error = "ERROR:"; protected static String warning = "WARNING:"; protected static String divByZero = "Division by ZERO"; protected static String intDiv = "This calculator implements INTEGER division"; protected static String overFlow = "OVERFLOW: Maximum of 20 digits allowed"; ///////////////////////////////////////////////////////////////////////////// // // Error Methods. // // Each of these methods creates a frame and a dialog box, then displays // it to the screen, for specific errors. // ///////////////////////////////////////////////////////////////////////////// // Division by Zero Error public static void divByZero(){ Frame f = new Frame(error); dialogbox d = new dialogbox(f, (error + " Division by Zero"), divByZero); d.show(); } // Integer Division Warning public static void intDiv(){ Frame f = new Frame(warning); dialogbox d = new dialogbox(f, (warning + " Integer Division"), intDiv); d.show(); } // Overflow Error public static void overFlow(){ Frame f = new Frame(error); dialogbox d = new dialogbox(f, (error + " Overflow"), overFlow); d.show(); } public static void credits(){ Frame f = new Frame("Credits"); dialogbox d = new dialogbox(f, "Credits", "Matthew Narrell "); d.show(); } } /////////////////////////////////////////////////////////////////////////////// // // Private class to handle dialog box, and "OK" button. // /////////////////////////////////////////////////////////////////////////////// class dialogbox extends Dialog implements ActionListener{ protected Button ok; protected Label display; public dialogbox(Frame parent, String title, String message){ //Call to parent class to create frame. super(parent, title, false); this.setLayout(new BorderLayout(15,15)); //Set the label to be the passed error message. display = new Label(message); display.setAlignment(1); this.add(display, BorderLayout.CENTER); //Create the "OK" button. ok = new Button("OK"); ok.addActionListener(this); Panel p = new Panel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15)); p.add(ok); this.add("South", p); this.pack(); } public void actionPerformed(ActionEvent e){ //Close dialog box upon clicking "OK". setVisible(false); } } class CloseWindow extends WindowAdapter{ public void windowClosing(WindowEvent e){ e.getWindow().setVisible(false); } }