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

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

搜索更多相关主题的帖子: swing形式 Label java awt 
2005-12-01 11:14
cll19820814
Rank: 2
等 级:新手上路
威 望:3
帖 子:328
专家分:0
注 册:2005-11-30
收藏
得分:0 
眼都花了......

懵懵懂懂,看千遍而不会;设身处地,试一下就成功!
2005-12-02 10:34
快速回复:[求助]java程序该成swing形式(1)
数据加载中...
 
   



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

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