这几个程序运行出来是awt形式,谁能把他们改成运行出来是swing形式
1)
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class bookIn extends Frame implements ActionListener ,ItemListener
{
private Label lbb_name = new Label("教材名称");
private Label lbb_editor = new Label("教材编者");
private Label lbb_pubhouse = new Label("出 版 社");
private Label lbb_price = new Label("教材定价");
private Label lbb_num = new Label("入库数量");
private Label lbb_provider = new Label("供货商");
private Label lbb_department = new Label("使用部门");
private Label lbb_isbn = new Label("ISBN");
private Choice chodep = new Choice();//department
private Choice chopub = new Choice();//publishinghouse
public booIn()
{
setTitle("教材入库");
setSize(600,400);
setLocationRelativeTo(this.getParent());
lbb_name.setSize(
}
public static void main(String arg[])
{
bookIn bookinput = new bookIn();
}
}
2)
/*
* @(#)BookMng.java 1.0 05/10/18
*
* You can modify the template of this file in the
* directory ..\JCreator\Templates\Template_1\Project_Name.java
*
* You can also create your own project template by making a new
* folder in the directory ..\JCreator\Template\. Use the other
* templates as examples.
*
*/
//定义登录界面
import java.awt.*;
import java.awt.event.*;
import java.awt.Window;
import java.sql.*;
import javax.swing.*;
public class BookMng extends Frame {
public Label lbname = new Label("姓 名:");
public Label lbpwd = new Label("密 码:");
public TextField txtname = new TextField(20);
public TextField txtpwd = new TextField(20);
public Button btnok = new Button("登录");
public Button btnexit = new Button("取消");
public condb db = new condb();
public BookMng()
{
setTitle("欢迎使用教材管理系统!");
setLayout(null);
setBackground(Color.LIGHT_GRAY);
setResizable(false);
setSize(320,180);
//set frm at screen's center
Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm = this.getSize();
setLocation((scr.width-frm.width)/2,(scr.height-frm.height)/2-200);
txtpwd.setEchoChar('*');
lbname.setLocation(40,50);
lbpwd.setLocation(40,80);
btnok.setLocation(60,130);
txtname.setLocation(120,50);
txtpwd.setLocation(120,80);
btnexit.setLocation(170,130);
lbname.setSize(50,20);
lbpwd.setSize(50,20);
txtname.setSize(150,20);
txtpwd.setSize(150,20);
btnok.setSize(80,20);
btnexit.setSize(80,20);
add(lbname);
add(txtname);
add(lbpwd);
add(txtpwd);
add(btnok);
add(btnexit);
setVisible(true);
// btnok.addActionListener(this);
//单击取消按钮退出系统
btnexit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
System.exit(0);
}
});
//单击确定按钮与数据库连接,进入系统
btnok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:bookmng");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from idpwd where user_name = '"+txtname.getText()+"' and user_pwd = '"+txtpwd.getText()+"'");
if(rs.next())
{
mainFrame mf = new mainFrame();
mf.show();
dispose();
}
con.close();
rs.close();
}catch(Exception ee){try
{
String sql = "Select * from idpwd where user_name ='"+txtname.getText()+"' and user_pwd = '"+txtpwd.getText()+"'";
ResultSet rs = db.getrs(db.con,sql);
System.out.println(sql);
if( rs.next())
{
mainFrame mf = new mainFrame();
dispose();
mf.show();
db.dbclose(db.con,rs);
}
else
{JOptionPane .showMessageDialog(null,"wrong","密码不正确",JOptionPane. WARNING_MESSAGE );
System.exit(0);}
}catch(SQLException re){} }
/*try
{
String sql = "Select * from idpwd where user_name ='"+txtname.getText()+"' and user_pwd = '"+txtpwd.getText()+"'";
ResultSet rs = db.getrs(db.con,sql);
System.out.println(sql);
if(rs.next())
{
mainFrame mf = new mainFrame();
dispose();
mf.show();
db.dbclose(db.con,rs);
}
else
{
System.out.println("用户名与密码不对,请重新输入!");
}
}catch(SQLException re){}*/
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
BookMng mainframe = new BookMng();
}
}
3)
//数据库的连接
import java.sql.*;
public class condb
{
public Connection con ;
public condb()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e){};
try
{
con = DriverManager.getConnection("jdbc:odbc:bookmng");
}catch(SQLException e){System.out.println("connect database error!");}
}
public ResultSet getrs(Connection con,String sql)
{
ResultSet rs = null;
try
{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sql);
}catch(Exception e){};
return rs;
}
public void moddb(Connection con,String sql)
{
try
{
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
}catch(Exception e){};
}
public void dbclose(Connection con,ResultSet rs)
{
try
{
con.close();
rs.close();
}catch(SQLException rse){}
}
}
4)
//系部信息
import java.awt.*;
import java.awt.event.*;
import java.awt.Window;
import java.sql.*;
import javax.swing.*;
public class department extends Frame implements ActionListener
{
private condb condep = null;
private ResultSet rs = null;
private String sql = null;
private Label lbname = new Label("部门名称");
private Label lbdep = new Label("部门列表");
private TextField txtdep = new TextField(20);
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 department()
{
super();
setTitle("部门信息");
setSize(400,200);
setBackground(Color.LIGHT_GRAY);
this.setLocationRelativeTo(this.getParent());
this.setResizable(false);
setLayout(null);
lbname.setSize(50,20);
txtdep.setSize(170,20);
lbdep.setSize(50,20);
chodep.setSize(170,20);
btnadd.setSize(50,20);
btndel.setSize(50,20);
btnmod.setSize(50,20);
btnexit.setSize(50,20);
lbname.setLocation(80,50);
txtdep.setLocation(160,50);
lbdep.setLocation(80,100);
chodep.setLocation(160,100);
btnadd.setLocation(60,150);
btndel.setLocation(140,150);
btnmod.setLocation(220,150);
btnexit.setLocation(300,150);
add(lbname);
add(txtdep);
add(btnadd);
add(btndel);
add(btnmod);
add(btnexit);
add(chodep);
add(lbdep);
//initial choice
initchodep();
setVisible(true);
btnadd.addActionListener(this);
btndel.addActionListener(this);
btnmod.addActionListener(this);
btnexit.addActionListener(this);
chodep.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e)
{
txtdep.setText(chodep.getSelectedItem());
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
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 department where dep_name = '"+txtdep.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 department values('"+txtdep.getText()+"')";
condep = new condb();
try
{
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ue){}
chodep.addItem(txtdep.getText());
txtdep.setText("");
condep = null;
}
}catch(Exception be){}
}
if(e.getActionCommand().equals("修改"))
{
//此处添加信息对话框,提示不那嘎修改为空格情况
condep = new condb();
sql = "update department set dep_name = '"+txtdep.getText()+"' where dep_name = '"+chodep.getSelectedItem()+"'";
try
{
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ee){}
chodep.remove(chodep.getSelectedIndex());
chodep.add(txtdep.getText());
txtdep.setText("");
condep = null;
}
if(e.getActionCommand().equals("删除"))
{
condep = new condb();
sql = "delete from department where dep_name = '"+chodep.getSelectedItem()+"'";
try
{
condep.moddb(condep.con,sql);
condep.dbclose(condep.con,null);
}catch(Exception ee){}
chodep.remove(chodep.getSelectedIndex());
txtdep.setText("");
condep = null;
}
}
public static void main(String arg[])
{
department dep = new department();
}
}