import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.sql.*;
import java.awt.GridLayout;
class myStudent {
public myStudent() {
}
public static void main(String[] args) {
loginFrame lf=new loginFrame();
lf.setVisible(true);
lf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
class mainFrame extends JFrame implements ActionListener{
MenuBar myMenuBar=new MenuBar();
Menu myMenuFile,myMenuEdit,myMenuUser,myMenuAbout;
MenuItem miNew,miOpen,miSave,miSaveAs,miExit;
MenuItem miAdd,miEdit,miDel,miFind,miShow,miUser,miAbout;
public JTable table = new JTable();
Icon background_icon=new ImageIcon("pct.jpg");
JLabel background_Label=new JLabel(background_icon);
public DefaultTableModel mm ;
public mainFrame(){
myMenuFile=new Menu("文件");
miNew=new MenuItem("新建");
miOpen=new MenuItem("打开");
miSave=new MenuItem("保存");
miExit=new MenuItem("退出");
//miNew.enable(false);
//miOpen.enable(false);
//miSave.enable(false);
//myMenuFile.add(miNew);
//myMenuFile.add(miOpen);
//myMenuFile.add(miSave);
myMenuFile.add(miExit);
myMenuEdit=new Menu("数据编辑");
miFind=new MenuItem("查找数据");
miAdd=new MenuItem("添加数据");
miEdit=new MenuItem("修改数据");
miDel=new MenuItem("删除数据");
miShow=new MenuItem("全部显示");
myMenuEdit.add(miFind);
myMenuEdit.add(miAdd);
myMenuEdit.add(miEdit);
myMenuEdit.add(miDel);
myMenuEdit.add(miShow);
myMenuUser=new Menu("用户");
miUser=new MenuItem("编辑用户");
myMenuUser.add(miUser);
myMenuAbout=new Menu("我的课程设计");
miAbout=new MenuItem("课程设计说明");
myMenuAbout.add(miAbout);
myMenuBar.add(myMenuFile);
myMenuBar.add(myMenuEdit);
myMenuBar.add(myMenuUser);
myMenuBar.add(myMenuAbout);
String[] col = {"学号","姓名","性别","民族","年龄","年级","班级","专业"};//创建属性列名
mm= new DefaultTableModel(col,0);
table.setModel(mm);
JScrollPane tableScrollPane = new JScrollPane(table);
this.setMenuBar(myMenuBar);
this.add(tableScrollPane);
miExit.addActionListener(this);
miFind.addActionListener(this);
miAdd.addActionListener(this);
miEdit.addActionListener(this);
miDel.addActionListener(this);
miShow.addActionListener(this);
miUser.addActionListener(this);
miAbout.addActionListener(this);
}
class myConnection{
ResultSet re;
String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=学生管理数据库.mdb";
public myConnection(){}
public ResultSet getResult(String sql){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet re=stmt.executeQuery(sql);
return re;
}
catch(Exception e){
System.out.println("getResult------"+e.toString());
return null;
}
}
class addFrame extends JDialog implements ActionListener{
public static final int WIDTH = 400;
public static final int HEIGHT = 400;
JLabel 学号1,姓名1,性别1,民族1,年龄1,年级1,班级1,专业1;
JTextField 学号,姓名,性别,民族,年龄,年级,班级,专业;
JButton b;
JPanel p;
mainFrame mf;
class editFrame extends JDialog implements ActionListener{
public static final int WIDTH = 400;
public static final int HEIGHT = 400;
JLabel 学号1,姓名1,性别1,民族1,年龄1,年级1,班级1,专业1;
JTextField 学号,姓名,性别,民族,年龄,年级,班级,专业;
JButton b;
JPanel p;
mainFrame mf;
class findFrame extends JDialog implements ActionListener{
mainFrame mf;
JPanel p;
JComboBox c;
JTextField t;
JButton b;
JButton fAll;
String sql="select * from student";
String[] colStr={"学号","姓名","性别","民族","年龄","年级","班级","专业"};
public findFrame(mainFrame mmf){
mf=mmf;
p=new JPanel();
c=new JComboBox(colStr);
t=new JTextField(10);
b=new JButton("查找");
fAll=new JButton("全部显示");
b.addActionListener(this);
fAll.addActionListener(this);
p.add(new JLabel("选择"));
p.add(c);
p.add(new JLabel("查找内容"));
p.add(t);
p.add(b);
p.add(fAll);
this.add(p);
this.setTitle("查找");
this.setSize(450,80);
}
class aboutFrame extends JDialog{
aboutFrame(){
JPanel p1=new JPanel();
p1.add(new JLabel("学生信息管理系统"));
p1.add(new JLabel("白金晓 201006040203"));
p1.add(new JLabel("承德石油高等专科学校"));
p1.add(new JLabel("计算机类1002 "));
p1.setLayout(new GridLayout(4,1,5,5));
this.add(p1);
this.setTitle("关于我");
this.setSize(300,200);
}
}
class userFrame extends JFrame implements ActionListener{
JTextField user,pass;
JButton add,del;
JTable t;
JPanel p1,p2,p3,p4,p5;
DefaultTableModel m;
public userFrame(){
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
user=new JTextField(8);
pass=new JTextField(8);
add=new JButton("添加");
del=new JButton("删除");
String[] col = {"用户名","密码"};
m= new DefaultTableModel(col,0);
t=new JTable();
t.setModel(m);
JScrollPane sp = new JScrollPane(t);
p1.add(new JLabel("用户名"));
p1.add(user);
p1.add(new JLabel("密码"));
p1.add(pass);
p1.add(add);
p2.add(sp);
p3.add(del);
add.addActionListener(this);
del.addActionListener(this);
myConnection conn=new myConnection();
ResultSet rs;
rs=conn.getResult("select * from 管理员");
if (rs!=null){
try{
//m.setRowCount(0);
//table.setModel(mm);
while(rs.next()){
String 用户名 = rs.getString("用户名");
String 密码 = rs.getString("密码");
String[] cloumns ={用户名,密码};
m.addRow(cloumns);
}
t.setModel(m);
}catch(Exception e){
System.out.println(e.toString());
}
}
this.add(p1,BorderLayout.NORTH);
this.add(p2,BorderLayout.CENTER);
this.add(p3,BorderLayout.SOUTH);
this.add(p4,BorderLayout.WEST);
this.add(p5,BorderLayout.EAST);
this.setTitle("用户管理");
this.setSize(600,400);
}
class loginFrame extends JDialog implements ActionListener{
JPanel p;
JTextField user,pass;
JButton login,cancel;
public loginFrame(){
p=new JPanel();
user=new JTextField(10);
pass=new JTextField(10);
login=new JButton("登录");
cancel=new JButton("退出");
login.addActionListener(this);
cancel.addActionListener(this);
Icon background_icon=new ImageIcon("pct.jpg");
JLabel background_Label=new JLabel(background_icon);
p.add(background_Label);
p.add(new JLabel("账号"));
p.add(user);
p.add(new JLabel("密码"));
p.add(pass);
p.add(login);
p.add(cancel);
this.add(p);
this.setTitle("系统登录");
this.setSize(360,260);
}
发了 查收 聊天程序也发你了
我有
你好。
聊天室代码刚刚发过去了。
学生信息管理系统类库太多,不好发。