package bmpviewer; import java.awt.*; import java.awt.event.*; import java.util.*; /** * Dialog to display messages. *

* @author Hiroyuki Murata * @since JDK1.1 */ public class MessageDialog extends Dialog implements ActionListener,WindowListener { MessageDialog(Frame frame, String title, String msg) { super(frame, title); setBackground(Color.lightGray); addWindowListener(this); StringTokenizer st = new StringTokenizer(msg,"\n"); int clm=0, row=0; while (st.hasMoreTokens()) { int len = st.nextToken().length(); if (clm < len) clm = len; row++; } TextArea ta = new TextArea(msg, row,clm, TextArea.SCROLLBARS_NONE); //Font font = new Font("Monospaced", Font.PLAIN, 12); //ta.setFont(font); add("Center",ta); Panel pBtn = new Panel(); add("South",pBtn); Button btnOK = new Button("OK"); pBtn.add(btnOK); btnOK.addActionListener(this); pack(); setVisible(true); } public void paint(Graphics g) { pack(); super.paint(g); } // as ActionListener ("OK") ---------------------------- public void actionPerformed(ActionEvent ev) { setVisible(false); } // as WindowListener ----------------------------------- public void windowClosing(WindowEvent ev) { setVisible(false); } public void windowOpened(WindowEvent ev) {} public void windowClosed(WindowEvent ev) {} public void windowIconified(WindowEvent ev) {} public void windowDeiconified(WindowEvent ev) {} public void windowActivated(WindowEvent ev) {} public void windowDeactivated(WindowEvent ev) {} }