⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addbookframe.java

📁 图书馆管理系统,从我们导师的实验室(国家重点实验室)带出来的,不过是我们自己开发的,已经提交,没有问题!站长采纳,可别说是偶传的噢!
💻 JAVA
字号:
/****************************************************************
*                     添加书籍窗体                              *
*****************************************************************/

package frames;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import booksys.*;

public class addbookframe extends JFrame{
	manager m1;
	Vector book = new Vector();
	Vector bookstore = new Vector();
	int currentsl = 0; 
	String ss="该书共有";//显示字符串
	String ss1 ="本,这是第";
	String ss2 = "本";
	String s;
	
	JPanel p = new JPanel();
	JPanel p1 = new JPanel();
	JPanel p2 = new JPanel();
	JPanel p3 = new JPanel();
	JPanel p4 = new JPanel();
	
	JLabel booknm = new JLabel("书名:");
	JLabel publisher = new JLabel("出版社:");
	JLabel author1 = new JLabel("作者1:");
	JLabel author2 = new JLabel("作者2:");
	JLabel isbn = new JLabel("ISBN:");
	JLabel price = new JLabel("单价:");
	JLabel version = new JLabel("版本:");
	JLabel allcount = new JLabel("数量:");	
	JLabel introduce = new JLabel("简介:");
	
	JTextField booknmt = new JTextField(10);
	JTextField publishert = new JTextField(10);
	JTextField authort1 = new JTextField(10);
	JTextField authort2 = new JTextField(10);
	JTextField isbnt = new JTextField(10);
	JTextField pricet = new JTextField(10);
	JTextField versiont = new JTextField(10);
	JTextField allcountt = new JTextField(10);	
	
	JTextArea introducearea = new JTextArea(8,25);
	JScrollPane scroller = new JScrollPane(introducearea);
	Dimension d = new Dimension(400,100);
	JButton check = new JButton("检查书名");
	
	
	JButton priv = new JButton("上一条");
	JTextField number = new JTextField(40);
	JButton next = new JButton("下一条");
	
	JButton ok = new JButton("保存");
	JButton cancel = new JButton("退出");
	JButton coun = new JButton("继续增加");
	JButton addnew = new JButton("新增");
	
	public addbookframe(){
		m1 = loginframe.m1;
		this.setBounds(150,150,600,420);
		this.setTitle("增加新书");
		p1.setSize(400,500);
		p1.setLayout(new GridLayout(5,4,5,15));
		p2.setLayout(new FlowLayout(FlowLayout.CENTER));
		p4.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		p1.add(booknm);
		p1.add(booknmt);
		p1.add(publisher);
		p1.add(publishert);
		p1.add(author1);
		p1.add(authort1);
		p1.add(author2);
		p1.add(authort2);
		p1.add(isbn);
		p1.add(isbnt);
		p1.add(price);
		p1.add(pricet);
		p1.add(version);
		p1.add(versiont);
		p1.add(allcount);
		p1.add(allcountt);
	
		
		
		p2.add(introduce);
		p2.add(scroller);
		scroller.setPreferredSize(d);
	
		
		number.setText("该书共有0本,这是第0本");
		p3.add(number);
		check.addActionListener(new check());
		p3.add(check);
		
		addnew.addActionListener(new addnew());
		p4.add(addnew);
		ok.addActionListener(new ok());
		p4.add(ok);
		priv.setEnabled(false);
		priv.addActionListener(new priv());
		p4.add(priv);
		next.setEnabled(false);
		next.addActionListener(new next());
		p4.add(next);
		coun.addActionListener(new coun());
		p4.add(coun);
		cancel.addActionListener(new cancel());
		p4.add(cancel);
		
		p.add(p1);
		p.add(p2);
		p.add(p3);
		p.add(p4);
		
		this.setContentPane(p);
		try{
			setlook("windows");
			}catch(Exception sete){
				JOptionPane.showMessageDialog(null,sete.getMessage());
			}	
		this.setVisible(true);
		}
		
	class coun implements ActionListener{
		public void actionPerformed(ActionEvent e){
			booknmt.setText("");			
			publishert.setText("");
			authort1.setText("");
			authort2.setText("");
			isbnt.setText("");
			pricet.setText("");
			versiont.setText("");
			introducearea.setText("");
			number.setText("该书共有0本,这是第0本");
			}
		}
		
	class cancel implements ActionListener{
		public void actionPerformed(ActionEvent e){
			mainframe.add1.setVisible(false);
			}
		}
	
	class priv implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			if(currentsl>0){
				currentsl-=1;
				filltext();
				String zs = String.valueOf(book.size());
				String s1 = String.valueOf(currentsl+1);
				s = ss+zs+ss1+s1+ss2;
				number.setText(s);
				}else{
					JOptionPane.showMessageDialog(null,"已到第一条");
					}
				}catch(Exception prive){
					JOptionPane.showMessageDialog(null,prive.getMessage());
					}
			}
		}
		
	class next implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			if(currentsl<book.size()-1){
				currentsl+=1;
				filltext();
				String zs = String.valueOf(book.size());
				String s1 = String.valueOf(currentsl+1);
				s = ss+zs+ss1+s1+ss2;
				number.setText(s);
				}else{
					JOptionPane.showMessageDialog(null,"已到最后一条");
					}
				}catch(Exception prive){
					JOptionPane.showMessageDialog(null,prive.getMessage());
					}
			}
		}
		
		
	class check implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
				String booknm = booknmt.getText();
				book.clear();
				book=books.checknewbook(booknm);			
							
				if(book.size()>0){
					if(book.size()>1){
					priv.setEnabled(true);
					next.setEnabled(true);
					}
					for(int i=0;i<book.size();i++){
						s="";
						number.setText("");
						currentsl=0;
						books b = (books)book.elementAt(i);
						bookstore.addElement(bookstores.searchcount(b.getbookid()));
						}
						JOptionPane.showMessageDialog(null,"该书存在,请输入数量!");
						String zs = String.valueOf(book.size());
						filltext();
						String s1 = String.valueOf(currentsl+1);
						s = ss+zs+ss1+s1+ss2;
						number.setText(s);						
					}else{
						JOptionPane.showMessageDialog(null,"这是一本新书!");
						
						}
				}catch(Exception checke){
					JOptionPane.showMessageDialog(null,checke.getMessage());
					}
			}
		}
		
	class ok implements ActionListener{
		public void actionPerformed(ActionEvent e){
			boolean succ =false;
			try{
				if(book.size()>0){					
					int count = Integer.parseInt(allcountt.getText());
					bookstores store1 = (bookstores)bookstore.elementAt(currentsl);
					store1.allcount +=count;
					store1.currentcount +=count;
					succ=store1.updatebookstores(store1.id);
					if(succ) JOptionPane.showMessageDialog(null,"书已添加!");
					else JOptionPane.showMessageDialog(null,"添加失败!");
						
					}else{
						int bookid = books.getid();
						String booknm = booknmt.getText();
						String author1 = authort1.getText();
						String author2 = authort2.getText();
						String isbn = isbnt.getText();
						float price=Float.parseFloat(pricet.getText());
						int publisherid = publishers.searchid(publishert.getText());
						String version = versiont.getText();
						String introduce = introducearea.getText();
						books book1 = new books(bookid,booknm,author1,author2,isbn,price,publisherid,version,introduce);						
						int id = bookstores.getid();
						int allcount = Integer.parseInt(allcountt.getText());
						bookstores store1 = new bookstores(id,bookid,allcount,0,allcount,1,1);
						if(book1.addnewbook()&&store1.addbookstores()) JOptionPane.showMessageDialog(null,"书已添加!");
						else JOptionPane.showMessageDialog(null,"添加失败!");							
					}			
				}catch(Exception savee){
					JOptionPane.showMessageDialog(null,savee.getMessage());
					}
			
			}
		}
		
		class addnew implements ActionListener{
			public void actionPerformed(ActionEvent e){
				try{
					int bookid = books.getid();
					String booknm = booknmt.getText();
					String author1 = authort1.getText();
					String author2 = authort2.getText();
					String isbn = isbnt.getText();
					float price=Float.parseFloat(pricet.getText());
					int publisherid = publishers.searchid(publishert.getText());
					String version = versiont.getText();
					String introduce = introducearea.getText();					
					books book1 = new books(bookid,booknm,author1,author2,isbn,price,publisherid,version,introduce);						
					int id = bookstores.getid();
					int allcount = Integer.parseInt(allcountt.getText());
					bookstores store1 = new bookstores(id,bookid,allcount,0,allcount,1,1);
					if(book1.addnewbook()&&store1.addbookstores()) JOptionPane.showMessageDialog(null,"书已添加!");
					else JOptionPane.showMessageDialog(null,"添加失败!");
					}catch(Exception addnewe){
						JOptionPane.showMessageDialog(null,addnewe.getMessage());
						}
				}
			}
		
		public void filltext() throws Exception{
			books b1 = (books)book.elementAt(currentsl);
			booknmt.setText(b1.getnm());
			String s1 = publishers.searchnm(b1.getpublisherid());					
			publishert.setText(s1);
			authort1.setText(b1.getauthor1());
			authort2.setText(b1.getauthor2());
			isbnt.setText(b1.getisbn());
			pricet.setText(String.valueOf(b1.getprice()));
			versiont.setText(b1.getversion());
			introducearea.setText(b1.getintroduce());
			allcountt.setText("");
			}
			
		public void setlook(String look) throws Exception{//设置外观效果
		
			if(look.equals("java")){
				UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");				
				SwingUtilities.updateComponentTreeUI(this);
				//this.pack();
				}
			if(look.equals("windows")){
				UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
				SwingUtilities.updateComponentTreeUI(this);
				//this.pack();
				}
				
			if(look.equals("motif")){
				UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
				SwingUtilities.updateComponentTreeUI(this);
				//this.pack();
				}
			
			}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -