KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > naming > namemanager > NSPrefsDlg


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.naming.namemanager;
22
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.*;
26
27 public class NSPrefsDlg
28 extends JDialog
29 implements ActionListener, KeyListener
30 {
31     JTextField editSeconds;
32     boolean isOk;
33     public int updateInterval;
34
35     public NSPrefsDlg(Frame frame, int updInt)
36     {
37         super(frame,"Preferences",true);
38         isOk=false;
39         JPanel mainPanel=new JPanel(new GridLayout(2,1));
40         getContentPane().add(mainPanel);
41         JPanel hiPanel=new JPanel(new FlowLayout());
42         JPanel loPanel=new JPanel();
43         mainPanel.add(hiPanel);
44         mainPanel.add(loPanel);
45
46         JLabel label1=new JLabel("Update view after ");
47
48         Integer JavaDoc upd=new Integer JavaDoc(updInt);
49         editSeconds=new JTextField(upd.toString(),3);
50         JLabel label2=new JLabel("seconds ");
51         hiPanel.add(label1); hiPanel.add(editSeconds); hiPanel.add(label2);
52
53         JButton ok=new JButton("Ok");
54         JButton cancel=new JButton("Cancel");
55         loPanel.add(ok); loPanel.add(cancel);
56         ok.addActionListener(this);
57         cancel.addActionListener(this);
58         editSeconds.addKeyListener(this);
59     }
60     public void actionPerformed(ActionEvent e)
61     {
62         if (e.getActionCommand().equals("Ok"))
63         {
64             try
65             {
66                 updateInterval=Integer.parseInt(editSeconds.getText());
67                 isOk=true; dispose();
68             } catch (Exception JavaDoc ex)
69             {
70                 JOptionPane.showMessageDialog(this,"Wrong number format",
71                     "Input error", JOptionPane.ERROR_MESSAGE);
72                 editSeconds.grabFocus(); editSeconds.selectAll();
73             }
74         }
75         else dispose();
76     }
77     public void keyPressed(KeyEvent e)
78     {
79         if (e.getKeyCode()==KeyEvent.VK_ENTER)
80             actionPerformed(new ActionEvent(this,0,"Ok"));
81         else if (e.getKeyCode()==KeyEvent.VK_ESCAPE)
82             actionPerformed(new ActionEvent(this,0,"Cancel"));
83     }
84     public void keyReleased(KeyEvent e) {}
85     public void keyTyped(KeyEvent e) {}
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Popular Tags