引用: |
【令小虎翀的贴子】都改了,还是老样子,老大,你能做个简单的监听给我试试吗,谢谢了啊 ……………… |
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Exam extends JFrame implements ActionListener
{
Container con;
JLabel jl1,jl2,jl3;
JTextField jtf1,jtf2,jtf3;
JButton jb1,jb2,jb3;
public Exam()
{
con=this.getContentPane();
con.setLayout(null);
jl1=new JLabel("班号");
jl2=new JLabel("参考人数");
jl3=new JLabel("通过认输");
jtf1=new JTextField("");
jtf2=new JTextField("");
jtf3=new JTextField("");
jb1=new JButton("输入数据");
jb2=new JButton("通过率查询");
jb3=new JButton("关闭");
con.add(jl2);
con.add(jl1);
con.add(jl3);
con.add(jtf1);
con.add(jtf2);
con.add(jtf3);
con.add(jb1);
con.add(jb2);
con.add(jb3);
jl1.setBounds(20,30,100,30);
jtf1.setBounds(20,60,100,30);
jl2.setBounds(150,30,100,30);
jtf2.setBounds(150,60,100,30);
jl3.setBounds(280,30,100,30);
jtf3.setBounds(280,60,100,30);
jb1.setBounds(50,150,100,30);
jb2.setBounds(180,150,100,30);
jb3.setBounds(130,200,100,30);
jb3.addActionListener(this);
jb2.addActionListener(this);
jb1.addActionListener(this);
this.setSize(400,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jb1)
{
int class_id=Integer.parseInt(jtf1.getText());
int total=Integer.parseInt(jtf2.getText());
int pass=Integer.parseInt(jtf3.getText());
float ratio=((float)pass)/((float)total);
try
{
SQLDemo sql=new SQLDemo();
sql.insert(class_id,total,pass,ratio);
}
catch(ClassNotFoundException ee)
{
ee.printStackTrace();
}
catch(SQLException ee)
{
ee.printStackTrace();
}
JOptionPane.showMessageDialog(con,"数据添加成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
else if(e.getSource()==jb2)
{
Find f =new Find();
this.dispose();
}
else if(e.getSource()==jb3)
{
this.dispose();
}
}
public static void main(String[] args)
{
Exam no1=new Exam();
no1.setTitle("考试通过率设计");
}
}