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

📄 menu1_3.java

📁 实现一个图书管理系统的界面。要求简洁美观。可以把主要功能放在状态栏上。
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.sql.*;
public class Menu1_3 extends JFrame implements ActionListener{
	JLabel lbl1=new JLabel("排架号");
	JLabel lbl2=new JLabel("排架名");
	JButton btn1=new JButton("添加");
	JButton btn2=new JButton("退出");
	JButton btn4=new JButton("浏览");
	JButton btn5=new JButton("退出");
	JTextField txt1=new JTextField(10);
	JTextField txt2=new JTextField(10);
	JTextField txt3=new JTextField(10);
	String col[]={"排架号","排架名"};
	String rows[][]=new String[5][2];
	JTable tb;
	JScrollPane jsp;
	JTabbedPane tab=new JTabbedPane();
	public Menu1_3()	//构造函数
    {
        init();
    	btn1.addActionListener(this);
    	btn2.addActionListener(this);
    	btn4.addActionListener(this);
    	btn5.addActionListener(this);
    }
	public void init()
    {
    	this.setTitle("图书架排管理");
        //-------------------Tab1-----------------------------
   		JPanel jp1=new JPanel();
   		jp1.setLayout(new GridLayout(2,2));
   	    jp1.add(lbl1);jp1.add(txt1);
   	    jp1.add(lbl2);jp1.add(txt2);	
   		JPanel jp2=new JPanel();
    	jp2.add(btn1);jp2.add(btn2);
    	
    	JPanel jp3=new JPanel();
    	jp3.setLayout(new BorderLayout());
    	jp3.add(jp1,BorderLayout.CENTER);
    	jp3.add(jp2,BorderLayout.SOUTH);
    	
    	//-------------------Tab2-----------------------------
    	
    	JPanel jp4=new JPanel();
        jp4.add(btn4);jp4.add(btn5);
      	tb=new JTable(rows,col);
    	jsp=new JScrollPane(tb);

    	JPanel jp5=new JPanel();
    	jp5.setLayout(new BorderLayout());
    	jp5.add(jsp,BorderLayout.CENTER);
    	jp5.add(jp4,BorderLayout.SOUTH);
    
    	//-------------------放置Tab-----------------------------
    	tab.add(jp3,"注册");tab.add(jp5,"改查删");
    	this.getContentPane().add(tab);
    	
    	this.setLocation(200,200);
    	this.setSize(500,300);
    	this.setVisible(true);
    
    }
    public void actionPerformed(ActionEvent e)
    {
    	if(e.getSource()==btn1){
			try{	
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection("jdbc:odbc:yyp","","");
			Statement cmd=con.createStatement();
			cmd.executeUpdate("insert into bookDesk(bDeskId,bDeskName) values('"+txt1.getText()+"',"+"'"+txt2.getText()+"')");	
			JOptionPane.showMessageDialog(this,"储存成功");		
    		}
				catch(Exception ex)
			{
				System.out.println(ex);
			}   
		}				
    	if(e.getSource()==btn2)
    		this.dispose();
    	if(e.getSource()==btn4){
    		try{
    			int flag=0;
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				Connection con=DriverManager.getConnection("jdbc:odbc:yyp","","");
				Statement cmd=con.createStatement();
				ResultSet rs=cmd.executeQuery("select * from bookDesk");
				while(rs.next())
				{
						rows[flag][0]=rs.getString(1);
						rows[flag][1]=rs.getString(2);
						
					    flag++;
					    tb.setModel(new DefaultTableModel(rows,col));
				}
			}
				catch(Exception ex)
			{
				System.out.println(ex);
			}   		
			}		
    	if(e.getSource()==btn5)
    		this.dispose();
    }
     public static void main(String arg[]){
    	Menu1_3 frm=new Menu1_3();
    	frm.setSize(420,320);
    	frm.setVisible(true);
    }
}

⌨️ 快捷键说明

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