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

📄 bflowgui.java

📁 图书管理系统。 借书
💻 JAVA
字号:
package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import shujuku
.*;public class BFlowGUI extends JFrame implements ActionListener {
	public static final int WIDTH = 500;

	public static final int HEIGHT = 300;
String x;
String y;
	public JTextField tID;

	public JTextField dID;

	public JTextField bookname;

	public JTextField writter;

	public JTextField da;

	public JTextField tID0;

	public JTextField dID0;

	public JTextField bookname0;

	public JTextField writter0;

	public JTextField rd;

	public JTextField m;

	public static final int VERTICAL_STRUT_SIZE = 100;

	public static final int VERTICAL_STRUT_SIZ = 100;

	public BFlowGUI() {
		setSize(WIDTH, HEIGHT);
		addWindowListener(new WindowDestroyer());
		setTitle("图书管理系统");
		Dimension screen = getToolkit().getScreenSize();  //得到屏幕尺寸
		  setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2); //设置窗口位置
		Container contentPane = getContentPane();
		contentPane.setBackground(Color.WHITE);
		contentPane.setLayout(new BorderLayout());

		JPanel mainp = new JPanel();mainp.setBackground(Color.LIGHT_GRAY);
		mainp.setLayout(new BorderLayout());

		JPanel n1 = new JPanel();n1.setBackground(Color.LIGHT_GRAY);
		n1.setLayout(new BoxLayout(n1, BoxLayout.Y_AXIS));
		Component n1Strut = Box.createVerticalStrut(VERTICAL_STRUT_SIZE);
		n1.add(n1Strut);
		JButton ck = new JButton("出             库");
		ck.addActionListener(this);
		n1.add(ck);
		JButton sp = new JButton("锁 定  屏 幕");
		sp.addActionListener(this);
		n1.add(sp);
		JButton returnto = new JButton("返回主界面");
		returnto.addActionListener(this);
		n1.add(returnto);
		JButton tc = new JButton("退             出");
		tc.addActionListener(this);
		n1.add(tc);

		JPanel z = new JPanel();z.setBackground(Color.LIGHT_GRAY);
		z.setLayout(new GridLayout(4, 1));

		JPanel m1 = new JPanel();m1.setBackground(Color.LIGHT_GRAY);
		m1.setLayout(new FlowLayout());
		JLabel bID = new JLabel("图书ID号");
		m1.add(bID);
		tID = new JTextField(8);
		m1.add(tID);
		JLabel rID = new JLabel("读者ID号");
		dID = new JTextField(8);
		m1.add(rID);
		m1.add(dID);
		z.add(m1);

		JPanel a = new JPanel();a.setBackground(Color.LIGHT_GRAY);
		a.setLayout(new FlowLayout());
		a.add(new JLabel("图书书名"));
		bookname = new JTextField(22);
		a.add(bookname);
		z.add(a);
		JPanel b = new JPanel();b.setBackground(Color.LIGHT_GRAY);
		b.setLayout(new FlowLayout());
		b.add(new JLabel("图书作者"));
		writter = new JTextField(22);
		b.add(writter);
		z.add(b);
		JPanel c = new JPanel();c.setBackground(Color.LIGHT_GRAY);
		c.setLayout(new FlowLayout());
		c.add(new JLabel("出借日期"));
		da = new JTextField(22);
		c.add(da);
		z.add(c);
		mainp.add(z, BorderLayout.CENTER);
		mainp.add(n1, BorderLayout.EAST);

		JPanel mainp1 = new JPanel();mainp1.setBackground(Color.LIGHT_GRAY);
		mainp1.setLayout(new BorderLayout());

		JPanel n2 = new JPanel();n2.setBackground(Color.LIGHT_GRAY);
		n2.setLayout(new BoxLayout(n2, BoxLayout.Y_AXIS));
		Component n2Strut = Box.createVerticalStrut(VERTICAL_STRUT_SIZ);
		n2.add(n2Strut);
		JButton rk = new JButton("入             库");
		rk.addActionListener(this);
		n2.add(rk);
		JButton sp1 = new JButton("锁 定  屏 幕");
		sp1.addActionListener(this);
		n2.add(sp1);
		JButton returnto1 = new JButton("返回主界面");
		returnto1.addActionListener(this);
		n2.add(returnto1);
		JButton tc1 = new JButton("退出");
		tc1.addActionListener(this);
		n2.add(tc1);

		JPanel y = new JPanel();y.setBackground(Color.LIGHT_GRAY);
		y.setLayout(new GridLayout(5, 1));

		JPanel m2 = new JPanel();m2.setBackground(Color.LIGHT_GRAY);
		m2.setLayout(new FlowLayout());
		JLabel bID1 = new JLabel("图书ID号");
		m2.add(bID1);
		tID0 = new JTextField(8);
		m2.add(tID0);
		JLabel rID0 = new JLabel("读者ID号");
		dID0 = new JTextField(8);
		m2.add(rID0);
		m2.add(dID0);
		y.add(m2);

		JPanel d = new JPanel();d.setBackground(Color.LIGHT_GRAY);
		d.setLayout(new FlowLayout());
		d.add(new JLabel("图书书名"));
		bookname0 = new JTextField(22);
		d.add(bookname0);
		y.add(d);
		JPanel e = new JPanel();e.setBackground(Color.LIGHT_GRAY);
		e.setLayout(new FlowLayout());
		e.add(new JLabel("图书作者"));
		writter0 = new JTextField(22);
		e.add(writter0);
		y.add(e);
		JPanel f = new JPanel();f.setBackground(Color.LIGHT_GRAY);
		f.setLayout(new FlowLayout());
		f.add(new JLabel("归还日期"));
		rd = new JTextField(22);
		f.add(rd);
		y.add(f);
		JPanel g = new JPanel();g.setBackground(Color.LIGHT_GRAY);
		g.setLayout(new FlowLayout());
		g.add(new JLabel("罚       款"));
		m = new JTextField(22);
		g.add(m);
		y.add(g);

		mainp1.add(y, BorderLayout.CENTER);
		mainp1.add(n2, BorderLayout.EAST);

		JPanel help = new JPanel();help.setBackground(Color.LIGHT_GRAY);
		JLabel set=new JLabel("          尚未设置此方法        ");
		  set.setFont(new Font("黑体",30,36));
		  JLabel ja=new JLabel("       详情咨询NEWWORLD     ");
		  ja.setFont(new Font("黑体",30,36));
		  help.add(set);help.add(ja);
		JTabbedPane js = new JTabbedPane();
		js.addTab("借书", mainp);
		js.addTab("还书", mainp1);
		js.addTab("帮助", help);
		js.setVisible(true);
		contentPane.add(js);

	}

	public class WindowDestroyer extends WindowAdapter {
		public void windowCloseing(WindowEvent e) {
			System.exit(0);
		}

	}

	

	public void actionPerformed(ActionEvent e) {
		String com = e.getActionCommand();
		if (com.equals("出             库")) {
			String a = tID.getText();
			String b = dID.getText();
			String c="yes";String d="no";
			try{
			Connection con=LinkToDB.buildlinktodb();
			Statement state = con.createStatement();
			ResultSet result = state
					.executeQuery("SELECT BOOKNAME图书名 FROM 图书 WHERE BOOKID图书编号='"
							+ a + "'");
			 Statement state0 = con.createStatement();
			 ResultSet result0 = state0
			 .executeQuery("SELECT AUTHOR图书作者 FROM 图书 WHERE BOOKID图书编号='"+a+"'");
			while (result.next()) {
				x= result.getString("BOOKNAME图书名");}
			while (result0.next()){
				y= result0.getString("AUTHOR图书作者");
			}bookname.setText(x);

			writter.setText(y);

			GetDate gd=new GetDate(); 
			String time=gd.getDate();
			da.setText(time);
			Statement state1 = con.createStatement();
			Boolean result1 = state1.execute("insert into 图书访问记录 values ('"+a+"','"+b+"','"+time+"')");
					
			Statement state2 = con.createStatement();
//			Boolean result2 =
				state2.executeUpdate("update 图书 set STAUS图书状态='"+d+"' where BOOKID图书编号='"+a+"'");
				JOptionPane.showMessageDialog(this,"       借书成功!!!!!!!!      ");	
						
			result.close();
			result0.close();
			state.close();
			con.close();
		} catch (ClassNotFoundException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		}
	}
		if (com.equals("入             库")) {
			String a = tID0.getText();
			String b = dID0.getText();
			String c="yes";String d="no";
				Connection con;
				try {
					con = LinkToDB.buildlinktodb();

				Statement state = con.createStatement();
				ResultSet result = state
						.executeQuery("SELECT BOOKNAME图书名 FROM 图书 WHERE BOOKID图书编号='"
								+ a + "'");
				 Statement state0 = con.createStatement();
				 ResultSet result0 = state0
				 .executeQuery("SELECT AUTHOR图书作者 FROM 图书 WHERE BOOKID图书编号='"+a+"'");
				while (result.next()) {
					String x = result.getString("BOOKNAME图书名");
					bookname0.setText(x);}
				while (result0.next()) {
					writter0.setText(result0.getString("AUTHOR图书作者"));
				}

				GetDate gd=new GetDate(); 
				String time=gd.getDate();
				rd.setText(time);
				Statement state1 = con.createStatement();
				Boolean result1 = state1.execute("DELETE FROM 图书访问记录 WHERE 借阅图书号='" + a + "'");
				Statement state2 = con.createStatement();
				Boolean result2 = state2.execute("update 图书 set STAUS图书状态='"+c+"'"
					+ " where BOOKID图书编号='"+a+"'");
				JOptionPane.showMessageDialog(this,"       还书成功!!!!!!!!!!      ");
				m.setText("还没处理");
				result.close();
				result0.close();
				state.close();
				con.close();
				} catch (ClassNotFoundException e1) {
					// TODO 自动生成 catch 块
					e1.printStackTrace();
				} catch (SQLException e1) {
					// TODO 自动生成 catch 块
					e1.printStackTrace();
				}
		}
		if (com.equals("返回主界面")) {
			GUIClass go = new GUIClass();
			go.setVisible(true);
			show();
			dispose();
		} else if (com.equals("退出")) {
			 WindowConfirm guig=new WindowConfirm();
		

	}
}}

⌨️ 快捷键说明

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