📄 delete.java
字号:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class Delete extends Frame implements ActionListener
{
Label l1,message,title;
TextField t1,text[];
Button 确定,删除,退出;
ScrollPane scrollpane;
Panel p1,p2,p3;
GridLayout net;
Connection con;
Statement sql;
ResultSet rs1,rs2;
boolean b;
Delete()
{
super("书籍信息删除窗口");
setBounds(5,100,780,150);
net=new GridLayout(4,1);
setLayout(net);
title=new Label("标识 书名 出版社 作者 出版社地址 出版日期 价格 是否借出",Label.CENTER);
title.setBackground(Color.orange);
l1=new Label("输入要删除书的编号(标识):");
message=new Label(" ");
t1=new TextField(30);
确定=new Button("确定");
删除=new Button("删除");
退出=new Button("退出");
确定.addActionListener(this);
删除.addActionListener(this);
退出.addActionListener(this);
删除.setEnabled(false);
p1=new Panel();
p2=new Panel();
p2.setLayout(new GridLayout(1,8));
text=new TextField[9];
for(int k=1;k<=8;k++)
{
text[k]=new TextField(2);
text[k].setEditable(false);
p2.add(text[k]);
}
p3=new Panel();
p1.add(l1);p1.add(t1);p1.add(确定);p1.add(message);
p3.add(删除);p3.add(退出);
add(p1);
add(title);
add(p2);
add(p3);
setVisible(true);
validate();
try
{
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e1)
{
message.setText("无法建立数据源!");
}
try
{
con=DriverManager.getConnection("jdbc:odbc:book","","");
sql=con.createStatement();
}
catch(SQLException e2)
{
message.setText("没有找到数据表!");
}
addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e)
{
setVisible(false);
dispose();
}});
}
public void actionPerformed(ActionEvent e)
{
String bookid=t1.getText().trim();
bookid="'"+bookid+"'";
if(e.getSource()==确定)
{ text[1].setText("");
try
{
rs1=sql.executeQuery("SELECT * FROM 书籍信息表 WHERE 标识="+bookid);
while(rs1.next())
{
text[1].setText(rs1.getString(1));
text[2].setText(rs1.getString(2));
text[3].setText(rs1.getString(3));
text[4].setText(rs1.getString(4));
text[5].setText(rs1.getString(5));
text[6].setText(rs1.getString(6));
text[7].setText(String.valueOf(rs1.getFloat(7)));
b=rs1.getBoolean(8);
if(b==true)
{
text[8].setText("已经借出");
}
else
{
text[8].setText("没有借出");
}
}
if((text[1].getText().trim()).length()==0)
{
Color c1=message.getBackground();
message.setBackground(Color.red);
message.setText("没有你要删除的书!");
try
{
Thread.sleep(3000);
}
catch(InterruptedException ee){}
message.setBackground(c1);
message.setText(" ");
t1.setText("");
删除.setEnabled(false);
validate();
}
else
{
删除.setEnabled(true);
validate();
}
}
catch(SQLException e3){}
}
if(e.getSource()==删除)
{
try
{
sql.executeUpdate("DELETE FROM 书籍信息表 WHERE 标识="+bookid);
title.setBackground(Color.red);
title.setText("已 成 功 删 除 !");
try
{
Thread.sleep(3000);
}
catch(InterruptedException ee){}
title.setBackground(Color.orange);
t1.setText("");
for(int i=1;i<=8;i++)
text[i].setText("");
title.setText("标识 书名 出版社 作者 出版社地址 出版日期 价格 评论");
删除.setEnabled(false);
}
catch(SQLException e3){}
}
if(e.getSource()==退出)
{
try
{
con.close();
}catch(SQLException e4){}
setVisible(false);
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -