1 19 20 package org.chateverywhere; 21 22 import java.lang.*; 23 import java.awt.*; 24 import java.awt.event.*; 25 26 27 public class InputDialog extends Dialog implements ActionListener 28 { 29 private TextField password; 30 private Button ok, cancel; 31 private boolean data_ok = false; 32 private String data; 33 34 public InputDialog(Frame owner, String title, String text, 35 Color fg_color, Color bg_color, Color c_fg_color, Color c_bg_color) 36 { 37 super(owner, title, true); 38 39 draw_dialog(text, fg_color, bg_color, c_fg_color, c_bg_color); 40 41 center_on_screen(); 42 this.setVisible(true); 43 password.requestFocus(); 44 } 45 46 47 private void draw_dialog(String text, 48 Color fg_color, Color bg_color, Color c_fg_color, Color c_bg_color) 49 { 50 Panel buttons; 51 52 this.setLayout(new GridLayout(3, 1)); 53 54 this.setBackground(bg_color); 55 this.setForeground(fg_color); 56 57 ok = new Button("OK"); 58 ok.addActionListener(this); 59 ok.setForeground(c_fg_color); 60 ok.setBackground(c_bg_color); 61 cancel = new Button("Cancel"); 62 cancel.addActionListener(this); 63 cancel.setForeground(c_fg_color); 64 cancel.setBackground(c_bg_color); 65 password = new TextField(10); 66 password.setEchoChar('*'); 67 password.addActionListener(this); 68 password.setForeground(c_fg_color); 69 password.setBackground(c_bg_color); 70 buttons = new Panel(); 71 buttons.add(ok); 72 buttons.add(cancel); 73 74 this.add(new Label(text)); 75 this.add(password); 76 this.add(buttons); 77 78 setSize(new Dimension(250, 130)); 79 validate(); 80 } 81 82 83 public void actionPerformed(ActionEvent evt) 84 { 85 if(evt.getSource().equals(ok) || evt.getSource().equals(password)) { 86 data = password.getText(); 87 data_ok = true; 88 dispose(); 89 } 90 91 if(evt.getSource().equals(cancel)) { 92 data = ""; 93 data_ok = false; 94 dispose(); 95 } 96 } 97 98 public boolean is_data_ok() 99 { 100 return data_ok; 101 } 102 103 public String get_data() 104 { 105 return data; 106 } 107 108 private void center_on_screen() 109 { 110 Dimension screen; 111 Dimension w = this.getSize(); 112 113 screen = this.getToolkit().getScreenSize(); 115 120 121 this.setBounds(screen.width/2 - w.width/2, 122 screen.height/2 - w.height/2, 123 w.width, w.height); 124 } 125 126 127 128 129 } 130 131 132 | Popular Tags |