addbook.java

来自「用Jsp实现的图书管理系统代码」· Java 代码 · 共 53 行

JAVA
53
字号
//源程序名:AddBook.java
//这是添加新书的类
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AddBook extends JFrame implements ActionListener{
	JLabel lbName=new JLabel("书名:");
	JLabel lbPrice=new JLabel("书价:");
	JLabel lbNumber=new JLabel("编号:");
	JLabel lbAmount=new JLabel("现库存量:");
	JLabel lbDemo=new JLabel("图书说明:");	
	JTextField tfName=new JTextField(15);
	JTextField tfPrice=new JTextField(15);
	JTextField tfAmount=new JTextField(6);
	JTextField tfNumber=new JTextField(15);
	JTextArea taDemo=new JTextArea();
	JButton btnAdd=new JButton("添加到库");
	JButton btnClose=new JButton("关   闭");
	AddBook(){
		super("添加图书");
		setSize(200,250);
		setLayout(new FlowLayout());
		add(lbName);add(tfName);
		add(lbPrice);add(tfPrice);
		add(lbNumber);add(tfNumber);
		add(btnAdd);add(btnClose);
		setLocation(370,220);
		setVisible(true);
		btnAdd.addActionListener(this);
		btnClose.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e)
		{
		    DatabaseConn addbook=new DatabaseConn();
			if (e.getSource()==btnAdd)
			{
				String sql="";
				
				String strName=tfName.getText();
				String strPrice=tfPrice.getText();
				String strNumber=tfNumber.getText();
                sql="insert into bookinfo(book_name,book_price,book_number)values('"+strName+"','"+strPrice+"','"+strNumber+"')";
				System.out.println(sql);
				addbook.executeUpdate(sql);
				
			}
			else if (e.getSource()==btnClose)
			{
				addbook.close();
				dispose();
			}
}}

⌨️ 快捷键说明

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