JAVA找不到con窗口_有代码,找不到怎么解决,求指教。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

第二段

package z1;

import java.awt.Container;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;

public class StudentInfo extends JFrame implements ActionListener{

JButton displayBtn,addBtn,searchBtn,deleteBtn,updateBtn;

JTextArea displayJta;

JScrollPane jsp;

public StudentInfo(){

super("学生信息管理小工具");

displayBtn=new JButton("浏览");

displayBtn.addActionListener(this);

addBtn=new JButton("增加");

searchBtn=new JButton("查看");

deleteBtn=new JButton("删除");

updateBtn=new JButton("修改");

displayJta=new JTextArea(10,40);

jsp=new JScrollPane(displayJta);

Container con=this.getContentPane();

con.setLayout(new FlowLayout());

con.add(displayBtn);

con.add(addBtn);

con.add(searchBtn);

con.add(deleteBtn);

con.add(updateBtn);

con.add(jsp);

setSize(480,280);

setVisible(true);

}

public void actionPerformed(ActionEvent e){

String s="";

if(e.getSource()==displayBtn){

flag=1;

Conn cc=new Conn();

try{

s=cc.display();

}catch(SQLException|ClassNotFoundException e1){

e1.printStackTrace();

}

displayJta.setText(s);

}

if(e.getSource()==addBtn){

flag=2;

new AddOrUpdate(this,"增加学生信息",true);

}

}

}

class AddOrUpdate extends JDialog implements ActionListener{

JLabel idLb,nameLb,sexLb,ageLb;

JTextField idTf,nameTf,sexTf,ageTf;

JButton OkBtn,CancelBtn;

JFrame jf;

public AddOrUpdate(JFrame jf,String title,boolean model){

super(jf,title,model);

this.jf=jf;

idLb=new JLabel("学号:");

nameLb=new JLabel("姓名:");

sexLb=new JLabel("性别:");

ageLb=new JLabel("年龄:");

if(flag==2){

idTf=new JTextField(10);

nameTf=new JTextField(10);

sexTf=new JTextField(10);

ageTf=new JTextField(10);

}else{

idTf=new JTextField(id,10);

nameTf=new JTextField(name,10);

sexTf=new JTextField(sex,10);

ageTf=new JTextField(age+"",10);

idTf.setEditable(false);

}

OkBtn=new JButton("确定");

OkBtn.addActionListener(this);

CancelBtn=new JButton("取消");

CancelBtn.addActionListener(this);

Container con=this.getContentPane();

con.setLayout(new FlowLayout());

con.add(idLb);

con.add(idTf);

con.add(nameLb);

con.add(nameTf);

con.add(sexLb);

con.add(sexTf);

con.add(ageLb);

con.add(ageTf);

con.add(OkBtn);

con.add(CancelBtn);

this.setLocation(jf.getLocation().x+(jf.getWidth()-180)/2,jf.getLocation().y+(jf.getHeight()-210)/2);

this.setSize(180, 210);

this.setVisible(true);

}

public void actionPerformed(ActionEvent arg0){

String sql,tid,tname,tsex,tage;

tid=idTf.getText();

tname=nameTf.getText();

tsex=sexTf.getText();

tage=ageTf.getText();

if(flag==2){

sql="insert into studeninfo values('"+tid+"','"+tname+"','"+tsex+"',"+tage+")";

}else{

sql="update studeninfo set studetnname='"+tname+"',studentsex='"+tsex+"',studentage="+"tage+where studentID='"+tid+"'";

}

if(arg0.getSource()==OkBtn){

this.hide();

try{

Connection cc=new Conn().getDBConnection();

Statement sm=cc.createStatement();

sm.executeUpdate(sql);

}catch(SQLException|ClassNotFoundException e1){

e1.printStackTrace();

JOptionPane.showMessageDialog(this,"该学生已经存在","提示",1);

}

}else{

this.hide();

}

}

public static void main(String[]args){

StudentInfo stu=new StudentInfo();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值