📄 clientgui.java
字号:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.io.LineNumberReader;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import Bank.AccountInfo;
import database.*;
public class ClientGUI extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField bal_textField;
private JTextPane message_textPane;
private JTextField name_textField;
private JTextField id_textField;
private JTable main_table;
private JScrollPane main_table_pane;
private ButtonGroup buttonGroup = new ButtonGroup();
Bank.AccountIterator accIterator;
AccountInfo[] al;
DatabaseTableModel model;
String sql;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
ClientGUI frame = new ClientGUI();
frame.setVisible(true);
//初始化ORB
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
//利用POA全名与对象标识"BankManager"查找账户管理员
LineNumberReader input = new LineNumberReader(new FileReader("iteratorServer.ior"));
String ior = input.readLine();
org.omg.CORBA.Object obj = orb.string_to_object(ior);
frame.accIterator = Bank.AccountIteratorHelper.narrow(obj);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public ClientGUI() {
super();
//
setBounds(100, 100, 600, 425);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JSplitPane main_splitPane = new JSplitPane();
getContentPane().add(main_splitPane, BorderLayout.CENTER);
final JPanel qurry_panel = new JPanel();
qurry_panel.setLayout(new BorderLayout());
main_splitPane.setLeftComponent(qurry_panel);
final JSplitPane qurry_splitPane = new JSplitPane();
qurry_splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
qurry_panel.add(qurry_splitPane);
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
qurry_splitPane.setLeftComponent(panel);
id_textField = new JTextField();
panel.add(id_textField);
final JRadioButton idRadioButton = new JRadioButton();
idRadioButton.setText("ID");
panel.add(idRadioButton, BorderLayout.NORTH);
buttonGroup.add(idRadioButton);
final JPanel panel_1 = new JPanel();
panel_1.setLayout(new BorderLayout());
panel.add(panel_1, BorderLayout.SOUTH);
name_textField = new JTextField();
panel_1.add(name_textField);
final JRadioButton nameRadioButton = new JRadioButton();
nameRadioButton.setText("NAME");
panel_1.add(nameRadioButton, BorderLayout.NORTH);
buttonGroup.add(nameRadioButton);
final JPanel balance_panel = new JPanel();
balance_panel.setLayout(new BorderLayout());
qurry_splitPane.setRightComponent(balance_panel);
final JPanel panel_2 = new JPanel();
panel_2.setLayout(new BorderLayout());
balance_panel.add(panel_2);
final JPanel panel_3 = new JPanel();
panel_3.setLayout(new BorderLayout());
panel_2.add(panel_3);
message_textPane = new JTextPane();
panel_3.add(message_textPane);
final JPanel panel_6 = new JPanel();
panel_6.setLayout(new BorderLayout());
panel_3.add(panel_6, BorderLayout.NORTH);
final JPanel panel_7 = new JPanel();
panel_7.setLayout(new BorderLayout());
panel_6.add(panel_7, BorderLayout.SOUTH);
bal_textField = new JTextField();
panel_7.add(bal_textField);
final JRadioButton low_radioButton = new JRadioButton();
low_radioButton.setText("小于");
panel_7.add(low_radioButton, BorderLayout.NORTH);
buttonGroup.add(low_radioButton);
final JPanel panel_4 = new JPanel();
panel_4.setLayout(new BorderLayout());
panel_2.add(panel_4, BorderLayout.NORTH);
final JRadioButton high_radioButton = new JRadioButton();
high_radioButton.setText("大于");
panel_4.add(high_radioButton);
buttonGroup.add(high_radioButton);
final JRadioButton equal_radioButton = new JRadioButton();
equal_radioButton.setText("等于");
panel_4.add(equal_radioButton, BorderLayout.SOUTH);
buttonGroup.add(equal_radioButton);
final JLabel balanceLabel = new JLabel();
balanceLabel.setText(" BALANCE的取值");
balance_panel.add(balanceLabel, BorderLayout.NORTH);
final JLabel left_label = new JLabel();
left_label.setText("选择查询条件");
qurry_panel.add(left_label, BorderLayout.NORTH);
final JPanel main_panel = new JPanel();
main_panel.setLayout(new BorderLayout());
main_splitPane.setRightComponent(main_panel);
main_table = new JTable();
main_table_pane = new JScrollPane();
main_panel.add(main_table_pane, BorderLayout.CENTER);
main_table_pane.setViewportView(main_table);
final JLabel right_label = new JLabel();
right_label.setText("查询结果: ");
main_panel.add(right_label, BorderLayout.NORTH);
final JPanel button_panel = new JPanel();
main_panel.add(button_panel, BorderLayout.SOUTH);
final JLabel nowPage_label = new JLabel();
final JLabel totalPage_label = new JLabel();
final JButton fisrt_button = new JButton();
fisrt_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//得到当前页要显示的数据
al = accIterator.returnFirstPage();
DatabaseTableModel model= new DatabaseTableModel(al ,true);
main_table.setModel(model);
right_label.setText("查询结果: "+" 当前页有"+al.length+"条记录");
accIterator.setNowPage(1);
nowPage_label.setText(""+accIterator.getNowPage());
}
});
fisrt_button.setText("首页");
button_panel.add(fisrt_button);
final JButton pre_button = new JButton();
pre_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
message_textPane.setText("");
if(accIterator.hasPre()){
//得到当前要显示的数据
al = accIterator.pre();
DatabaseTableModel model= new DatabaseTableModel(al ,true);
main_table.setModel(model);
right_label.setText("查询结果: "+" 当前页有"+al.length+"条记录");
nowPage_label.setText(""+accIterator.getNowPage());
}else{
message_textPane.setText("到顶了,请向后浏览!");
}
}
});
pre_button.setText("上一页");
button_panel.add(pre_button);
final JButton next_button = new JButton();
next_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
message_textPane.setText("");
if(accIterator.hasNext()){
//得到当前要显示的数据
al = accIterator.next(sql);
DatabaseTableModel model= new DatabaseTableModel(al ,true);
main_table.setModel(model);
right_label.setText("查询结果: "+" 当前页有"+al.length+"条记录");
nowPage_label.setText(""+accIterator.getNowPage());
}else{
message_textPane.setText("到底了,请向前浏览!");
}
}
});
next_button.setText("下一页");
button_panel.add(next_button);
final JButton last_button = new JButton();
last_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//得到当前要显示的数据
al = accIterator.returnLastPage();
DatabaseTableModel model= new DatabaseTableModel(al ,true);
main_table.setModel(model);
right_label.setText("查询结果: "+" 当前页有"+al.length+"条记录");
accIterator.setNowPage(Integer.parseInt(totalPage_label.getText()));
nowPage_label.setText(""+accIterator.getNowPage());
}
});
last_button.setText("尾页");
button_panel.add(last_button);
//final JLabel nowPage_label = new JLabel();
//nowPage_label.setText("10000");
button_panel.add(nowPage_label);
final JLabel patition_label = new JLabel();
patition_label.setText("/");
button_panel.add(patition_label);
//final JLabel totalPage_label = new JLabel();
//totalPage_label.setText("10000");
button_panel.add(totalPage_label);
final JButton start_button = new JButton();
start_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try{
accIterator.clean();
if(idRadioButton.isSelected()){
sql = "SELECT * FROM Accounts WHERE id = '"+ id_textField.getText()+ "'";
}else if (nameRadioButton.isSelected()){
sql = "SELECT * FROM Accounts WHERE name = '"+ name_textField.getText()+ "'";
}else if(high_radioButton.isSelected()){
sql = "SELECT * FROM Accounts WHERE balance > "+ bal_textField.getText();
}else if(equal_radioButton.isSelected()){
sql = "SELECT * FROM Accounts WHERE balance = "+ bal_textField.getText();
}else if(low_radioButton.isSelected()){
sql = "SELECT * FROM Accounts WHERE balance < "+ bal_textField.getText();
}
//得到当前要显示的数据
al = accIterator.next(sql);
//看是否没有查找到结果
if(al[0].id.equals("null")){
message_textPane.setText("没有查到符合查询条件的记录!");
return;
}
totalPage_label.setText(""+accIterator.getTotalPage());
nowPage_label.setText(""+accIterator.getNowPage());
model = new DatabaseTableModel(al ,true);
right_label.setText("查询结果: "+" 当前页有"+al.length+"条记录");
main_table.setModel(model);
message_textPane.setText("查询成功!");
}catch(Exception e){
message_textPane.setText("查询出错!");
e.printStackTrace();
}
}
});
start_button.setText("查询");
button_panel.add(start_button);
final JButton exit_button = new JButton();
exit_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(1);
}
});
exit_button.setText("退出");
button_panel.add(exit_button);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -