📄 readermanagerbean.java
字号:
package com.jlib.client;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import java.awt.Rectangle;
import javax.swing.JComboBox;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.table.TableColumnModel;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
public class ReaderManagerBean extends JFrame {
static int X = 10;
static int XX = 6;
static String[][] s1 = new String[X][7];
String[] s2 = {" ","ID","姓名","所在系","电话","地址","备注"};
static String[][] s3 = new String[XX][5];
String[] s4 = {" ","书名","ISBN","借阅时间","归还时间"};
public static JTable table;
private JScrollPane scrollPane;
private JButton button_4;
private JButton button_3;
private JButton button_2;
private JButton button;
private JTextField textField;
private JRadioButton radioButton_1;
private ButtonGroup buttonGroup = new ButtonGroup();
private JRadioButton radioButton;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JPanel jPanel = null;
private JComboBox jComboBox = null;
private JScrollPane jScrollPane1 = null;
public static JTable jTable = null;
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
try {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJPanel());
} catch (java.lang.Throwable e) {
// TODO: Something
}
}
return jScrollPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
try {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("\u5b8b\u4f53", Font.PLAIN, 12), Color.black));
jPanel.add(getJComboBox());
jPanel.add(getRadioButton());
jPanel.add(getRadioButton_1());
jPanel.add(getTextField());
jPanel.add(getButton());
jPanel.add(getButton_2());
jPanel.add(getButton_3());
jPanel.add(getButton_4());
jPanel.add(getScrollPane());
jPanel.add(getJScrollPane1(), null);
} catch (java.lang.Throwable e) {
// TODO: Something
}
}
return jPanel;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
try {
jComboBox = new JComboBox();
jComboBox.addItem("ID");
jComboBox.addItem("姓名");
jComboBox.setBounds(new Rectangle(14, 25, 245, 20));
jComboBox.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
} catch (java.lang.Throwable e) {
// TODO: Something
}
}
return jComboBox;
}
/**
* This method initializes jScrollPane1
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
try {
jScrollPane1 = new JScrollPane();
jScrollPane1.setBounds(new Rectangle(4, 299, 765, 156));
jScrollPane1.setViewportView(getJTable());
} catch (java.lang.Throwable e) {
// TODO: Something
}
}
return jScrollPane1;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
try {
jTable = new JTable(s3,s4);
jTable.setEnabled(true);
TableColumnModel tcm = jTable.getColumnModel();
tcm.getColumn(0).setMaxWidth(28);
tcm.getColumn(1).setPreferredWidth(100);
tcm.getColumn(2).setPreferredWidth(40);
tcm.getColumn(3).setPreferredWidth(30);
tcm.getColumn(4).setPreferredWidth(60);
tcm.getColumn(5).setPreferredWidth(60);
tcm.getColumn(6).setPreferredWidth(60);
jTable.getTableHeader().setReorderingAllowed(false);
jTable.getTableHeader().setResizingAllowed(true);
jTable.setBounds(new Rectangle(0, 0, 773, 80));
} catch (java.lang.Throwable e) {
// TODO: Something
}
}
return jTable;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try {
UIManager.setLookAndFeel("com.nilo.plaf.nimrod.NimRODLookAndFeel");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ReaderManagerBean thisClass = new ReaderManagerBean();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
/**
* This is the default constructor
*/
public ReaderManagerBean() {
super();
setResizable(false);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(799, 520);
this.setContentPane(getJContentPane());
this.setTitle("读者管理");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
}
return jContentPane;
}
protected JRadioButton getRadioButton() {
if (radioButton == null) {
radioButton = new JRadioButton();
buttonGroup.add(radioButton);
radioButton.setText("精确查找");
radioButton.setSelected(true);
radioButton.setBounds(10, 3, 73, 23);
}
return radioButton;
}
protected JRadioButton getRadioButton_1() {
if (radioButton_1 == null) {
radioButton_1 = new JRadioButton();
buttonGroup.add(radioButton_1);
radioButton_1.setText("模糊查找");
radioButton_1.setBounds(156, 3, 73, 23);
}
return radioButton_1;
}
protected JTextField getTextField() {
if (textField == null) {
textField = new JTextField();
textField.setBorder(new BevelBorder(BevelBorder.LOWERED));
textField.setBounds(14, 55, 245, 20);
}
return textField;
}
protected JButton getButton() {
if (button == null) {
button = new JButton();
button.setText("查询");
button.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
button.setBounds(296, 38, 90, 37);
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
if(radioButton.isSelected()&&jComboBox.getSelectedItem().equals("ID")){
com.jlib.client.ReaderSearchFun rsf = new com.jlib.client.ReaderSearchFun(ReaderManagerBean.this);
rsf.send(com.jlib.client.LoginBean.PORT,com.jlib.client.LoginBean.IP,textField.getText());
rsf.start();
}
if(radioButton_1.isSelected()&&jComboBox.getSelectedItem().equals("ID")){
com.jlib.client.ReaderMSearchFun rmsf = new com.jlib.client.ReaderMSearchFun();
rmsf.send(com.jlib.client.LoginBean.PORT,com.jlib.client.LoginBean.IP,textField.getText());
rmsf.start();
}
}
});
}
return button;
}
protected JButton getButton_2() {
if (button_2 == null) {
button_2 = new JButton();
button_2.setText("刷新");
button_2.setBounds(614, 38, 90, 37);
button_2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
s1[0][1] = null;
s1[0][2] = null;
s1[0][3] = null;
s1[0][4] = null;
s1[0][5] = null;
s1[0][6] = null;
jTable.repaint();
table.repaint();
int i=0;
for(i=0;i<6;i++){
s3[i][1] = null;
s3[i][2] = null;
s3[i][3] = null;
s3[i][4] = null;
s3[i][5] = null;
s3[i][6] = null;
}
}
});
}
return button_2;
}
protected JButton getButton_3() {
if (button_3 == null) {
button_3 = new JButton();
button_3.setText("删除");
button_3.setBounds(402, 38, 90, 37);
button_3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
if(e.getSource()==button_3){
if(JOptionPane.showConfirmDialog(null,"<html><font size=3>确定要删除该用户吗?</b></font></html>" ,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
com.jlib.client.ReaderRemoveFun rrf = new com.jlib.client.ReaderRemoveFun();
rrf.remove(com.jlib.client.LoginBean.IP, com.jlib.client.LoginBean.PORT,textField.getText());
rrf.start();
}
}
}
});
}
return button_3;
}
protected JButton getButton_4() {
if (button_4 == null) {
button_4 = new JButton();
button_4.setText("关闭");
button_4.setBounds(507, 38, 90, 37);
button_4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
ReaderManagerBean.this.setVisible(false);
}
});
}
return button_4;
}
protected JScrollPane getScrollPane() {
if (scrollPane == null) {
scrollPane = new JScrollPane();
scrollPane.setBounds(4, 81, 765, 215);
scrollPane.setViewportView(getTable());
}
return scrollPane;
}
protected JTable getTable() {
if (table == null) {
table = new JTable(s1,s2);
table.setEnabled(true);
TableColumnModel tcm = table.getColumnModel();
tcm.getColumn(0).setMaxWidth(28);
tcm.getColumn(1).setPreferredWidth(100);
tcm.getColumn(2).setPreferredWidth(40);
tcm.getColumn(3).setPreferredWidth(30);
tcm.getColumn(4).setPreferredWidth(60);
tcm.getColumn(5).setPreferredWidth(60);
tcm.getColumn(6).setPreferredWidth(60);
table.getTableHeader().setReorderingAllowed(false); //不可整列移动
table.getTableHeader().setResizingAllowed(true); //不可拉动表格
}
return table;
}
} // @jve:decl-index=0:visual-constraint="55,16"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -