import java.awt。*;
import java.awt.event。*;
import java.sql.*;
import java。util。*;
import javax.swing。*;
// ———-———--——————-———--——-——-———--——--—-—-—--——--———-—————--———--————-—-————————-——---———-————-—-—-—————--—
public static void main(String args[]) {
dbframe db = new dbframe(”图书管理程序”);
}
}
// 图书管理系统主界面
class dbframe extends Frame implements ActionListener {
MenuBar daohang = new MenuBar(); // 建立菜单栏 Menu mfile = new Menu(”功能"); // 建立“功能”菜单组 Menu mhelp = new Menu(”帮助"); // 建立“帮助”菜单组
MenuItem mdenglu = new MenuItem(”登陆”);
MenuItem mchaxun = new MenuItem("查询");
MenuItem mtianjia = new MenuItem(”添加");
MenuItem mshanchu = new MenuItem("删除");
MenuItem mexit = new MenuItem("退出");
MenuItem mhelpp = new MenuItem(”关于");
Denglu pdenglu=new Denglu();
Ptianjia ptianjia = new Ptianjia();
Pmain pmain = new Pmain();
Pchaxun pchaxun = new Pchaxun();
Pshanchu pshanchu = new Pshanchu();
dbframe(String s) { // 在窗口上添加菜单选项
setTitle(s);
mfile。add(mdenglu);
mfile.add(mtianjia);
mfile。add(mchaxun);
mfile。add(mshanchu);
mfile。add(mexit);
mhelp。add(mhelpp);
daohang。add(mfile);
daohang.add(mhelp);
setMenuBar(daohang);
add(pmain);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
it(0);
}
});
setBounds(200, 200, 340, 250);
setResizable(false);
setVisible(true);
mexit.addActionListener(this);
mdenglu.addActionListener(this);
mtianjia.addActionListener(this);
mchaxun.addActionListener(this);
mshanchu。addActionListener(this);
mhelpp。addActionListener(this);
validate();
} // 窗口事件监听
public void actionPerformed(ActionEvent e) {
if (e.getSource() == mexit)
it(0);
if(e。getSource()==mdenglu){
removeAll();
add(pdenglu);
铁皮枫斗口服液
validate();
}
if (e。getSource() == mtianjia) {
removeAll();
add(ptianjia);
validate();
} // 图书添加功能
if (e。getSource() == mchaxun) {
removeAll();
add(pchaxun);
validate();
} // 图书查询功能
if (e。getSource() == mshanchu) {
removeAll();
add(pshanchu);
validate();
} // 图书删除功能
if (e。getSource() == mhelpp) {
JOptionPane。showMessageDialog(this, ”欢迎使用图书管理系统”, ”关于本系统”,
JOptionPane。INFORMATION_MESSAGE);
}
} // 各功能菜单事件监听
}
//
class Ptianjia extends Panel implements ActionListener {
TextField tname, tauthor, tpublish, tdate, tcomment;
Label lname, lauthor, lpublish, ldate, lcomment;
Button btn;
Ptianjia() {
setLayout(null);
btn = new Button("添加"); // 创建“添加”按钮 tname = new TextField();
tauthor = new TextField();
tpublish = new TextField();
tdate = new TextField();
tcomment = new TextField(); // 创建5个文本框
lname = new Label(”书名”);
lauthor = new Label("作者”);
lpublish = new Label(”出版社”);
ldate = new Label(”出版日期");
lcomment = new Label("评论");
add(lname);
add(tname);
add(lauthor);
add(tauthor);
add(lpublish);
add(tpublish);
add(ldate);
add(tdate);
add(lcomment);
add(tcomment);
add(btn); // 添加“按钮"到窗口面板上
lname.setBounds(10, 10, 70, 25);
tname。setBounds(90, 10, 220, 25);
lauthor.setBounds(10, 40, 70, 25);
tauthor.setBounds(90, 40, 220, 25);
lpublish.setBounds(10, 70, 70, 25);
tpublish。setBounds(90, 70, 220, 25);
ldate.setBounds(10, 100, 70, 25);
tdate。setBounds(90, 100, 220, 25);
lcomment。setBounds(10, 130, 70, 25);
tcomment。setBounds(90, 130, 220, 25);
btn.setBounds(130, 160, 70, 25); // 设置按钮位置
煤气化炉
btn。addActionListener(this); // 设置按钮监听
setSize(340, 250); // 设置窗口大小
setBackground(Color。white); // 设置窗口背景颜
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e) {
String sname = Text();
String sauthor = tauthor。getText();
String spublish = tpublish。getText();
String sdate = Text();
String scomment = tcomment。getText();
String insertstr = ”insert into book values" + "(” + "'” + sname + "’”
立式导热油加热器
+ ”,” + "'” + sauthor + ”’" + "," + "'" + spublish + ”'" + ”,”
+ "'" + sdate + "’” + ”,” + ”’” + scomment + ”’” + ”)”; // SQL语句
Connection con;
Statement sta;
ResultSet rs;
try {
Class.forName(”oracle。jdbc。driver。OracleDriver”); // 加载JDBC驱动
文具盒生产过程
} catch (ClassNotFoundException ee) {
System.out.println(”” + ee);
}
try {
con = Connection(”jdbc:oracle:thin:@localhost:1521:orcl”, ”sa”, ”orcl”); // 连接数据库
sta = ateStatement();
sta。executeUpdate(insertstr); // 执行SQL语句
con。close(); // 关闭数据库
tname。setText("”);宠物清洗机
tauthor。setText(””);
tpublish。setText(””);
tdate。setText("");
tcomment。setText("”); // 重新初始化文本框内容