// written to support the Triangle Puzzle by // Dr. Roger Webster // 4/20/96 import java.awt.*; public class Trianglewindow extends Dialog { protected Button button; protected Button solvebutton; protected TextArea outputarea; protected Triangle Triparent; public Trianglewindow (Triangle Triparent, Frame parent, String title, String message) { // Create a dialog with the specified title super(parent, title, false); // this.resize(300, 50); // Create and use a BorderLayout manager with margins this.setLayout(new BorderLayout(15, 15)); this.Triparent = Triparent; //creates input output fields... outputarea = new TextArea(); // No typing in output field... outputarea.setEditable(false); this.add("Center", outputarea); // Create QUIT button in Panel; add Panel to window // Use a FlowLayout to center the button. Panel p = new Panel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15)); button = new Button("QUIT"); p.add(button); solvebutton = new Button("SOLVE"); p.add(solvebutton); this.add("South", p); p.show(); // Resize the window to preferred size of components this.pack(); this.show(); } public boolean action(Event e, Object what) { if (e.target instanceof Button) { String label = (String)what; if (label.equals ("QUIT")) { if (this.isShowing()) { this.hide(); this.dispose(); } } if (label.equals ("SOLVE")) Triparent.solve(); return true; } return false; } // When the window gets keyboard focus, give it to button. // This allows keyboard shortcuts to pop down the dialog. public boolean gotFocus(Event e, Object arg) { button.requestFocus(); return true; } public void write_msg(String message) { outputarea.setText(message); this.show(); } public void kill() { this.hide(); this.dispose(); } }