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

📄 book_append.java

📁 图书馆管理系统 用swing界面做的一个图书馆管理系统 里面有增删改等功能 适合初学者看看
💻 JAVA
字号:

//图书添加
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class book_append extends JFrame implements ActionListener{
	
	JLabel la_remark=new JLabel("注:带(*)的项目必填!");
	
	JLabel la_info=new JLabel("简介");
	
	JLabel la_id=new JLabel("书目编号(*)",JLabel.CENTER);
	JLabel la_price=new JLabel("价  格",JLabel.CENTER);
	JLabel la_name=new JLabel("图书名称(*)",JLabel.CENTER);
	JLabel la_author=new JLabel("作  者",JLabel.CENTER);
	JLabel la_isbn=new JLabel("ISBN  号 (*)",JLabel.CENTER);
	JLabel la_publish=new JLabel("出版社",JLabel.CENTER);
	
	JTextField t_id=new JTextField(20);
	JTextField t_price=new JTextField(20);
	JTextField t_name=new JTextField(20);
	JTextField t_author=new JTextField(20);
	JTextField t_isbn=new JTextField(20);
	JTextField t_publish=new JTextField(20);
	
	JButton b_into=new JButton("录 入");
	JButton b_reset=new JButton("重 置");
	JButton b_exit=new JButton("返 回");
	
	JTextArea ta_append = new JTextArea();
	JScrollPane sp= new JScrollPane(ta_append);
	
	action_into ac_into=new action_into();
	action_reset ac_reset=new action_reset();
	
	Connection conn = null;
	
	public book_append(){
		super("录入图书");
		this.setLayout(null);
		
		JPanel p_up =new JPanel();//上面面板
		JPanel p_down=new JPanel();//下面面板
		
		JPanel p_down1 =new JPanel();
		
		JPanel p_info1=new JPanel();
		
		JPanel p_info2=new JPanel();//备注提示栏目
		
		p_info1.setBounds(3,10,150,20);
		p_info1.add(la_remark);
		this.add(p_info1);
		
		p_up.setBounds(50,30,400,90);//上面板
		p_up.setLayout(new GridLayout(3,4,5,5));
		
		p_up.add(la_id); p_up.add(t_id); p_up.add(la_price); p_up.add(t_price);
		p_up.add(la_name); p_up.add(t_name); p_up.add(la_author); p_up.add(t_author);
		p_up.add(la_isbn); p_up.add(t_isbn); p_up.add(la_publish);p_up.add(t_publish);
		
		this.add(p_up); 
		
		p_info2.setBounds(3,120,65,20);//提示 简介 面板
		p_info2.add(la_info);
		this.add(p_info2);
		
		sp.setBounds(3,140,590,150); //滚动面板
		this.add(sp);
		
		p_down.setBounds(3,290,590,40);
		p_down.add(b_into); p_down.add(b_reset); p_down.add(b_exit);
		this.add(p_down);
		
		//窗口界面 	
		this.setBounds(200,200,600,370);
		this.setVisible(true);
		
		this.setResizable(false);
		//注册监听器
		b_into.addActionListener(ac_into);
		b_reset.addActionListener(ac_reset);
		b_exit.addActionListener(this);
		
		//连接数据库
		conn = book_sql.getConn();
		//System.out.println(conn);
			
	}
	public void actionPerformed(ActionEvent e){
			new book_main();//返回主菜单
			this.dispose();
	}
	//录入按钮
	class action_into implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			PreparedStatement pst=null;
			
			String s_id=t_id.getText().trim();
			String s_price=t_price.getText().trim();
			String s_name=t_name.getText().trim();
			String s_author=t_author.getText().trim();
			String s_isbn=t_isbn.getText().trim();
			String s_publish=t_publish.getText().trim();
			String s_brief=ta_append.getText().trim();
			//必须添加项目
			if(s_name.trim().length()==0||s_isbn.trim().length()==0){				
				JOptionPane.showMessageDialog(null,"带*必填项请填全",
							"Caution",JOptionPane.WARNING_MESSAGE);					
						return;
			}else
				try{
				
				pst=conn.prepareStatement("insert into bookinfo values(?,?,?,?,?,?,?)");
			
				pst.setString(1,s_id);
				pst.setString(2,s_price);
				pst.setString(3,s_name);
				pst.setString(4,s_author);
				pst.setString(5,s_isbn);
				pst.setString(6,s_publish);
				pst.setString(7,s_brief);
				
				pst.executeUpdate();
				
				}catch(SQLException sqlee){
					sqlee.printStackTrace();
				}
				JOptionPane.showMessageDialog(null,"录入成功",
							"Caution",JOptionPane.WARNING_MESSAGE);					
						return;
		}
	}
	//重置按钮
	class action_reset implements ActionListener{
		public void actionPerformed(ActionEvent e){
			
			t_id.setText("");
			t_price.setText("");
			t_name.setText("");
			t_author.setText("");
			t_isbn.setText("");
			t_publish.setText("");
			ta_append.setText("");
			
			JOptionPane.showMessageDialog(null,"清空成功",
							"Caution",JOptionPane.WARNING_MESSAGE);					
						return;
		}
	}
//
}

⌨️ 快捷键说明

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