这几个程序运行出来是awt形式,谁能把他们改成运行出来是swing形式
5)
import java.awt.*;
import java.awt.event.*;
import java.awt.Window;
//班级信息
import java.sql.*;
import javax.swing.*;
public class gradeClass extends Frame implements ActionListener
{
private condb condep = null;
private ResultSet rs = null;
private String sql = null;
private Label lbname = new Label("班级名称");
private Label lbnum = new Label("班级人数");
private Label lbdep = new Label("所属系部");
private Label lbgc = new Label("班级列表");
private TextField txtgc = new TextField(20);
private TextField txtnum = new TextField(20);
private Choice chogc = new Choice();
private Choice chodep = new Choice();
private Button btnadd = new Button("增加");
private Button btndel = new Button("删除");
private Button btnmod = new Button("修改");
private Button btnexit = new Button("退出");
public gradeClass()
{
super();
setTitle("班级信息");
setSize(400,250);
setBackground(Color.LIGHT_GRAY);
this.setLocationRelativeTo(this.getParent());
this.setResizable(false);
setLayout(null);
lbname.setSize(50,20);
lbnum.setSize(50,20);
lbdep.setSize(50,20);
lbgc.setSize(50,20);
txtgc.setSize(170,20);
txtnum.setSize(170,20);
chodep.setSize(170,20);
chogc.setSize(170,20);
btnadd.setSize(50,20);
btndel.setSize(50,20);
btnmod.setSize(50,20);
btnexit.setSize(50,20);
lbname.setLocation(80,50);
lbnum.setLocation(80,80);
lbdep.setLocation(80,110);
lbgc.setLocation(80,140);
txtgc.setLocation(160,50);
txtnum.setLocation(160,80);
chodep.setLocation(160,110);
chogc.setLocation(160,140);
btnadd.setLocation(60,180);
btndel.setLocation(140,180);
btnmod.setLocation(220,180);
btnexit.setLocation(300,180);
add(lbname);
add(lbnum);
add(txtgc);
add(txtnum);
add(btnadd);
add(btndel);
add(btnmod);
add(btnexit);
add(chodep);
add(lbdep);
add(lbgc);
add(chogc);
//initial choice
initchodep();
initchogc();
setVisible(true);
btnadd.addActionListener(this);
btndel.addActionListener(this);
btnmod.addActionListener(this);
btnexit.addActionListener(this);
chodep.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie)
{
condep = new condb();
sql = "select * from gradeclass where gc_dep = '"+chodep.getSelectedItem()+"'";
chogc.removeAll();
try
{
rs = condep.getrs(condep.con,sql);
while(rs.next())
{
chogc.addItem(rs.getString("gc_name"));
}
condep.dbclose(condep.con,rs);
}catch(Exception gce){}
}
});
chogc.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e)
{
txtgc.setText(chogc.getSelectedItem());
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
public void initchogc()
{
condep = new condb();
sql = "select gc_name from gradeclass where gc_dep = '"+chodep.getSelectedItem()+"'";
chogc.removeAll();
try
{
rs = condep.getrs(condep.con,sql);
while(rs.next())
{
chogc.addItem(rs.getString("gc_name"));
}
condep.dbclose(condep.con,rs);
condep = null;
rs = null;
}catch(Exception ee){}
}
public void initchodep()
{
condep = new condb();
sql = "select * from department";
try
{
rs = condep.getrs(condep.con,sql);
while(rs.next())
{
chodep.addItem(rs.getString("dep_name"));
}
condep.dbclose(condep.con,rs);
condep = null;
rs = null;
}catch(Exception ee){}
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("退出"))
{
this.dispose();
}
if(e.getActionCommand().equals("增加"))
{
condep = new condb();
sql = "select * from gradeclass where gc_name = '"+txtgc.getText()+"'";
try
{
rs = condep.getrs(condep.con,sql);
if(rs.next())
{
JOptionPane jop = new JOptionPane();
jop.showConfirmDialog(null,"该用户已经存在!","警告!",-1);
condep.dbclose(condep.con,rs);
condep = null;
rs =null;
}
else
{
sql = "insert into gradeclass values('"+txtgc.getText()+"','"+chodep.getSelectedItem()+"',"+Integer.parseInt(txtnum.getText())+")";
condep = new condb();
try
{
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ue){}
int num =Integer.parseInt(txtgc.getText().substring(txtgc.getText().length()-1));
chogc.addItem(txtgc.getText());
String str =txtgc.getText().substring(0,txtgc.getText().length()-1)+Integer.toString(num+1);
txtgc.setText(str);
condep = null;
}
}catch(Exception be){}
}
if(e.getActionCommand().equals("修改"))
{
//此处添加信息对话框,提示不那嘎修改为空格情况
condep = new condb();
sql = "update gradeclass set gc_name = '"+txtgc.getText()+"' where gc_name = '"+chogc.getSelectedItem()+"'";
try
{
System.out.println(sql);
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ee){}
chogc.remove(chogc.getSelectedIndex());
chogc.add(txtgc.getText());
txtgc.setText("");
condep = null;
}
if(e.getActionCommand().equals("删除"))
{
condep = new condb();
sql = "delete * from gradeclass where gc_name = '"+chogc.getSelectedItem()+"'";
try
{
System.out.println(sql);
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ee){}
chogc.remove(chogc.getSelectedIndex());
txtgc.setText("");
condep = null;
}
}
public static void main(String arg[])
{
gradeClass dep = new gradeClass();
}
}