为什么点击按钮跳转不到这个界面,点击按钮没有反应
package GLY;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class qingjiashenpi extends JFrame implements ActionListener{
private static final Statement PraparedStatement = null;
Connection con;
JLabel cpmc = new JLabel("产品名称");
JLabel cpdw = new JLabel("产品单位");
JLabel rkzj = new JLabel("入库总计");
JLabel ckzj = new JLabel("出库总计");
JLabel kc = new JLabel("库存");
JLabel je = new JLabel("金额");
JLabel banner = new JLabel();
Icon biaoti = new ImageIcon("image/4.jpg");
JTextField cpmc1 = new JTextField(10);
JTextField cpdw1 = new JTextField(10);
JTextField rkzj1 = new JTextField(10);
JTextField ckzj1 = new JTextField(10);
JTextField kc1 = new JTextField(10);
JTextField je1 = new JTextField(10);
JButton yes = new JButton("确认");
JButton cx = new JButton("查询");
public void del() {
setTitle("添加统计信息");
setLayout(null);
cpmc.setBounds(180,90,100,50);
cpmc1.setBounds(250,103,200,20);
cpmc.setBounds(180,120,100,50);
cpmc1.setBounds(250,133,200,20);
cpdw.setBounds(180,150,100,50);
cpdw1.setBounds(250,163,200,20);
rkzj.setBounds(180,180,100,50);
rkzj1.setBounds(250,193,200,20);
ckzj.setBounds(180,210,100,50);
ckzj1.setBounds(250,223,200,20);
kc.setBounds(180,240,100,50);
kc1.setBounds(250,253,200,20);
je.setBounds(180,270,100,50);
je1.setBounds(250,283,200,20);
banner.setIcon(biaoti);
banner.setBounds(0,0,800,80);
getContentPane().setBackground(Color.gray);
yes.setBounds(80,400, 80, 30);
cx.setBounds(440, 400, 80,30);
add(cpmc);
add(cpmc1);
add(cpdw);
add(cpdw1);
add(ckzj);
add(ckzj1);
add(rkzj);
add(rkzj1);
add(kc);
add(kc1);
add(je);
add(je1);
add(banner);
add(yes);
add(cx);
yes.addActionListener(this);
cx.addActionListener(this);
setVisible(true);
setBounds(600,300,600,600);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==yes) { //如果你点击的是确认按钮
String s1=cpmc1.getText();
String s2=cpdw1.getText();
String s3=rkzj1.getText(); //获取文本框中的信息
String s4=ckzj1.getText();
String s5=kc1.getText();
//获取文本框中的信息
String s6=je1.getText();
//加载数据库驱动
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e1) {
}
//连接数据库
String uri ="jdbc:mysql://localhost:3306/gsglxt?characterEncoding=gbk"; //ip改为自己的ip,“Stu”数据库中自己新建的数据库名
String user = "root"; //sa为自己的数据库用户名
String password = "123456"; //自己的数据库密码
try {
con = DriverManager.getConnection(uri,user,password);
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
JOptionPane.showMessageDialog(null, "数据库连接成功", "连接数据库",
JOptionPane.INFORMATION_MESSAGE);
try {
if(init()==false){ //如果没有,则执行添加
String sql="insert into gsglxt(name,sex,tel,password,bm,zw,gz)"+"values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"')"; //创建sql语句
Statement statement = null;
try {
statement = con.createStatement();
} catch (SQLException e2) {
e2.printStackTrace();
}
try {
int result = statement.executeUpdate(sql); //执行sql语句
} catch (SQLException e1) {
e1.printStackTrace();
}
JOptionPane.showMessageDialog(null, "添加销售信息成功", "完成",
JOptionPane.INFORMATION_MESSAGE);
dispose();
}
} catch (HeadlessException | SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
//判断添加的Id在数据库中是否存在的方法
public boolean init() throws SQLException {
String s1 = null;
String sql1="select tel FROM gsglxt where tel='"+s1+"'";
PreparedStatement pstm = con.prepareStatement(sql1);// 执行查询
ResultSet rs = pstm.executeQuery();
boolean result = false;
while(rs.next()) {
result = true;
}
rs = pstm.executeQuery();
return result;
}
public static void main(String args[]){
new qingjiashenpi();
}
}
表结构也发一下
从服务器接收到数据以后,需要处理数据是否和数据库匹配