1 package zirc.gui ; 2 3 import java.awt.* ; 4 import java.awt.event.* ; 5 import javax.swing.* ; 6 import java.util.* ; 7 8 21 28 29 public class MessageBox 30 { 31 private static JDialog dlg = new JDialog() ; 32 private static GridLayout gridLayout1 = new GridLayout() ; 33 private static JPanel jPanel1 = new JPanel() ; 34 private static JPanel jPanel2 = new JPanel() ; 35 private static JButton jButton1 = new JButton() ; 36 private static JLabel jLabel1 = new JLabel() ; 37 private static JTextField jTextField1 = new JTextField() ; 38 private static GridLayout gridLayout2 = new GridLayout() ; 39 40 private MessageBox() 41 { 42 try 43 { 44 jbInit() ; 45 } 46 catch (Exception e) 47 { 48 e.printStackTrace() ; 49 } 50 51 } 52 53 private void jbInit() throws Exception 54 { 55 dlg.setDefaultCloseOperation(3) ; 56 dlg.setModal(true) ; 57 dlg.setResizable(false) ; 58 dlg.setTitle("Message"); 59 dlg.getContentPane().setLayout(gridLayout1) ; 60 gridLayout1.setColumns(0) ; 61 gridLayout1.setHgap(0) ; 62 gridLayout1.setRows(1) ; 63 dlg.setUndecorated(true) ; 64 jPanel1.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 65 jPanel1.setLayout(gridLayout2) ; 66 jButton1.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 67 jButton1.setText("Ok") ; 68 jButton1.addActionListener(new java.awt.event.ActionListener () 69 { 70 public void actionPerformed(ActionEvent e) 71 { 72 jButton1_actionPerformed(e) ; 73 } 74 }) ; 75 jLabel1.setHorizontalAlignment(SwingConstants.CENTER) ; 76 jLabel1.setHorizontalTextPosition(SwingConstants.CENTER) ; 77 jTextField1.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 78 jTextField1.setText("") ; 79 gridLayout2.setColumns(0) ; 80 gridLayout2.setRows(3) ; 81 dlg.getContentPane().add(jPanel1, null) ; 82 jPanel1.add(jLabel1, null) ; 83 jPanel1.add(jTextField1, null) ; 84 jPanel1.add(jPanel2, null) ; 85 jPanel2.add(jButton1, null) ; 86 } 87 88 public static String show(JDialog owner, String title, String message) 89 { 90 MessageBox mb = new MessageBox() ; 91 dlg.setTitle(title) ; 92 dlg.setBounds(250, 250, 188, 93) ; 93 jLabel1.setText(message) ; 94 dlg.show() ; 95 96 return jTextField1.getText() ; 97 } 98 99 void jButton1_actionPerformed(ActionEvent e) 100 { 101 if (jTextField1.getText().trim().length() > 0) 102 { 103 dlg.dispose() ; 104 } 105 } 106 } 107 | Popular Tags |