📄 addressdialog.java
字号:
import java.awt.*;
import java.awt.event.*;
public class AddressDialog extends Dialog implements ActionListener
{
private Address address = null;
private Button okay = new Button("Okay");
private Button cancel = new Button("Cancel");
private TextField inputs[] = null;
protected boolean isOkay = false;
private class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
AddressDialog.this.hide();
}
}
public void DlgCenterlization(AddressBook parent)
{
int x = parent.getLocation().x + (parent.getSize().width - getSize().width) / 2;
int y = parent.getLocation().y + (parent.getSize().height - getSize().height) / 2;
x = Math.min(getToolkit().getScreenSize().width - getSize().width, x);
y = Math.min(getToolkit().getScreenSize().height - getSize().height, y);
setLocation(Math.max(0, x), Math.max(0, y));
}
public AddressDialog(AddressBook parent, Address _address)
{
super(parent, "Address Infomation", true);
address = _address;
setup();
okay.addActionListener(this);
cancel.addActionListener(this);
addWindowListener(new WindowCloser());
pack();
DlgCenterlization(parent);
show();
}
public String[] getData()
{
String inputStrings[] = new String[inputs.length];
for (int i = 0; i < inputs.length; i ++)
inputStrings[i] = inputs[i].getText().trim();
return inputStrings;
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == okay)
isOkay = true;
this.hide();
}
private void setup()
{
Panel data = new Panel();
data.setLayout(new GridLayout(address.getLabels().length, 2));
inputs = new TextField[address.getLabels().length];
for (int i = 0; i < address.getLabels().length; i ++)
{
inputs[i] = new TextField(address.getAddress()[i], 20);
data.add(new Label(address.getLabels()[i], Label.RIGHT));
data.add(inputs[i]);
}
Panel buttons = new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(okay); buttons.add(cancel);
setLayout(new BorderLayout());
add("Center", data);
add("South", buttons);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -