📄 deleteinf.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class deleteinf implements ActionListener,ItemListener{
JDialog dialog;
JTextField tF1=new JTextField();
ButtonGroup bg;
JRadioButton r1,r2;
int op=0;
deleteinf(JFrame f)
{
dialog=new JDialog(f,"删除联糸人",true);
Container dialogPane=dialog.getContentPane();
dialogPane.setLayout(new GridLayout(3,2));
r1=new JRadioButton("姓名");
r2=new JRadioButton("电话");
dialogPane.add(r1);
dialogPane.add(r2);
bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
r1.addItemListener(this);
r2.addItemListener(this);
dialogPane.add(new JLabel("请输入要删除的联糸人的信息:",SwingConstants.CENTER));
dialogPane.add(tF1);
JButton b1=new JButton("删除");
dialogPane.add(b1);
JButton b2=new JButton("取消");
dialogPane.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
//dialog.setBounds(200,150,600,130);
dialog.getRootPane().setDefaultButton(b1);
dialog.pack();
dialog.setVisible(true);
f.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e){System.exit(0);}});
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==r1) op=1;
if(e.getSource()==r2) op=2;
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("删除"))
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:notebook","zxp","121");
Statement s=con.createStatement();
PreparedStatement ps=null;
String n=tF1.getText();
switch(op)
{
case 1:
ps=con.prepareStatement("DELETE FROM phone WHERE name=?");
ps.setString(1, n);
//resultSet=ps.executeQuery();
if(ps.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog,"您要删除的联糸人不存在!");
}else
{
dialog.dispose();
JOptionPane.showMessageDialog(dialog,"删除成功");
con.close();
s.close();
}break;
case 2:
ps=con.prepareStatement("DELETE FROM phone WHERE phone=?");
ps.setString(1, n);
//resultSet=ps.executeQuery();
if(ps.executeUpdate()!=1)
{
JOptionPane.showMessageDialog(dialog,"您要删除的联糸人不存在!");
}else
{
dialog.dispose();
JOptionPane.showMessageDialog(dialog,"删除成功");
con.close();
s.close();
}break;
//con.close();
//s.close();
}
}catch(Exception ex){System.exit(0);}
}
else if(cmd.equals("取消"))
{
dialog.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -