简单Java课程设计 截图+代码


import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class MYWIND{
public static void main(String args[])
{deluwin a=new deluwin();}

}





class deluwin extends JFrame implements ActionListener
{
JLabel l1,l2;
JTextField t1;
JPasswordField t2;
JButton button;
deluwin()
{ setTitle("登陆");
setLayout(new FlowLayout());
setBounds(50,50,200,150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
l1=new JLabel("用户名");
l2=new JLabel("密 码");
t1=new JTextField(10);
t2=new JPasswordField(10);
button=new JButton("登陆");
button.addActionListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(button);
setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
String a=t1.getText();
String b=t2.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="select * from guanli where name='"+a+"' and password='"+b+"'" ;
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{new mainwin();
this.setVisible(false);
}
else

{
JOptionPane.showMessageDialog(this, "用户名或密码错误!","消息对话",JOptionPane.PLAIN_MESSAGE);

}

}catch(Exception ee){}
}

}






class mainwin extends JFrame implements ActionListener
{
JMenuBar bar;
JMenu menu;
JMenu menu2;
JMenu menu3;
JMenu menu4;
JMenuItem item1,item2,item3,item4 ;
JMenuItem item5,item7,item8 ,item6;
JMenuItem item9,item10,item12;
mainwin()
{
setBounds(50,50,600,200);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
bar=new JMenuBar();
menu=new JMenu("会员管理");
menu2=new JMenu("图书管理");
menu3=new JMenu("借阅管理");
menu4=new JMenu("罚款管理");
item1=new JMenuItem("添加会员");
item2=new JMenuItem("查询会员");
item3=new JMenuItem("删除会员");
item4=new JMenuItem("修改会员");

item5=new JMenuItem("图书查询");
item6=new JMenuItem("图书信息修改");
item7=new JMenuItem("添加图书");
item8=new JMenuItem("删除图书");

item9=new JMenuItem("借出查询");
item10=new JMenuItem("归还查询");

item12=new JMenuItem("罚款查询");
item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);
item4.addActionListener(this);
item5.addActionListener(this);
item6.addActionListener(this);
item8.addActionListener(this);
item7.addActionListener(this);
item9.addActionListener(this);
item10.addActionListener(this);
item12.addActionListener(this);
menu.add(item1);
menu.add(item2);
menu.add(item3);
menu.add(item4);
menu2.add(item5);
menu2.add(item6);
menu2.add(item7);
menu2.add(item8);
menu3.add(item9);
menu3.add(item10);
menu4.add(item12);
bar.add(menu);
bar.add(menu2);
bar.add(menu3);
bar.add(menu4);
setJMenuBar(bar);
setVisible(true);
}

public void actionPerformed(ActionEvent e)
{if(e.getSource()==item1)
{new wr

itewin();
}
if(e.getSource()==item2)
{new searchwin();
}
if(e.getSource()==item3)
{new deletewin();
}
if(e.getSource()==item4)
{new updatewin();

}
if(e.getSource()==item5)
{new searchwin2();

}
if(e.getSource()==item6)
{new updatewin2();

}
{if(e.getSource()==item7)
{new writewin2();
}
if(e.getSource()==item8)
{new deletewin2();
}
if(e.getSource()==item9)
{new searchwin3();

}

if(e.getSource()==item10)
{new searchwin31();

}
if(e.getSource()==item12)
{new searchwin4();

}
}
}
}






class writewin extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2,t3,t4,t5;
JButton button;
writewin()
{setLayout(new FlowLayout());
setBounds(20,20,500,400);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
l1=new JLabel("name");

l2=new JLabel("password");
l3=new JLabel("户名");

l4=new JLabel("性别");
l5=new JLabel("说明");

t1=new JTextField(15);

t2=new JTextField(15);
t3=new JTextField(15);

t4=new JTextField(15);
t5=new JTextField(15);

button=new JButton("添加");
button.addActionListener(this);
button.setBounds(150,260,60,20);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(button);
setVisible(true);

}


public void actionPerformed(ActionEvent e)
{String t11=t1.getText();
String t22=t2.getText();
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="insert into user1(name,password) values('"+t11+"','"+t22+"')";
stmt.executeUpdate(sql);
con.close();}
catch(Exception e1){
System.out.print(e1);}

JOptionPane.showMessageDialog(this, "添加成功!","消息对话",JOptionPane.WARNING_MESSAGE);
this.setVisible(false);
}

}



class updatewin extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;
JButton button0, button;
JTextField password,户名,性别,name;
JTextArea 说明;

updatewin()
{
setLocation(20,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("ID");
add(l0);
l0.setBounds(20,20,30,20);
t0=new JTextField();
add(t0);
t0.setBounds(55,20,80,20);
button0=new JButton("查找");
add(button0);

button0.setBounds(140,20,60,20);
button0.addActionListener(this);

JLabel l11=new JLabel("ID:");
add(l11);
l11.setBounds(20,50,30,20);
name=new JTextField(10);
add(name);
name.setBounds(60,50,80,20);
JLabel l1=new JLabel("密码:");
add(l1);
l1.setBounds(150,50,30,20);
password=new JTextField(10);
add(password);
password.setBounds(190,50,80,20);

JLabel l2=new JLabel("户名:");
add(l2);
l2.setBounds(280,50,30,20);

户名=new JTextField(

10);

add(户名);
户名.setBounds(320,50,80,20);
JLabel l3=new JLabel("性别:");
add(l3);
l3.setBounds(410,50,30,20);

性别=new JTextField(10);
add(性别);
性别.setBounds(450,50,80,20);
JLabel l4=new JLabel("说明");
add(l4);
l4.setBounds(220,80,30,20);


说明=new JTextArea(20,30);


add(说明);
说明.setBounds(40,105,400,200);

button=new JButton("修改");
add(button);
button.setBounds(200,315,60,30);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);


}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button0)
{
String title0=t0.getText().trim();
Connection con;
Statement stmt;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
stmt=con.createStatement();

rs= stmt.executeQuery("select * from user1 where name='"+title0+"'");


if(rs.next())
{
name.setText(rs.getString(1));
password.setText(rs.getString(2));

户名.setText(rs.getString(3));
性别.setText(rs.getString(4));
说明.append(rs.getString(5));


}
con.close();
}
catch(Exception e2) {
System.out.println(e2);
}
}
else if(e.getSource()==button)
{
String date2=password.getText();
String title2=name.getText();
String content2=说明.getText();
String weather2=性别.getText();
String weather1=户名.getText();


Connection con2;
Statement stmt2;
ResultSet rs2;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


con2=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
stmt2=con2.createStatement();
String sql="update user1 set password='"+date2+"',户名='"+weather1+"',说明='"+content2+"',性别='"+weather2+"' where name='"+title2+"'";
stmt2.executeUpdate(sql);
name.setText(null);
password.setText(null);
户名.setText(null);
说明.setText(null);
性别.setText(null);
JOptionPane.showMessageDialog(this, "操作成功!","消息对话",JOptionPane.PLAIN_MESSAGE);
this.setVisible(false);
}catch(Exception e3){ System.out.print(e3);}

}
}
}



class deletewin extends JFrame implements ActionListener
{
JButton button;
JTextField name;
deletewin()
{
setLocation(20,30);
setSize(500,600);
setLayout(new FlowLayout());
add(new JLabel("ID:"));
name=new JTextField(10);
add(nam

e);
button=new JButton("删除");
add(button);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
String title1=name.getText();
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName

("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1) {
System.out.print(e);
}
try {
con=DriverManager.getConnection

("jdbc:odbc:mydate","sa","");
sql=con.createStatement();

sql.executeUpdate("delete from user1 where name='"+title1+"'");

con.close();
JOptionPane.showMessageDialog(this, "删除成功!","消息对话",JOptionPane.PLAIN_MESSAGE);

}
catch(SQLException e2) {
System.out.println(e);
}

}
}

class searchwin2 extends JFrame implements ActionListener
{
JButton button;
JTextField title;
JTextArea content1;
searchwin2()
{

setLocation(20,30);
setSize(700,600);
setLayout(new FlowLayout());
add(new JLabel("图书编号:"));
title=new JTextField(10);
add(title);
button=new JButton("查询");
add(button);
content1=new JTextArea(40,50);
add(content1);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
String title1=title.getText();
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName

("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1) {
System.out.print(e);
}
try {
con=DriverManager.getConnection

("jdbc:odbc:mydate","sa","");
sql=con.createStatement();

rs=sql.executeQuery("select * from tushu where 编号='"+title1+"'");
while(rs.next())
{
content1.append(rs.getString(1)+" ");
content1.append(rs.getString(2)+" ");
content1.append(rs.getString(3)+" ");
content1.append(rs.getString(4)+" ");
content1.append("\n");
}

con.close();

}
catch(SQLException e2) {
System.out.println(e);
}
}
}



class writewin2 extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2,t3,t4,t5;
JButton button;
writewin2()
{setLayout(new FlowLayout());
setBounds(20,20,500,400);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
l1=new JLabel("编号");

l2=new JLabel("书名");

l3=new JLabel("作者");

l4=new JLabel("出版社");

l5=new JLabel("出版日期");


t1=new JTextField(15);

t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
t5=new JTextField(15);

button=new JButton("添加");
button.addActionListener(this);
button.setBounds(150,260,60,20);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(button);
setVisible(true);

}


public void actionP

erformed(ActionEvent e)
{String t11=t1.getText();
String t22=t2.getText();
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="insert into tushu(编号,书名) values('"+t11+"','"+t22+"')";
stmt.executeUpdate(sql);
con.close();}
catch(Exception e1){
System.out.print(e1);}

JOptionPane.showMessageDialog(this, "添加成功!","消息对话",JOptionPane.WARNING_MESSAGE);
this.setVisible(false);
}

}
class updatewin2 extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;
JButton button0, button;
JTextField 出版时间,书名,作者,编号;
JTextArea 出版社;

updatewin2()
{
setLocation(20,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("编号");
add(l0);
l0.setBounds(20,20,30,20);
t0=new JTextField();
add(t0);
t0.setBounds(55,20,80,20);
button0=new JButton("查找");
add(button0);

button0.setBounds(140,20,60,20);
button0.addActionListener(this);

JLabel l11=new JLabel("编号:");
add(l11);
l11.setBounds(20,50,30,20);
编号=new JTextField(10);
add(编号);
编号.setBounds(60,50,80,20);
JLabel l1=new JLabel("书名:");
add(l1);
l1.setBounds(150,50,30,20);
书名=new JTextField(10);
add(书名);
书名.setBounds(190,50,80,20);

JLabel l2=new JLabel("作者:");
add(l2);
l2.setBounds(280,50,30,20);

作者=new JTextField(10);

add(作者);
作者.setBounds(320,50,80,20);
JLabel l3=new JLabel("出版时间:");
add(l3);
l3.setBounds(410,50,30,20);

出版时间=new JTextField(10);
add(出版时间);
出版时间.setBounds(450,50,80,20);
JLabel l4=new JLabel("出版社");
add(l4);
l4.setBounds(220,80,30,20);


出版社=new JTextArea(20,30);


add(出版社);
出版社.setBounds(40,105,400,200);

button=new JButton("修改");
add(button);
button.setBounds(200,315,60,30);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);


}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button0)
{
String title0=t0.getText().trim();
Connection con;
Statement stmt;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
stmt=con.createStatement();

rs= stmt.executeQuery("select * from user1 where name='"+title0+"'");


if(rs.next())
{

编号.setText(rs.getString(1));
书名.setText(rs.getString(2));

作者.setText(rs.getString(3));
出版时间.setText(rs.getString(4));
出版社.append(rs.getString(5));


}
con.close();
}
catch(Exception e2) {
System.out.println(e2);
}
}
else if(e.getSource()==button)
{
String date2=书名.getText();
String title2=编号.getText();
String content2=出版社.getText();
String weather2=出版时间.getText();
String weather1=书名.getText();


Connection con2;
Statement stmt2;
ResultSet rs2;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


con2=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
stmt2=con2.createStatement();
String sql="update user1 set password='"+date2+"',户名='"+weather1+"',说明='"+content2+"',性别='"+weather2+"' where name='"+title2+"'";
stmt2.executeUpdate(sql);
编号.setText(null);
书名.setText(null);
作者.setText(null);
出版社.setText(null);
出版时间.setText(null);
JOptionPane.showMessageDialog(this, "操作成功!","消息对话",JOptionPane.PLAIN_MESSAGE);
this.setVisible(false);
}catch(Exception e3){ System.out.print(e3);}

}
}
}




class deletewin2 extends JFrame implements ActionListener
{
JButton button;
JTextField name;
deletewin2()
{
setLocation(20,30);
setSize(500,600);
setLayout(new FlowLayout());
add(new JLabel("编号:"));
name=new JTextField(10);
add(name);
button=new JButton("删除");
add(button);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}

public void actionPerformed(ActionEvent e)

{
String title1=name.getText();
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName

("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1) {
System.out.print(e);
}
try {
con=DriverManager.getConnection

("jdbc:odbc:mydate","sa","");
sql=con.createStatement();

sql.executeUpdate("delete from tushu where 编号='"+title1+"'");

con.close();
JOptionPane.showMessageDialog(this, "删除成功!","消息对话",JOptionPane.PLAIN_MESSAGE);

}
catch(SQLException e2) {
System.out.println(e);
}

}

}



class searchwin3 extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;

JComboBox b;
JButton button1;
JTextArea c;

searchwin3()
{ setTitle("借出查询");
setLocation(100,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("输入要查询图书编号或会员ID:");
add(l0);
l0.setBo

unds(110,30,300,30);
t0=new JTextField();
add(t0);
t0.setBounds(290,30,150,30);

b=new JComboBox();
b.addItem("编号");
b.addItem("name");



b.setBounds(460,30,80,30);
add(b);

c=new JTextArea(1200,800);
c.setBounds(110,100,750,400);
add(c);
button1=new JButton("查询");
button1.setBounds(570,30,80,30);
add(button1);

button1.addActionListener(this);



setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);



}
public void actionPerformed(ActionEvent e) {
try{
String b1=b.getSelectedItem().toString();

String b2=t0.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="select * from jieyue where "+b1+"='"+b2+"'";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next())
{c.append(rs.getString(1)+" ");
c.append(rs.getString(2)+" ");
c.append("\n");

}



}catch(Exception ee){System.out.print(ee);}}
}


class searchwin31 extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;

JComboBox b;
JButton button1;
JTextArea c;

searchwin31()
{ setTitle("归还查询");
setLocation(100,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("输入要查询图书编号或会员ID:");
add(l0);
l0.setBounds(110,30,300,30);
t0=new JTextField();
add(t0);
t0.setBounds(290,30,150,30);

b=new JComboBox();
b.addItem("编号");
b.addItem("name");



b.setBounds(460,30,80,30);
add(b);

c=new JTextArea(1200,800);
c.setBounds(110,100,750,400);
add(c);
button1=new JButton("查询");
button1.setBounds(570,30,80,30);
add(button1);

button1.addActionListener(this);



setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);



}
public void actionPerformed(ActionEvent e) {
try{
String b1=b.getSelectedItem().toString();

String b2=t0.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="select * from jieyue2 where "+b1+"='"+b2+"'";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next())
{c.append(rs.getString(1)+" ");
c.append(rs.getStrin

g(2)+" ");

c.append("\n");

}



}catch(Exception ee){System.out.print(ee);}}
}

class searchwin4 extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;

JComboBox b;
JButton button1;
JTextArea c;

searchwin4()
{ setTitle("罚款管理");
setLocation(100,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("输入要查询图书编号或会员ID:");
add(l0);
l0.setBounds(110,30,300,30);
t0=new JTextField();
add(t0);
t0.setBounds(290,30,150,30);

b=new JComboBox();
b.addItem("编号");
b.addItem("name");



b.setBounds(460,30,80,30);
add(b);

c=new JTextArea(1200,800);
c.setBounds(110,100,750,400);
add(c);
button1=new JButton("查询");
button1.setBounds(570,30,80,30);
add(button1);

button1.addActionListener(this);



setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);



}
public void actionPerformed(ActionEvent e) {
try{
String b1=b.getSelectedItem().toString();

String b2=t0.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="select * from fakuan where "+b1+"='"+b2+"'";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next())
{c.append(rs.getString(1)+" ");
c.append(rs.getString(2)+" ");
c.append("\n");

}



}catch(Exception ee){System.out.print(ee);}}
}

class searchwin extends JFrame implements ActionListener
{ JLabel l0;
JTextField t0;

JComboBox b;
JButton button1;
JTextArea c;

searchwin()
{ setTitle("会员查询");
setLocation(100,30);
setSize(700,600);
setLayout(null);
l0=new JLabel("输入要查户名或会员ID:");
add(l0);
l0.setBounds(110,30,300,30);
t0=new JTextField();
add(t0);
t0.setBounds(290,30,150,30);

b=new JComboBox();
b.addItem("name");
b.addItem("户名");



b.setBounds(460,30,80,30);
add(b);

c=new JTextArea(1200,800);
c.setBounds(110,100,750,400);
add(c);
button1=new JButton("查询");
button1.setBounds(570,30,80,30);
add(button1);

button1.addActionListener(this);



setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);



}
public void actionPerformed(Action

Event e) {
try{
String b1=b.getSelectedItem().toString();

String b2=t0.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydate","sa","");
Statement stmt=con.createStatement();
String sql="select * from user1 where "+b1+"='"+b2+"'";

ResultSet rs=stmt.executeQuery(sql);

while(rs.next())
{c.append(rs.getString(1)+" ");
c.append(rs.getString(2)+" ");
c.append("\n");

}



}catch(Exception ee){System.out.print(ee);}}
}


相关文档
最新文档