📄 querypanel.java
字号:
// 查询通话记录的图形用户界面
package Telephone;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QueryPanel extends JPanel implements ActionListener {
// 属性
protected JApplet applet; // 当前正在运行的Applet
protected JTextField subscriberTextField; // 输入用户名字的字段
protected JPanel tablePanel; // 显示二维表的面板
// 构造方法,显示图形用户界面
public QueryPanel(JApplet applet) {
this.applet = applet;
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
// 查询条件面板
JPanel conditionPanel = new JPanel(new BorderLayout());
conditionPanel.setBorder(BorderFactory.createEtchedBorder());
add("North", conditionPanel);
// 顾客姓名面板
JPanel subscriberPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
conditionPanel.add("Center", subscriberPanel);
// 顾客姓名的标签
JLabel subscriberLabel = new JLabel("电话用户名");
subscriberPanel.add(subscriberLabel);
// 顾客姓名的文本域
subscriberTextField = new JTextField();
subscriberTextField.setPreferredSize(new Dimension(160, 18));
subscriberPanel.add(subscriberTextField);
// 按钮面板
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
conditionPanel.add("East", buttonPanel);
// 查询按钮
JButton queryButton = new JButton("查询");
queryButton.setActionCommand("QUERY");
queryButton.addActionListener(this);
buttonPanel.add(queryButton);
// 重置按钮
JButton resetButton = new JButton("清除");
resetButton.setActionCommand("RESET");
resetButton.addActionListener(this);
buttonPanel.add(resetButton);
// 以带标签窗格显示查询结果
JTabbedPane resultTabbedPane = new JTabbedPane();
add(resultTabbedPane);
// 查询页面
tablePanel = new JPanel(new BorderLayout());
resultTabbedPane.addTab("查询结果", null, tablePanel, "");
// 显示上述GUI控件
validate();
setVisible(true);
}
// 实现ActionListener规定的事件处理程序,对发生的事件evt进行处理
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (cmd.equals("QUERY")) { // 处理"查询"按钮
String subscriber = subscriberTextField.getText();
if (subscriber.equals("")) return;
// 调用远程对象的方法进行查询
Database.DatabaseTableModel result = null;
try {
// 从Applet提取主机名
String host = "//" + applet.getCodeBase().getHost() + "/";
// 远程对象的标识必须与服务程序注册时使用的对象标识完全相同
String objectId = "CallManager";
// 根据主机名与对象标识解析远程对象
CallManagerInterface manager = (CallManagerInterface)
java.rmi.Naming.lookup(host + objectId);
// 调用远程对象方法查询用户的通话记录
result = manager.getCallHistory(subscriber);
} catch(Exception exc) {
exc.printStackTrace();
}
// 将查询结果显示为二维表
tablePanel.removeAll();
tablePanel.add(new JScrollPane(new JTable(result)));
tablePanel.validate();
} else if (cmd.equals("RESET")) { // 处理"清除"按钮
subscriberTextField.setText("");
subscriberTextField.requestFocus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -