51,408
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) {
// Create application frame.
//new Login();
TestFrame frame = new TestFrame();
// Show frame.
frame.show(true);
}
}
public class TestFrame extends JFrame {
/**
* The constructor.
*/
public TestFrame() {
this.setLocationRelativeTo(null);
this.setTitle("Login");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu();
JMenuItem menuSave = new JMenuItem();
JMenuItem menuFileExit = new JMenuItem();
JMenu menuEdit = new JMenu();
JMenuItem menuAdd = new JMenuItem();
JMenuItem menuAlter = new JMenuItem();
JMenuItem menuDelete = new JMenuItem();
menuFile.setText("菜单");
menuSave.setText("保存");
menuFileExit.setText("退出");
menuEdit.setText("编辑");
menuAdd.setText("添加新联系人");
menuAlter.setText("修改信息");
menuDelete.setText("删除信息");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
TestFrame.this.windowClosed();
}
}
);
menuAdd.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
TestFrame.this.Add();
}
}
);
menuFile.add(menuSave);
menuFile.add(menuFileExit);
menuEdit.add(menuAdd);
menuEdit.add(menuAlter);
menuEdit.add(menuDelete);
menuBar.add(menuFile);
menuBar.add(menuEdit);
setTitle("TestFrame");
setJMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TestFrame.this.windowClosed();
}
}
);
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
protected void Add() {
new Add();
}
}