📄 newrecgui.java
字号:
// NewRecGui class// ===============import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;class NewRecGui extends Frame implements WindowListener, ActionListener{ int recNum; DirBase dirBase; String fName, sName, telNoStr; // application window components Button enterButton, doneButton; TextField fNameTf, sNameTf, telNoTf; Label fNameLabel, sNameLabel, telNoLabel; public NewRecGui(DirBase db) // constructor { super("New Entries"); // resize(300,180); setSize(300,180); setLayout(new GridLayout(4,2)); fNameTf = new TextField(10); sNameTf = new TextField(10); telNoTf = new TextField(10); fNameLabel = new Label ("First name"); sNameLabel = new Label ("Surname"); telNoLabel = new Label ("Telephone"); add(sNameLabel); add(sNameTf); add(fNameLabel); add(fNameTf); add(telNoLabel); add(telNoTf); enterButton = new Button("enter"); doneButton = new Button("done"); add(enterButton); add(doneButton); enterButton.addActionListener(this); doneButton.addActionListener(this); sNameTf.addActionListener(this); fNameTf.addActionListener(this); telNoTf.addActionListener(this); dirBase = db; } // end of constructor public void actionPerformed (ActionEvent event) { if (event.getSource() == doneButton) { setVisible(false); } else if (event.getSource() == enterButton) { if ((sName == null) || (fName == null) || (telNoStr == null)) { AlertDialog id = new AlertDialog(this, "Incomplete record specified"); } else { int telNo; telNo = Integer.parseInt(telNoStr); dirBase.add(sName,fName,telNo); sName = null; fName = null; telNoStr = null; sNameTf.setText(null); fNameTf.setText(null); telNoTf.setText(null); } } else if (event.getSource() == sNameTf) { sName = new String(sNameTf.getText()); } else if (event.getSource() == fNameTf) { fName = new String(fNameTf.getText()); } else if (event.getSource() == telNoTf) { telNoStr = new String(telNoTf.getText()); } } // end of method "actionPerformed" public void windowOpened(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowClosed(WindowEvent event) {} public void windowActivated(WindowEvent event) {} public void windowDeactivated(WindowEvent event) {} public void windowClosing(WindowEvent event) { dispose(); } // end of method "windowClosing"} // end of class NewRecGui
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -