📄 vip.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.sql.*;
class VIP extends JFrame implements ActionListener
{ Object a[][];
Object name[]={"VIP编号","姓名"};
Connection con;
PreparedStatement sql,sqk;
ResultSet rs;
Button but1,but3,but2;
JTable table;
Label l1,l2,l3;
TextField t1,t2,t3,t4,t5,t6;
Box box,box1,box2;
VIP(){
setTitle("管理VIP用户界面");
but1=new Button("添加");
but2=new Button("删除");
but3=new Button("查看");
but1.addActionListener(this);
but2.addActionListener(this);
but3.addActionListener(this);
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
t5=new TextField(10);
t6=new TextField(10);
l1=new Label("输入编号");
l3=new Label("输入姓名");
l2=new Label("输入你要删除的编号");
a=new Object[28][2];
table=new JTable(a,name);
box=Box.createVerticalBox();
box.add(l1);box.add(Box.createVerticalStrut(18));
box.add(t1);box.add(Box.createVerticalStrut(18));
box.add(l3);box.add(Box.createVerticalStrut(18));
box.add(t2);box.add(Box.createVerticalStrut(18));
box.add(but1);box.add(Box.createVerticalStrut(18));
box.add(l2);box.add(Box.createVerticalStrut(18));
box.add(t3);box.add(Box.createVerticalStrut(18));
box.add(but2);box.add(Box.createVerticalStrut(18));
box.add(but3);box.add(Box.createVerticalStrut(18));
box1=Box.createVerticalBox();
box1.add(new JScrollPane(table));
box2=Box.createHorizontalBox();
box2.add(box);box2.add(Box.createHorizontalStrut(10));
box2.add(box1);
add(box2);
setLayout(new FlowLayout());
setBounds(10,10,700,500);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
// System.exit(0);
}
});
}
public void actionPerformed(ActionEvent te)
{ String s="",h,y,k;h=t1.getText();y=t2.getText();k=t3.getText();
Boolean Ip=false;int n=0,m=0;
if(te.getSource()==but1){System.out.println("but1");
s="insert into VIPConsumption (VIP编号,姓名) values('"+h+"','"+y+"')";
}
else if (te.getSource()==but2){System.out.println("but2");
s=" delete * from VIPConsumption where VIP编号='"+k+"'";}
else if (te.getSource()==but3){System.out.println("but3");
s="select * from VIPConsumption";Ip=true;}
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ee)
{System.out.println(ee);}
try
{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
if(Ip)
{sql=con.prepareStatement(s);
rs=sql.executeQuery();
while(rs.next())
{ String b=rs.getString(1);
String c=rs.getString(2);
a[n++][0]=b;
a[m++][1]=c;
System.out.println(b+c);
}
}
else{ sqk=con.prepareStatement(s); sqk.executeUpdate();}
con.close();
}
catch(SQLException w)
{System.out.println(w);
}
}
}
/*public class sun
{ public static void main(String args[])
{new VIP();
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -