?? 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 + -