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

📄 show.java

📁 个人之前学JAVA编的一个日程管理小系统(用界面操作ACCESS).可当初学JAVA和数据库例子.
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

public class Show implements ActionListener{
	JFrame showF = new JFrame("查看记录信息");  //???????????
	ConnectAccess CA1 = new ConnectAccess();
	RecordType rt = new RecordType();
	JPanel showP = new JPanel();
	JPanel showPMS = new JPanel();
    JPanel showPUp = new JPanel();
    JPanel showPDown = new JPanel();
    JLabel ms = new JLabel("浏览信息");
    JLabel addID = new JLabel("记录编号:");
    JLabel addIDShow = new JLabel();
    JLabel addTime = new JLabel("登记时间:");
    JLabel addTimeShow = new JLabel();
    JLabel doTime = new JLabel("应办时间:");
    JLabel doTimeShow = new JLabel();
    JLabel content = new JLabel("日程内容:");
    JLabel contentShow = new JLabel();
    JLabel other = new JLabel("备注:");
    JLabel otherShow = new JLabel();
    JLabel state = new JLabel("完成状况:");
    JLabel stateShow = new JLabel();
    JButton preB = new JButton("前一条");
    JButton aftB = new JButton("后一条");
    JButton firstB = new JButton("第一条");
    JButton lastB = new JButton("最未条");
    JButton searchB = new JButton("搜索");
    
	public Show() {
    	JPanel showP = new JPanel();
    	JPanel showPUp = new JPanel();
    	JPanel showPDown = new JPanel();
		showF.setSize(500, 400);
		showF.add(showP);
    	showP.setLayout(new BorderLayout());
    	showP.setBackground(Color.BLUE);
    	showPMS.setLayout(new GridLayout(1, 1));
    	showPUp.setLayout(new GridLayout(6, 2));
    	showPDown.setLayout(new GridLayout(1, 5));
    	showP.add("North", showPMS);
    	showP.add("Center", showPUp);
    	showP.add("South", showPDown);
    	showPMS.add(ms, SwingConstants.CENTER);
    	ms.setForeground(Color.red);
    	ms.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20));
    	showPUp.add(addID);
    	showPUp.add(addIDShow);
    	showPUp.add(addTime);
    	showPUp.add(addTimeShow);
    	showPUp.add(doTime);
    	showPUp.add(doTimeShow);
    	showPUp.add(content);
    	showPUp.add(contentShow);
    	showPUp.add(other);
    	showPUp.add(otherShow);
    	showPUp.add(state);
    	showPUp.add(stateShow);
    	preB.addActionListener(this);
    	aftB.addActionListener(this);
    	firstB.addActionListener(this);
    	lastB.addActionListener(this);
    	searchB.addActionListener(this);
    	showPDown.add(preB);
    	showPDown.add(aftB);
    	showPDown.add(firstB);
    	showPDown.add(lastB);
    	showPDown.add(searchB);
    	
    	showF.show();
    }
    
    public void search() {
    	String inf = null;
    	inf = JOptionPane.showInputDialog("请输入您要搜索的记录应办日期:", null);
    	System.out.println("inf = " + inf);
    	String sql = "select * from work where content = '%学校%'";
		CA1.exeSQL(sql);
		try {
			if (CA1.rs.next())
	    		set(CA1.rs);
	    	else
	    		JOptionPane.showMessageDialog(null, "对不起,暂无您要查找的记录!");
	    }
    	catch (Exception ex) {
			System.out.println("ERROR in search() : " + ex);
		}
    }
    
    public void find() {
    	try {
	    	CA1.createConn_Direct();
	    	CA1.exeSQL("select * from work");
	    	System.out.println("Find OK!");
	    	if (CA1.rs.next())
	    		set(CA1.rs);  //???????????????
    	}
    	catch (Exception ex) {
			System.out.println("ERROR in find() : " + ex);
		}
    }
    
    public void set(ResultSet rs) {
    	try {
		    if (!CA1.rs.wasNull()) {
		    	addIDShow.setText(rs.getString(1));
			    addTimeShow.setText(rs.getString(4));
			    doTimeShow.setText(rs.getString(3));
			    contentShow.setText(rs.getString(5));
			    otherShow.setText(rs.getString(6));
			    if (rs.getString(7).startsWith("1"))
			    	stateShow.setText("已完成");
			    else stateShow.setText("暂未完成");
		   	} else
		   		JOptionPane.showMessageDialog(null, "对不起,暂无记录!");
	   }
	   catch (Exception ex) {
			System.out.println("ERROR in set(ResultSet rs) : " + ex);
	   }
    }
    
    public void preCommit() {
    	try {
	    	if (CA1.rs.previous())
	    		set(CA1.rs);
	    	else
	    		JOptionPane.showMessageDialog(null, "已是第一条记录");
    	}
	    catch (Exception ex) {
			System.out.println("ERROR in preCommit() : " + ex);
		}
    }
    
    public void aftCommit() {
    	try {
	    	if (CA1.rs.next())
	    		set(CA1.rs);
	    	else
	    		JOptionPane.showMessageDialog(null, "已是最后一条记录");
    	}
	    catch (Exception ex) {
			System.out.println("ERROR in aftCommit() : " + ex);
		}
    }
    
    public void firstCommit() {
    	try {
	    	if (CA1.rs.first()) 
	    		set(CA1.rs);
	    	else
	    		JOptionPane.showMessageDialog(null, "找不到首记录");
	    	System.out.println("第一条记录!");
    	}
	    catch (Exception ex) {
			System.out.println("ERROR in firstCommit() : " + ex);
		}
    }
    
    public void lastCommit() {
    	try {
	    	if (CA1.rs.last())
	    		set(CA1.rs);
	    	else
	    		JOptionPane.showMessageDialog(null, "找不到未记录");
	    	System.out.println("最后一条记录!");
    	}
	    catch (Exception ex) {
			System.out.println("ERROR in lastCommit() : " + ex);
		}
    }
    
    public void actionPerformed(ActionEvent e){
		if (e.getSource() == preB)
			preCommit();
		else if (e.getSource() == aftB)
			aftCommit();
		else if (e.getSource() == firstB)
			firstCommit();
		else if (e.getSource() == lastB)
			lastCommit();
		else if (e.getSource() == searchB)
			search();
	}
	
	public static void main(String[] args) {
		Show show1 = new Show();
		show1.find();
		//show1.CA1.closeSQL();
	}
}

⌨️ 快捷键说明

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