📄 fixsystem.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class Find1 extends JFrame implements ActionListener
{
JLabel l2;
JTextField tf1;
JButton bt5,bt6,bt7;
JPanel p3,p4;
Container c2=null;
String Dno,r1,r2,r3,r4,r5,r6;
Find1()
{
super("查询模块");
c2=getContentPane();
p3=new JPanel();
l2=new JLabel("请输入你要查询的宿舍号:");
l2.setForeground(Color.BLUE);
l2.setFont(new Font("BOLD",Font.BOLD,28));
p3.add(l2);
tf1=new JTextField(20);
p3.add(tf1);
c2.add(p3,BorderLayout.CENTER);
p4=new JPanel();
p4.setLayout(new FlowLayout());
bt5=new JButton("确定");
bt6=new JButton("清除");
bt7=new JButton("退出");
p4.add(bt5);
p4.add(bt6);
p4.add(bt7);
c2.add(p4,BorderLayout.SOUTH);
bt5.addActionListener(this);
bt6.addActionListener(this);
bt7.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try{
if(e.getSource()==bt5)
{
try{
Dno=tf1.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:宿舍管理","df","1234");
String str="select * from 报修 where Dno='"+Dno+"'";
PreparedStatement ps=cn.prepareStatement(str);
ResultSet rs=ps.executeQuery();
System.out.println("Dno="+Dno);
if(rs.next()) {
r1=rs.getString("Dno");
r2=rs.getString("pno");
r3=rs.getString("pname");
r4=rs.getString("rsubmit");
r5=rs.getString("rsolve");
r6=rs.getString("Rreason");
findm1 fx=new findm1(this);
fx.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null,"您输入的宿舍号有误,请重新输入","输入错误",JOptionPane.YES_NO_OPTION);
}
cn.close();
}
catch(SQLException g)
{
System.out.println("Error Code:"+g.getErrorCode());
System.out.println("Message="+g.getMessage());
}
catch(Exception f)
{
f.printStackTrace();
}
}
if(e.getSource()==bt6)
{
tf1.setText("");
tf1.repaint();
}
if(e.getSource()==bt7)
{
System.exit(0);
}
}
catch(NumberFormatException ex)
{ JOptionPane.showMessageDialog(null,"数据转换错误!"); }
}
class findm1 extends JFrame implements ActionListener
{
JTextField tt1,tt2,tt3,tt4,tt5,tt6;
JButton b1;
Find1 parent2;
findm1(Find1 f2)
{
super("宿舍信息");
parent2=f2;
Container cc=getContentPane();
setBackground(new Color(215,215,215));
cc.setLayout(new GridLayout(3,1));
tt1=new JTextField(r1);
tt2=new JTextField(r2);
tt3=new JTextField(r3);
tt4=new JTextField(r4);
tt5=new JTextField(r5);
tt6=new JTextField(r6);
tt1.setEditable(false);
tt2.setEditable(false);
tt3.setEditable(false);
tt4.setEditable(false);
tt5.setEditable(false);
tt6.setEditable(false);
JPanel pp1=new JPanel();
pp1.add(new JLabel("宿舍号为"+Dno+"宿舍信息"));
cc.add(pp1);
JPanel pp2=new JPanel();
pp2.add(new JLabel("宿舍号",SwingConstants.CENTER));
tt1.setText(Dno);
pp2.add(tt1);
pp2.add(new JLabel("物品号",SwingConstants.CENTER));
pp2.add(tt2);
pp2.add(new JLabel("物品名",SwingConstants.CENTER));
pp2.add(tt3);
pp2.add(new JLabel("提交日期",SwingConstants.CENTER));
pp2.add(tt4);
pp2.add(new JLabel("解决日期",SwingConstants.CENTER));
pp2.add(tt5);
pp2.add(new JLabel("报修原因",SwingConstants.CENTER));
pp2.add(tt6);
cc.add(pp2);
JPanel pp3=new JPanel(new FlowLayout());
b1=new JButton("返回");
b1.addActionListener(this);
pp3.add(b1);
cc.add(pp3);
this.setSize(400,300);
}
public void actionPerformed(ActionEvent f)
{
if(f.getSource()==b1)
{
shutdown2();
}
}
public void shutdown2()
{
parent2.setVisible(true);
this.dispose();
}
}
}
class Insert1 extends JFrame implements ActionListener
{
JLabel l3;
JTextField tf2,tf3,tf4,tf5,tf6,tf7;
JButton bt8,bt9,bt10;
JPanel p5,p6;
String Dno,pname,rsubmit,rsolve,pno,Rreason;
Container c3=null;
public Insert1()
{
super("添加模块");
c3=getContentPane();
c3.setLayout(new GridLayout(3,1));
p5=new JPanel(new GridLayout(6,2));
p6=new JPanel(new FlowLayout());
l3=new JLabel("宿舍信息",SwingConstants.CENTER);
l3.setForeground(Color.BLUE);
l3.setFont(new Font("BOLD",Font.BOLD,28));
c3.add(l3);
tf2=new JTextField();
tf3=new JTextField();
tf7=new JTextField();
tf4=new JTextField();
tf5=new JTextField();
tf6=new JTextField();
p5.add(new JLabel("宿舍号",SwingConstants.CENTER));
p5.add(tf2);
p5.add(new JLabel("物品号",SwingConstants.CENTER));
p5.add(tf3);
p5.add(new JLabel("物品名",SwingConstants.CENTER));
p5.add(tf7);
p5.add(new JLabel("提交保修请求日期",SwingConstants.CENTER));
p5.add(tf4);
p5.add(new JLabel("解决日期",SwingConstants.CENTER));
p5.add(tf5);
p5.add(new JLabel("报修原因",SwingConstants.CENTER));
p5.add(tf6);
c3.add(p5);
bt8=new JButton("添加");
bt9=new JButton("清除");
bt10=new JButton("退出");
p6.add(bt8);
p6.add(bt9);
p6.add(bt10);
c3.add(p6);
bt8.addActionListener(this);
bt9.addActionListener(this);
bt10.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt8)
{ addfi();}
if(e.getSource()==bt9)
{ clearform(); }
if(e.getSource()==bt10)
{ shutdown4(); }
}
private void addfi()
{
Dno=tf2.getText();
pno=tf3.getText();
pname=tf7.getText();
rsubmit=tf4.getText();
rsolve=tf5.getText();
Rreason=tf6.getText();
if(Dno.length()==0||pno.length()==0||pname.length()==0||rsubmit.length()==0||
rsolve.length()==0||Rreason.length()==0)
JOptionPane.showMessageDialog(this,"请添加完全信息");
else
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:宿舍管理","df","1234");
String sqm="insert into 报修 values(?,?,?,?,?,?)";
PreparedStatement ps=cn.prepareStatement(sqm);
ps.setString(1,Dno);
ps.setString(2,pno);
ps.setString(3,pname);
ps.setString(4,rsubmit);
ps.setString(5,rsolve);
ps.setString(6,Rreason);
ps.executeUpdate();
cn.close();
JOptionPane.showMessageDialog(this,"添加成功!");
clearform();
}
catch(SQLException e)
{
System.out.println("E Code:"+e.getErrorCode());
System.out.println("E Message="+e.getMessage());
}
catch(Exception e)
{ e.printStackTrace();}
}
}
private void clearform()
{
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
}
private void shutdown4()
{ System.exit(0);
}
}
class Delete1 extends JFrame implements ActionListener
{
String Dno;
JPanel p7,p8;
JLabel l4,l5;
JTextField tf10;
JButton bt11,bt12;
Container c4=null;
public Delete1()
{
super("删除模块");
c4=getContentPane();
c4.setLayout(new GridLayout(3,1));
c4.setFont(new Font("true",Font.TRUETYPE_FONT,13));
p7=new JPanel();
p8=new JPanel();
l4=new JLabel("删除报修信息",SwingConstants.CENTER);
l4.setFont(new Font("true",Font.TRUETYPE_FONT,20));
l4.setForeground(Color.BLUE);
c4.add(l4);
l5=new JLabel("请输入宿舍号");
tf10=new JTextField(10);
p7.add(l5);
p7.add(tf10);
c4.add(p7);
bt11=new JButton("确定");
bt12=new JButton("退出");
p8.add(bt11);
p8.add(bt12);
c4.add(p8);
bt11.addActionListener(this);
bt12.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt11)
{ del2(); }
if(e.getSource()==bt12)
{ shutdown3(); }
}
private void del2()
{
Dno=tf10.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:宿舍管理");
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sqm="delete from 报修 where Dno='"+Dno+"'";
stmt.executeUpdate(sqm);
stmt.close();
cn.close();
JOptionPane.showMessageDialog(this,"删除成功");
}
catch(SQLException e)
{
System.out.println("Error Code:"+e.getErrorCode());
System.out.println("Message="+e.getMessage());
}
catch(Exception e)
{ e.printStackTrace(); }
}
private void shutdown3()
{
System.exit(0);
}
}
public class fixsystem extends JFrame implements ActionListener
{
Container c1=null;
JLabel l1;
JButton bt1,bt2,bt3,bt4;
JPanel p1,p2;
Insert1 insert1=new Insert1();
Delete1 delete1=new Delete1();
Find1 fx1=new Find1();
//findm1 fx=new findm1(fx1);
public fixsystem()
{
super("报修系统");
c1=getContentPane();
l1=new JLabel("欢迎进入宿舍报修系统!",SwingConstants.CENTER);
l1.setForeground(Color.BLUE);
l1.setFont(new Font("BOLD",Font.BOLD,28));
p1=new JPanel();
p1.add(l1);
c1.add(p1,BorderLayout.CENTER);
bt1=new JButton("查询");
bt2=new JButton("添加");
bt3=new JButton("删除");
bt4=new JButton("退出");
p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(bt1);
p2.add(bt2);
p2.add(bt3);
p2.add(bt4);
c1.add(p2,BorderLayout.SOUTH);
fx1.setSize(400,200);
fx1.setVisible(false);
insert1.setSize(400,500);
insert1.setVisible(false);
delete1.setSize(400,200);
delete1.setVisible(false);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
bt4.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if((JButton)e.getSource()==bt1)
fx1.setVisible(true);
if((JButton)e.getSource()==bt2)
insert1.setVisible(true);
if((JButton)e.getSource()==bt3)
delete1.setVisible(true);
if((JButton)e.getSource()==bt4)
System.exit(0);
}
public static void main(String[] args)
{
fixsystem FX=new fixsystem();
FX.setSize(400,200);
FX.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -