KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > gui > MessageBox


1 package zirc.gui ;
2
3 import java.awt.* ;
4 import java.awt.event.* ;
5 import javax.swing.* ;
6 import java.util.* ;
7
8 //zIrc, irc client.
9
// Copyright (C) 2004 CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com
10
//
11
// This program is free software; you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your option) any later version.
15
//
16
// This program is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
// GNU General Public License for more details.
20

21 /**
22  * <p>Title: MessageBox</p>
23  * <p>Description: recupere le message de kick</p>
24  * <p>Copyright: Copyright (c) 2004</p>
25  * <p>Company: CoolBytes(Stephane Claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
26  * @version 1.0
27  */

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 JavaDoc e)
47     {
48       e.printStackTrace() ;
49     }
50
51   }
52
53   private void jbInit() throws Exception JavaDoc
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 JavaDoc()
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 JavaDoc show(JDialog owner, String JavaDoc title, String JavaDoc 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