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

📄 bookinfoview.java

📁 代码是自己我的代码不是网上down的。是自己写的。里面有很多值得学习的知识点。还有一些javabean组件。不算自己写的JAR文件
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class BookInfoView extends JFrame
{
	ResultSet rs;
	private DBManager db=new DBManager();
	private JPanel centerpanel;
	private JPanel southpanel;
	private JLabel bookname;
	private JLabel publisher;
	private JLabel auther;
	private JLabel address;
	private JLabel publisherDate;
	private JLabel price;
	private JLabel comment;
	private JTextField mybookname;
    private JTextField mypublisher;
    private JTextField myauther;
    private JTextField myaddress;
    private JTextField mypublisherDate;
    private JTextField myprice;
    private JTextField mycomment;
	JButton ok;
    JButton edit;
	JButton del;
	JButton cancel;
	JButton clear;
    
	public BookInfoView()
	{
	centerpanel=new JPanel(new GridLayout(7,2));
	southpanel=new JPanel(new GridLayout(1,1));
	bookname=new JLabel("书 名");
	publisher=new JLabel("出版社");
	auther=new JLabel("作 者");
	address=new JLabel("地 址");
	publisherDate=new JLabel("出版日期");
	price=new JLabel("价 格");
	comment=new JLabel("备 注");
	mybookname=new JTextField(16);
    mypublisher=new JTextField(16);
    myauther=new JTextField(16);
    myaddress=new JTextField(16);
    mypublisherDate=new JTextField(16);
    myprice=new JTextField(16);
    mycomment=new JTextField(16);
	ok=new JButton("添加");
	edit=new JButton("修改");
	del=new JButton("删除");
	cancel=new JButton("查询");
	clear=new JButton("清空");
	centerpanel.add(bookname);
	centerpanel.add(mybookname);
	centerpanel.add(publisher);
	centerpanel.add(mypublisher);
	centerpanel.add(auther);
	centerpanel.add(myauther);
	centerpanel.add(address);
	centerpanel.add(myaddress);
    centerpanel.add(publisherDate);
    centerpanel.add(mypublisherDate);
    centerpanel.add(price);
    centerpanel.add(myprice);
    centerpanel.add(comment);
    centerpanel.add(mycomment);
	southpanel.add(clear);
	southpanel.add(ok);
	southpanel.add(edit);
	southpanel.add(del);
	southpanel.add(cancel);
	getContentPane().add(centerpanel,"Center");
	getContentPane().add(southpanel,"South");
    
	//setSize(300,260);
	Dimension screen=getToolkit().getScreenSize();
	setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2);
		addWindowListener(
			new WindowAdapter()
			{
				public void windowClosing(WindowEvent e)
				{
					System.exit(0);
				}
			}
			);
		cancel.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					BookSearch();
				}
			}
			);
		ok.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					BookAdd();
				}
			}
			);
		del.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					BookDel();
				}
			}
			);
			edit.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					BookEdit();
				}
			}
			);		
		clear.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					BookClear();
				}
			}
			);	
		show();
	}
	public void BookAdd()
	{
		if(mybookname.getText().trim().equals(""))
		{
			JOptionPane.showMessageDialog(this,"书名不能为空!");
			return;
		}
		
		else if(myauther.getText().trim().equals(""))
		{
			JOptionPane.showMessageDialog(this,"作者不能为空!");
			return;
		}
		else if(mypublisher.getText().trim().equals(""))
		{
			JOptionPane.showMessageDialog(this,"出版社不能为空!");
			return;
		}
	    else if(myprice.getText().trim().equals(""))
		{
			JOptionPane.showMessageDialog(this,"价格不能为空!");
			return;
		}
	   else
	   {
	   	BookBean bean=new BookBean();
		bean.setBookname(mybookname.getText().trim());
	    bean.setPress(mypublisher.getText().trim());
	    bean.setAuther(myauther.getText().trim());
	    bean.setAddress(myaddress.getText().trim());
	    bean.setPressdate(mypublisherDate.getText().trim());
	    bean.setPrice(myprice.getText().trim());
	    bean.setComment(mycomment.getText().trim());
	   if(bean.isnull())
	   {
	   	    if (bean.insert()) {
            JOptionPane.showMessageDialog(this, "插入成功!");
        } else {
            JOptionPane.showMessageDialog(this, "插入失败!");
        }
	   }
	   else
    	{
    		JOptionPane.showMessageDialog(this, "此图书信息已经存在!");
    	}
		
	   }
	  
	
		
	}
	public void BookDel()
	{
		BookBean bean=new BookBean();
		bean.setBookname(mybookname.getText().trim());
		if(bean.isnull())
		{
			JOptionPane.showMessageDialog(this, "没有此记录!");
            return;
		}
		 if (bean.delete()) {
            JOptionPane.showMessageDialog(this, "删除成功!");
        } else {
            JOptionPane.showMessageDialog(this, "删除失败!");
        }	
	}
	public void BookEdit()
	{
		BookBean bean=new BookBean();
		bean.setBookname(mybookname.getText().trim());
	    bean.setPress(mypublisher.getText().trim());
	    bean.setAuther(myauther.getText().trim());
	    bean.setAddress(myaddress.getText().trim());
	    bean.setPressdate(mypublisherDate.getText().trim());
	    bean.setPrice(myprice.getText().trim());
	    bean.setComment(mycomment.getText().trim());
		 if (bean.isnull()) {
            JOptionPane.showMessageDialog(this, "没有此记录!");
            return;
        }

        if (bean.modify()) {
            JOptionPane.showMessageDialog(this, "修改成功!");
        } else {
            JOptionPane.showMessageDialog(this, "修改失败!");
        }
	}
	public void BookSearch()
	{
		ResultSet rs=null;
		rs=new DBManager().execute("select * from 书籍信息表 where bookname='"+mybookname.getText()+"'");
		try
		{
		if(rs.next())
	    {
	    	mybookname.setText(rs.getString("bookname"));
	    	mypublisher.setText(rs.getString("press"));
	    	myauther.setText(rs.getString("auther"));
	    	myaddress.setText(rs.getString("address"));
	    	mypublisherDate.setText(rs.getString("pressdate"));
	    	myprice.setText(rs.getString("price"));
	    	mycomment.setText(rs.getString("comment"));
	    }
	    else
	    {
	       JOptionPane.showMessageDialog(this, "没有此记录!");
	    }	
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());
		}
	    
	}
	
	public void BookClear()
	{
		mybookname.setText("");
		mypublisher.setText("");
		myauther.setText("");
		myaddress.setText("");
		mypublisherDate.setText("");
		myprice.setText("");
		mycomment.setText("");
	}
}

⌨️ 快捷键说明

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