package libraryMIS;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class BookInsertFrm extends JFrame implements ItemListener, ActionListener {
private ManagerFrm thefrm;
final int thelen = 15;
Calendar thedate = Calendar.getInstance();
JLabel lbl_bookno = new JLabel("图书编号:");
JTextField txt_bookno = new JTextField(thelen);
JLabel lbl_bookname = new JLabel("图书名称");
JTextField txt_bookname = new JTextField(thelen);
JLabel lbl_author = new JLabel("作者");
JTextField txt_author = new JTextField(thelen);
JLabel lbl_press = new JLabel("出版社:");
JTextField txt_press = new JTextField(thelen);
JLabel lbl_date_press = new JLabel("出版日期:");
JTextField txt_date_press = new JTextField(thelen);
JLabel lbl_price = new JLabel("价格:");
JTextField txt_price = new JTextField(thelen);
JLabel lbl_date_register = new JLabel("录入日期:");
JTextField txt_date_register = new JTextField(thelen);
JLabel lbl_booktype = new JLabel("图书类型:");
JPanel jp_type = new JPanel();
JComboBox<String> com_type1 = new JComboBox<String>();
JComboBox<String> com_type2 = new JComboBox<String>();
JButton btn_Insert, btn_Cancel;
/*这里定义了两个ArrayList,用于存放两个JComboBox列表的内容 */
ArrayList<Booktypeinfo> booktypeList1 = new ArrayList<Booktypeinfo>();
ArrayList<Booktypeinfo> booktypeList2 = new ArrayList<Booktypeinfo>();
private BookTypeinfoDao bookTypeinfoDao = new BookTypeinfoDao();
private BooksDao bookDao = new BooksDao();
public BookInsertFrm(ManagerFrm managerfrm) {
this.thefrm=managerfrm;
String tmp = thedate.get(Calendar.YEAR) + "-" + (thedate.get(Calendar.MONTH) + 1) + "-"
+ thedate.get(Calendar.DATE);
txt_date_register.setText(tmp);
com_type1.setPreferredSize(new Dimension(100, 20));
com_type2.setPreferredSize(new Dimension(100, 20));
com_type1.setEditable(false);
com_type1.addItemListener(this);
jp_type.add(com_type1);
jp_type.add(com_type2);
btn_Insert = new JButton("新增图书");
btn_Insert.addActionListener(this);
btn_Cancel = new JButton("取消");
btn_Cancel.addActionListener(this);
JPanel jp = new JPanel();
jp.add(btn_Insert);
jp.add(btn_Cancel);
Box baseBox = Box.createHorizontalBox();
Box boxV1, boxV2;
int thestructsize1 =12;
boxV1 = Box.createVerticalBox();
boxV1.add(lbl_bookno);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_bookname);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_author);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_press);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_date_press);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_price);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_booktype);
boxV1.add(Box.createVerticalStrut(thestructsize1));
boxV1.add(lbl_date_register);
boxV1.add(Box.createVerticalStrut(thestructsize1));
int thestructsize2 = 6;
boxV2 = Box.createVerticalBox();
boxV2.add(txt_bookno);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_bookname);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_author);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_press);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_date_press);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_price);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(jp_type);
boxV2.add(Box.createVerticalStrut(thestructsize2));
boxV2.add(txt_date_register);
boxV2.setSize(10, 3);
baseBox = Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
add(baseBox, BorderLayout.CENTER);
add(jp, BorderLayout.SOUTH);
setBookTypeList();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
thefrm.setEnabled(true);
}
});
setVisible(true);
int width = 300, height = 320;
int x = (Toolkit.getDefaultToolkit().getScreenSize().width - width) / 2;
int y = (Toolkit.getDefaultToolkit().getScreenSize().height - height) / 2;
setBounds(x, y, width, height);
setTitle("图书信息录入");
setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void setBookTypeList() {
//获取第一级列表项
booktypeList1 = bookTypeinfoDao.bookTypelevel1Query();
if (!booktypeList1.isEmpty()) {
String booktypearray[] = new String[booktypeList1.size()];
for (int i = 0; i < booktypeList1.size(); i++) {
booktypearray[i] = booktypeList1.get(i).getTypename();
com_type1.addItem(booktypearray[i]);
}
}
}
public void itemStateChanged(ItemEvent e) {
com_type1_click();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn_Insert) {
btn_Insert_click();
} else if (e.getSource() == btn_Cancel) {
txtFieldReset();
}
}
public void btn_Insert_click() {
String bookno = txt_bookno.getText().trim();
String bookname = this.txt_bookname.getText().trim();
String author = txt_author.getText().trim();
String press = txt_press.getText().trim();
String date_press = txt_date_press.getText().trim();
String price = txt_price.getText().trim();
String date_register = txt_date_register.getText().trim();
String booktypename = com_type2.getSelectedItem().toString();
String booktypeno="";
//获取图书类型编号
for(int i=0;i<booktypeList2.size();i++) {
if(booktypeList2.get(i).getTypename().equals(booktypename)) {
booktypeno=booktypeList2.get(i).getTypeno();
break;
}
}
if (bookno.equals("") || bookname.equals("") || author.equals("") || press.equals("") || date_press.equals("")
|| price.equals("")||booktypeno.equals("")) {
JOptionPane.showMessageDialog(this, "编号、名称、作者、出版社、出版日期和价格均不能为空", "warning", JOptionPane.PLAIN_MESSAGE);
} else {
int c = 0;
c = bookDao.bookInsert(bookno, bookname, author, press, date_press, date_register,Double.parseDouble(price),
0,booktypeno);
if (c == 1) {
JOptionPane.showMessageDialog(this, "插入记录成功", "成功", JOptionPane.PLAIN_MESSAGE);
txtFieldReset();
}
}
}
public void txtFieldReset() {
txt_bookno.setText("");
txt_bookname.setText("");
txt_author.setText("");
txt_press.setText("");
txt_date_press.setText("");
txt_price.setText("");
}
public void com_type1_click() {
com_type2.removeAllItems();
String level1="";
String level1name = com_type1.getSelectedItem().toString();
//获取选中的第一级列表的编号
for(int i=0;i<booktypeList1.size();i++ ) {
if(booktypeList1.get(i).getTypename().equals(level1name)) {
level1=booktypeList1.get(i).getTypeno();
break;
}
}
//获取选中的第二级列表的编号
booktypeList2 = bookTypeinfoDao.bookTypelevel2Query(level1);
if (!booktypeList2.isEmpty()) {
String booktypearray[] = new String[booktypeList2.size()];
for (int i = 0; i < booktypeList2.size(); i++) {
booktypearray[i] = booktypeList2.get(i).getTypename();
System.out.println("test:"+booktypearray[i]);
com_type2.addItem(booktypearray[i]);
}
} else {
System.out.println("not found");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame.setDefaultLookAndFeelDecorated(true);
BookInsertFrm frm = new BookInsertFrm(null);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
图书管理系统_源码.zip
共42个文件
class:21个
java:16个
classpath:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 174 浏览量
2021-12-30
20:57:51
上传
评论
收藏 941KB ZIP 举报
温馨提示
图书管理系统_源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
图书管理系统_源码.zip (42个子文件)
Library20171437
bin
Userslogin$2.class 912B
libraryMIS
Limits.class 865B
Readers.class 2KB
LoginFrm.class 5KB
BookTypeinfoDao.class 2KB
StudentFrm$1.class 648B
ManagerFrm.class 4KB
BorrowingInfoDao.class 4KB
BookBorrowFrm$1.class 817B
Booktypeinfo.class 931B
StudentFrm.class 3KB
BooksDao.class 2KB
SQLHelper.class 3KB
BookBorrowFrm.class 7KB
Borrowinginfo.class 937B
ReadersDao.class 3KB
BookInsertFrm.class 9KB
BookInsertFrm$1.class 817B
LimitsDao.class 1KB
Userslogin.class 2KB
Userslogin$1.class 1KB
.settings
org.eclipse.jdt.core.prefs 598B
src
libraryMIS
ReadersDao.java 2KB
BookTypeinfoDao.java 1KB
BookInsertFrm.java 8KB
Limits.java 534B
Booktypeinfo.java 571B
BorrowingInfoDao.java 3KB
Borrowinginfo.java 567B
BooksDao.java 1KB
StudentFrm.java 2KB
ManagerFrm.java 4KB
Readers.java 1KB
BookBorrowFrm.java 6KB
LimitsDao.java 552B
SQLHelper.java 2KB
LoginFrm.java 4KB
Userslogin.java 2KB
.project 391B
sql
init.sql 4KB
.classpath 376B
libs
mysql-connector-java-5.1.30.jar 932KB
共 42 条
- 1
资源评论
mYlEaVeiSmVp
- 粉丝: 1923
- 资源: 19万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功