import java.awt.*; public class Trianglewindow extends Dialog { protected Button button; protected TextField inputfield; protected TextArea outputarea; public Trianglewindow (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)); // Create input and output fields inputfield = new TextField(15); outputarea = new TextArea(); outputarea.setEditable(false); this.add("Center", outputarea); // Create QUIT button in panel; add Panel to window // Use a FlowLayout to center the button button = new Button("QUIT"); Panel p = new Panel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15)); p.add(button); this.add("South", p); // Resize the window to preferred size of components this.pack(); } 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(); } } 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(); } }