1 20 21 package org.jacorb.naming.namemanager; 22 23 import javax.swing.*; 24 import java.awt.*; 25 import java.awt.event.*; 26 27 33 34 public class ObjectDialog 35 extends JDialog 36 implements ActionListener, KeyListener 37 { 38 JTextField nameField; 39 JTextField iorField; 40 JCheckBox rebindCheckBox; 41 boolean isOk; 42 43 public ObjectDialog(Frame frame) 44 { 45 super(frame, "Bind Object", true); 46 47 isOk = false; 48 JPanel mainPanel = new JPanel( new BorderLayout()); 49 50 JPanel hiPanel = new JPanel(); 51 hiPanel.setLayout( new BoxLayout( hiPanel, BoxLayout.Y_AXIS )); 52 JLabel nameLabel = new JLabel("Name:"); 53 JLabel objectLabel = new JLabel("IOR:"); 54 rebindCheckBox = new JCheckBox("Rebind if name is bound?", false); 55 nameField = new JTextField(40); 56 iorField = new JTextField(40); 57 58 hiPanel.add(nameLabel); 59 hiPanel.add(nameField); 60 hiPanel.add(objectLabel); 61 hiPanel.add(iorField); 62 hiPanel.add(rebindCheckBox); 63 64 JButton ok = new JButton("Ok"); 65 JButton cancel = new JButton("Cancel"); 66 67 JPanel loPanel = new JPanel(); 68 loPanel.add(ok); 69 loPanel.add(cancel); 70 71 ok.addActionListener(this); 72 cancel.addActionListener(this); 73 74 mainPanel.add(hiPanel, BorderLayout.CENTER); 75 mainPanel.add(loPanel, BorderLayout.SOUTH); 76 getContentPane().add(mainPanel); 77 78 pack(); 79 show(); 80 81 } 82 83 public boolean isRebind() 84 { 85 return rebindCheckBox.isSelected(); 86 } 87 88 public String getName() 89 { 90 return nameField.getText(); 91 } 92 93 public String getIOR() 94 { 95 return iorField.getText(); 96 } 97 98 public void actionPerformed(ActionEvent e) 99 { 100 if (e.getActionCommand().equals("Ok")) 101 { 102 try 103 { 104 isOk = true; 105 dispose(); 106 } 107 catch (Exception ex) 108 { 109 JOptionPane.showMessageDialog( this, ex.getMessage(), 110 "Input error", JOptionPane.ERROR_MESSAGE); 111 } 112 } 113 else dispose(); 114 } 115 116 public void keyPressed(KeyEvent e) 117 { 118 if (e.getKeyCode()==KeyEvent.VK_ENTER) 119 actionPerformed(new ActionEvent(this, 0, "Ok")); 120 else if (e.getKeyCode()==KeyEvent.VK_ESCAPE) 121 actionPerformed(new ActionEvent(this, 0, "Cancel")); 122 } 123 124 public void keyReleased(KeyEvent e) {} 125 public void keyTyped(KeyEvent e) {} 126 } 127 128 129 130 | Popular Tags |