| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:java程序该成swing形式(2)
只看楼主 加入收藏
南孤傲天
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-11-28
收藏
 问题点数:0 回复次数:0 
java程序该成swing形式(2)

这几个程序运行出来是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();
}
}

搜索更多相关主题的帖子: 形式 swing java 
2005-12-01 11:18
快速回复:java程序该成swing形式(2)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015606 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved