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

📄 pubs.java

📁 table小例子 table小例
💻 JAVA
字号:
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class Pubs extends JFrame
{
	private Connection con;
	private Statement  stmt;
	private ResultSet  rs;
	
    private  final JTextField txt_id=new JTextField();
    private  final JTextField txt_desc=new JTextField();
    private  final JTextField txt_max_lvl=new JTextField();
    private  final JTextField txt_min_lvl=new JTextField(); 
    
    private  final JButton   btnfirst=new JButton(new MoveAction("<<"));
    private  final JButton   btnlast=new JButton(new MoveAction(">>"));
    private  final JButton   btnnext=new JButton(new MoveAction(">"));
    private  final JButton   btnpreviout=new JButton(new MoveAction("<"));

    private  final JButton   btnadd=new JButton(new MoveAction("添加"));
    private  final JButton   btndel=new JButton(new MoveAction("删除"));
    private  final JButton   btnmodify=new JButton(new MoveAction("修改"));
    private  final JButton   btnupdate=new JButton(new MoveAction("更新"));
    
    private  final JButton   btnexit=new JButton(new MoveAction("退出"));
    private  final JButton   btntable=new JButton(new MoveAction("记录表"));
    class MoveAction extends AbstractAction
    {
    	public MoveAction(String name)
    	{
    		super(name);
    	}
    	public void actionPerformed(ActionEvent e)
    	{
    		try
    		{
    			if(getValue(Action.NAME)==">")
    			{
    				if(rs.next())
    				{
    					display();
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null,"这是最后一条记录","Pubs_jobs",JOptionPane.INFORMATION_MESSAGE);
    					rs.last();
    					display();
    				}
    			}
    			if(getValue(Action.NAME)=="<")
    			{
    				if(rs.previous())
    				{
    				    display();	
    				}
    				else
    				{
    					JOptionPane.showMessageDialog(null,"这是第一条记录!","Pubs_jobs",JOptionPane.INFORMATION_MESSAGE);
    					rs.first();
    					display();
    				}
    			}
    			if(getValue(Action.NAME)==">>")
    			{
    				rs.last();
    				display();
    			}
    			if(getValue(Action.NAME)=="<<")
    			{
    				rs.first();
    				display();
    			}
    			if(getValue(Action.NAME)=="退出")
    			{
    			    System.exit(0);
    			}
    			if(getValue(Action.NAME)=="记录表")
    			{
    				new rstable("Pub_Table");
    			}
    			    
    		}
    		catch(Exception me)
    		{
    			System.out.println("Move Exception: "+me);
    		}
    	}
    }
    class rstable extends JFrame
    {
    	 protected void frameInit()
         {
    	      super.frameInit();
    	
          }
    	public rstable(String title)
    	{
    		super(title);
    		String data[][]=new String[20][4];
    		int i=0;
    		try
    		{
    			rs.first();
    			while(rs.next())
    			{
    				data[i][0]=rs.getString(1);
    				data[i][1]=rs.getString(2);
    				data[i][2]=rs.getString(3);
    				data[i][3]=rs.getString(4);
    				i++;
    			}
    			String colums[]={"工作编号","工作类别","最小LVL","最大LVL"};
    			getContentPane().add(new JTable(data,colums),BorderLayout.CENTER);
    		}
    		catch(Exception e)
    		{
    			System.out.println("Inner Frame Exception: "+e);
    		} 
    		pack();		
    		show();
    	}
    }
    
    public void display()
    {
    	try
    	{
    		 txt_id.setText(rs.getString("job_id"));
    	     txt_desc.setText(rs.getString("job_desc"));
    	     txt_min_lvl.setText(rs.getString("min_lvl"));
    	     txt_max_lvl.setText(rs.getString("max_lvl"));
        }
        catch(Exception e)
        {
        	System.out.println("Display Exception: "+e);
        }       	
    }
    protected void frameInit()
    {
    	super.frameInit();
    	
    }
    public Pubs(String title)
    {
    	super(title);
    	try
    	{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		con=DriverManager.getConnection("jdbc:odbc:pubs","sa","bsd");
    		System.out.println("Connection success");
    		stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    	   	System.out.println("Statement success");
    		rs=stmt.executeQuery("select * from jobs");
    		System.out.println("ResultSet success");
    	 	System.out.println("Cursor direction: "+rs.getFetchDirection());
    		System.out.println("Direction: "+rs.getType());
    		rs.next();
            Container contentpane=getContentPane();
            JPanel panel=new JPanel();
            panel.setLayout(new GridLayout(4,2));
            
            JLabel label=new JLabel("工作编号:");
            panel.add(label);
            panel.add(txt_id);
            
            label=new JLabel("工作类别:");
            panel.add(label);
            panel.add(txt_desc);
            
            label=new JLabel("最小LVL :");
            panel.add(label);
            panel.add(txt_min_lvl);
            
            label=new JLabel("最大LVL :");
            panel.add(label);
            panel.add(txt_max_lvl);
            
            contentpane.add(panel,BorderLayout.NORTH);
            
            panel=new JPanel();
            panel.setLayout(new GridLayout(2,1));
            JPanel browsepanel=new JPanel();
            Border border=BorderFactory.createTitledBorder("记录浏览");
            browsepanel.setBorder(border);
            browsepanel.setLayout(new GridLayout(1,4));
            browsepanel.add(btnfirst);
            browsepanel.add(btnpreviout);
            browsepanel.add(btnnext);
            browsepanel.add(btnlast);
            panel.add(browsepanel);
            
            JPanel modifypanel=new JPanel();
            Border bordermodi=(BorderFactory.createTitledBorder("修改记录"));
            modifypanel.setBorder(bordermodi);
            modifypanel.setLayout(new GridLayout(1,4));
            modifypanel.add(btnadd);
            modifypanel.add(btndel);
            modifypanel.add(btnmodify);
            modifypanel.add(btnupdate);
            panel.add(modifypanel);
            contentpane.add(panel,BorderLayout.CENTER);
            
            panel=new JPanel();
            panel.setLayout(new GridLayout(1,2));
            panel.add(btntable);
            panel.add(btnexit); 
            contentpane.add(panel,BorderLayout.SOUTH);          
            display();
            
        }
        catch(Exception e)
        {
        	System.out.println("Init Exception: "+e);
        }
    }
    public static void main(String args[])
    {
    	JFrame mm=new Pubs(("Pub_Java_demo"));
    	mm.pack();
    	mm.show();
    }
}
            
            

⌨️ 快捷键说明

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