1 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 upd=new Integer (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 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 |