📄 haha.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.sql.*;
class haha extends Frame implements ActionListener
{ TextField t1,t2,t3,t4,t5,t6;
Box box1,box2,baseBox,box4,base,box,box5;
Button but2,but1,but3,but4,but5,but6;
Boolean IP;
JTable table;
Object a[][];
Object name[]={"商品编号","商品名称","商品价格","实收金额","购物日期"};
Connection con;
PreparedStatement sql;
ResultSet rs;
haha(){
setTitle("用户界面");
but1=new Button("查询商品信息");but1.addActionListener(this);
but2=new Button("查询VIP信息");
but2.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{ int i=0,m=0,n=0,h=0,j=0;
if(IP){
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException ee)
{System.out.println(ee);}
try
{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.prepareStatement("select * from CONSUME where VIP编号="+Integer.parseInt(t1.getText()) );
rs=sql.executeQuery();
while(rs.next())
{
int tq=rs.getInt("商品编号");
String s1=rs.getString("商品名称");
String s2=rs.getString("商品价格");
String fq=rs.getString("实收金额");
String s3=rs.getString("购物日期");
a[n++][0]=tq;
a[i++][1]=s1;
a[j++][2]=s2;
a[h++][3]=fq;
a[m++][4]=s3;
}
con.close();
}
catch(SQLException w)
{System.out.println(w);}
}
}
});
but3=new Button("help");but3.addActionListener(this);
but4=new Button("sure");
but5=new Button("注销");but5.addActionListener(this);
but6=new Button("退出");
t1=new TextField(10);
//t1.setEditable(false);
//t1.setText("sfje");
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
t5=new TextField(10);
t6=new TextField(10);
box1=Box.createVerticalBox();
box1.add(Box.createVerticalStrut(14));
box1.add(new Label("VIP编号:"));
box1.add(Box.createVerticalStrut(14));
box1.add(t1);
box1.add(Box.createVerticalStrut(14));
box1.add(new Label("姓名:"));
box1.add(Box.createVerticalStrut(14));
box1.add(t2);
box1.add(Box.createVerticalStrut(14));
box1.add(but4);
but4.addActionListener(this);
box2=Box.createVerticalBox();
box2.add(Box.createVerticalStrut(4));
box2.add(but1);
box2.add(Box.createVerticalStrut(4));
box2.add(but2);
box2.add(Box.createVerticalStrut(4));
box2.add(but3);box2.add(Box.createVerticalStrut(4));
box2.add(but5);box2.add(Box.createVerticalStrut(4));
box2.add(but6);but6.addActionListener(this);
baseBox=Box.createVerticalBox();
baseBox.add(Box.createVerticalStrut(14));
baseBox.add(box1);
baseBox.add(Box.createVerticalStrut(14));
baseBox.add(box2);
a=new Object[28][5];
setBounds(100,100,400,400);
table=new JTable(a,name);
box4=Box.createVerticalBox();
box4.add(Box.createVerticalStrut(8));
box4.add(new JScrollPane(table));
base=Box.createHorizontalBox();
base.add(baseBox);
base.add(Box.createHorizontalStrut(10));
base.add(Box.createHorizontalStrut(10));
base.add(box4);
box=Box.createVerticalBox();
box.add(base);
box.add(Box.createVerticalStrut(4));
setBounds(100,100,700,500);
setBackground(Color.pink);
setLayout(new FlowLayout());
add(box);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
// System.exit(0);
}
});
}public void actionPerformed(ActionEvent ee)
{ if(ee.getSource()==but3){JOptionPane.showMessageDialog(this,"请登录www.help.html咨询",
"通知对话框",JOptionPane.PLAIN_MESSAGE);
}
else if(ee.getSource()==but1&& IP){new goods();}
else if(ee.getSource()==but6 )System.exit(0);
else if(ee.getSource()==but4)
{ Connection con;
PreparedStatement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException te)
{System.out.println(te);}
try
{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.prepareStatement("select * from consume");
rs=sql.executeQuery();
while(rs.next())
{
if(Integer.parseInt(t1.getText())==(rs.getInt("VIP编号"))&&t2.getText().equals(rs.getString("姓名")))
{
IP=true;t1.setEditable(false);
t2.setEditable(false);
}
}
con.close();
}
catch(SQLException u)
{
System.out.println(u);
}
}
else if(ee.getSource()==but5){ for(int u=0;u<18;u++)
for(int y=0;y<5;y++) a[u][y]="";
IP=false;
t1.setEditable(true);t2.setEditable(true); }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -