📄 userpanel.java~2~
字号:
package mysiloer;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
/**
* <p>Title: MySiloer</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: yskey</p>
* @author 杨涛
* @version 1.0
*/
public class UserPanel extends JPanel {
private BorderLayout borderLayout1 = new BorderLayout();
private JButton manageButton = new JButton();
private Component component4;
private TablePanel tablePanel = new TablePanel();
private JSplitPane jSplitPane1 = new JSplitPane();
private FlowLayout flowLayout1 = new FlowLayout();
private JPanel controlPanel = new JPanel();
private JLabel label = new JLabel();
private JPanel subPanel = new JPanel(new BorderLayout());
private JButton changeButton = new JButton();
private JLabel jLabel1 = new JLabel();
Connection con = null;
private Toolkit kit = Toolkit.getDefaultToolkit();
public UserPanel(MainFrame frame) {
try {
this.con = frame.dataBase.connection;
jbInit();
showAll();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
void jbInit() throws Exception {
component4 = Box.createHorizontalStrut(8);
jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
manageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
manageButton_actionPerformed(e);
}
});
manageButton.setVerticalTextPosition(AbstractButton.CENTER);
manageButton.setText("管理用户");
manageButton.setMargin(new Insets(2, 2, 2, 2));
manageButton.setPreferredSize(new Dimension(100, 40));
manageButton.setMinimumSize(new Dimension(100, 40));
manageButton.setMaximumSize(new Dimension(100, 40));
this.setLayout(borderLayout1);
controlPanel.setLayout(flowLayout1);
label.setForeground(Color.blue);
label.setFont(new Font("宋体", Font.BOLD, 15));
changeButton.setMinimumSize(new Dimension(100, 40));
changeButton.setPreferredSize(new Dimension(100, 40));
changeButton.setMargin(new Insets(2, 2, 2, 2));
changeButton.setVerticalTextPosition(AbstractButton.CENTER);
changeButton.setText("更改密码");
changeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
changeButton_actionPerformed(e);
}
});
jLabel1.setText(" ");
controlPanel.add(manageButton, null);
controlPanel.add(component4, null);
controlPanel.add(jLabel1, null);
controlPanel.add(changeButton, null);
jSplitPane1.add(subPanel, JSplitPane.BOTTOM);
jSplitPane1.add(controlPanel, JSplitPane.TOP);
subPanel.add(label, BorderLayout.NORTH);
subPanel.add(tablePanel, BorderLayout.CENTER);
this.add(jSplitPane1, BorderLayout.CENTER);
tablePanel.table.setPreferredScrollableViewportSize(new Dimension(750, 360));
// tablePanel.table.setPreferredScrollableViewportSize(new Dimension(1150, 770));
}
void manageButton_actionPerformed(ActionEvent e) {
UserManageDialog dialog = new UserManageDialog(this, "用户管理对话框", true);
dialog.setVisible(true);
}
void changeButton_actionPerformed(ActionEvent e) {
ChangePwdDialog dialog = new ChangePwdDialog(this, "修改密码对话框!!", true);
dialog.setVisible(true);
}
void showAll(){
try{
Statement sta = con.createStatement();
ResultSet set = sta.executeQuery("select userName as '用 户 名' from "+Type.USERTABLE);
ResultSetMetaData meta = set.getMetaData();
// int colCount = meta.getColumnCount() +1;
int colCount = meta.getColumnCount();
int rowCount = this.tablePanel.tbModel.getRowCount();
for(int i = 0; i < rowCount; i++){
tablePanel.tbModel.removeRow(0);
}
Vector colNames = new Vector();
Vector row;
colNames.add("序 号");
for(int i = 1; i <= colCount; i++){
colNames.add(meta.getColumnLabel(i));
}
colNames.add("密 码");
tablePanel.tbModel.setColumnIdentifiers(colNames);
int j = 1;
while(set.next()){
row = new Vector();
Integer rowNumber = new Integer(j++);
row.add(rowNumber);
for(int i = 1; i <= colCount; i++){
String temp = set.getString(i);
row.add(temp);
row.add("●●●●●●●●");
// System.out.print(set.getString(i)+" ");
}
// System.out.println();
tablePanel.tbModel.addRow(row);
}//end while
set.close();
sta.close();
}
catch(SQLException ex){
System.err.println(ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -