KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > util > JWhichUI


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JWhichUI.java
26  *
27  * Created on December 2, 2000, 3:09 PM
28  */

29
30 package com.sun.enterprise.tools.common.util;
31
32 import java.awt.*;
33 import java.awt.event.*;
34 import javax.swing.*;
35 import javax.swing.text.*;
36
37 /**
38  *
39  * @author administrator
40  * @version
41  */

42
43 class JWhichUI extends JFrame implements ActionListener
44 {
45     public JWhichUI()
46     {
47         addButtonPanel();
48         addTextPanel();
49
50         setTitle(title);
51         setSize(900, 300);
52
53         addWindowListener(new WindowAdapter()
54         {
55             public void windowClosing(WindowEvent e)
56             {
57                 System.exit(0);
58             }
59         } );
60
61         show();
62     }
63
64     ////////////////////////////////////////////////////////
65

66     public void pr(String JavaDoc s)
67     {
68         //textArea.setText(textArea.getText() + s + "\n");//NOI18N
69
textArea.append(s + "\n");//NOI18N
70
}
71
72     //////////////////////////////////////////////////////////////
73

74     private void addButtonPanel()
75     {
76         JPanel panel = new JPanel();
77         searchButton = new JButton("Search");//NOI18N
78
panel.add(searchButton);
79         searchButton.addActionListener(this);
80         Dimension d = searchButton.getPreferredSize();
81         d.setSize(450, d.getHeight());
82         searchString = new JTextField();
83         searchString.setPreferredSize(d);
84         panel.add(searchString);
85         searchString.addActionListener(this);
86         
87         getContentPane().add(panel, "South");//NOI18N
88
}
89     
90     //////////////////////////////////////////////////////////////
91

92     private void addTextPanel()
93     {
94         textArea = new JTextArea(800, 50);
95         scrollPane = new JScrollPane(textArea);
96         getContentPane().add(scrollPane, "Center");//NOI18N
97
}
98     
99     //////////////////////////////////////////////////////////////
100

101     public void actionPerformed(ActionEvent evt)
102     {
103         Object JavaDoc source = evt.getSource();
104     
105         if(source == searchButton)
106         {
107             String JavaDoc what = searchString.getText();
108             
109             if(what == null || what.length() <= 0)
110                 return;
111             
112             JWhich jw = new JWhich(what);
113             pr(jw.getResult());
114         }
115     }
116
117     //////////////////////////////////////////////////////////////
118

119     public static void main(String JavaDoc[] args)
120     {
121         JWhichUI jwui = new JWhichUI();
122         jwui.show();
123     }
124     
125     //////////////////////////////////////////////////////////////
126

127     private JButton searchButton;
128     private JTextField searchString;
129     private JTextArea textArea;
130     private JScrollPane scrollPane;
131     private final static String JavaDoc title = "JWhich -- Class Finder";//NOI18N
132
}
133
134
Popular Tags