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

📄 viewbframe.java

📁 图书馆管理系统,从我们导师的实验室(国家重点实验室)带出来的,不过是我们自己开发的,已经提交,没有问题!站长采纳,可别说是偶传的噢!
💻 JAVA
字号:
/****************************************************************
*                     管理员浏览图书窗体                        *
*****************************************************************/
package frames;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import booksys.*;

public class viewbframe extends JFrame{
	Vector book = new Vector();
	Vector bookname = new Vector();
	Vector bookstore = new Vector();
	String[][] book1;
	String[] bookname1;
	int index=0;
	int zs;
	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 borrowcount = new JLabel("借出数量");
	JLabel currentcount = new JLabel("现存数量");
	JLabel store = 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);	
	JTextField borrowcountt = new JTextField(10);
	JTextField currentcountt = new JTextField(10);
	JTextField storet = new JTextField(10);
	JTextField number = new JTextField(50);
	
	JButton firstb = new JButton("第一条");
	JButton privb = new JButton("上一条");
	JButton nextb = new JButton("下一条");
	JButton lastb = new JButton("最后一条");
	JButton exitb = new JButton("退出");	
	
	
	public viewbframe(){		
		win();		
		this.setBounds(50,50,600,450);
		this.setTitle("增加新书");
		p1.setSize(400,500);
		p1.setLayout(new GridLayout(6,4,5,15));
		p2.setLayout(new FlowLayout(FlowLayout.CENTER));
		p4.setLayout(new FlowLayout(FlowLayout.CENTER));
		Dimension d = new Dimension(500,100);
		Dimension d1 = new Dimension(800,100);
		JTable t1 = new JTable(book1,bookname1);
		for(int i=0;i<bookname1.length;i++){
			TableColumn column = t1.getColumnModel().getColumn(i);
			//column.setMinWidth(100);
			column.setResizable(false);
			}
		t1.setPreferredSize(d1);		
		JScrollPane scrollp = new JScrollPane(t1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		
		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);
		p1.add(borrowcount);
		p1.add(borrowcountt);
		p1.add(currentcount);
		p1.add(currentcountt);
	
		
				
		p2.add(scrollp);
		scrollp.setPreferredSize(d);
	
				
		p3.add(number);
		//check.addActionListener(new check());
		
		
		firstb.addActionListener(new first());
		p4.add(firstb);
		privb.addActionListener(new priv());
		p4.add(privb);
		nextb.addActionListener(new next());		
		p4.add(nextb);
		lastb.addActionListener(new last());
		p4.add(lastb);
		exitb.addActionListener(new exit());
		p4.add(exitb);
		
		
		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);
		}
		
	
		public void win(){
			try{	
				settable();	
				filltext();		
				zs = book.size();				
				s = "共有"+String.valueOf(zs)+"本书,这是第"+String.valueOf(index+1)+"本。";	
				number.setText(s);
				
			}catch(Exception we){
				}
			
		}
		
	public void filltext() throws Exception{
			books b1 = (books)book.elementAt(index);
			bookstores store1 = (bookstores)bookstore.elementAt(index);
			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());		
			allcountt.setText(String.valueOf(store1.allcount));
			borrowcountt.setText(String.valueOf(store1.borrowcount));
			currentcountt.setText(String.valueOf(store1.currentcount));
			}
			
	class first implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			index=0;
			filltext();
			s = "共有"+String.valueOf(zs)+"本书,这是第"+String.valueOf(index+1)+"本。";	
			number.setText(s);
			}catch(Exception fe){
				JOptionPane.showMessageDialog(null,fe.getMessage());
				}
			}
		}
		
	class priv implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			if(index>0){
				index-=1;
				filltext();
				s = "共有"+String.valueOf(zs)+"本书,这是第"+String.valueOf(index+1)+"本。";	
				number.setText(s);
				}else{
					JOptionPane.showMessageDialog(null,"已到第一条记录!");
					}
			}catch(Exception fe){
				JOptionPane.showMessageDialog(null,fe.getMessage());
				}
			}
		}
		
	class next implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			if(index<book.size()-1){
				index+=1;
				filltext();
				s = "共有"+String.valueOf(zs)+"本书,这是第"+String.valueOf(index+1)+"本。";	
				number.setText(s);
				}else{
					JOptionPane.showMessageDialog(null,"已到最后一条!");
					}
			}catch(Exception fe){
				JOptionPane.showMessageDialog(null,fe.getMessage());
				}
			}
		}
		
	class last implements ActionListener{
		public void actionPerformed(ActionEvent e){
			try{
			index=book.size()-1;
			filltext();
			s = "共有"+String.valueOf(zs)+"本书,这是第"+String.valueOf(index+1)+"本。";	
			number.setText(s);
			}catch(Exception fe){
				JOptionPane.showMessageDialog(null,fe.getMessage());
				}
			}
		}
		
	class exit implements ActionListener{
		public void actionPerformed(ActionEvent e){
			mainframe.vb1.setVisible(false);
			}
		}
		
	public void settable() throws Exception{
				book.clear();			
				book = books.browse("select * from books");				
				book1 = new String[book.size()][9];				
			if(book.size()>0){
				for(int i=0;i<book.size();i++){
					books b1 = (books)book.elementAt(i);
					bookstore.addElement(bookstores.searchcount(b1.getbookid()));
					book1[i][0] = String.valueOf(b1.getbookid());
					book1[i][1] = b1.getnm();
					book1[i][2] = b1.getauthor1();
					book1[i][3] = b1.getauthor2();
					book1[i][4] = b1.getisbn();
					book1[i][5] = String.valueOf(b1.getprice());
					book1[i][6] = publishers.searchnm(b1.getpublisherid());
					book1[i][7] = b1.getversion();					
					}
					bookname1 = new String[8];
					bookname1[0] = "书id";
					bookname1[1] = "书名";
					bookname1[2] = "作者1";
					bookname1[3] = "作者2";
					bookname1[4] = "isbn";
					bookname1[5] = "单价";
					bookname1[6] = "出版社";
					bookname1[7] = "版本";
				}else{
					JOptionPane.showMessageDialog(null,"没有书");
					}			
		}
		
		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 + -