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

📄 alter.java

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

public class Alter implements ActionListener{
		String RID = "0";
		JFrame fAdd;
        JButton commit;
        JButton reset;
        Container addPane;
        Container addPaneMS;
        Container addPaneUp;
        Container addPaneDown;
        JLabel ms;
        JLabel workDate, regDate, content, other, state;
        JTextField workDateT, regDateT, contentT, otherT, stateT;
        ConnectAccess CA = new ConnectAccess();
        
	public Alter() {
		fAdd= new JFrame("修改信息");
        commit = new JButton("修改");
        reset = new JButton("重置");
        addPane = new JPanel();
        addPaneMS = new JPanel();
        addPaneUp = new JPanel();
        addPaneDown = new JPanel();
        ms = new JLabel("修改记录");
        regDate = new JLabel("登记日期 : ");
        regDateT = new JTextField("");
        workDate = new JLabel("应办日期 : ");
        workDateT = new JTextField("");
        content = new JLabel("日程内容 : ");
        contentT = new JTextField("");
        other = new JLabel("备注 : ");
        otherT = new JTextField("");
        state = new JLabel("完成状态");
        stateT = new JTextField("");
        
        fAdd.add(addPane);
        addPane.setLayout(new BorderLayout());
        addPane.add("North", addPaneMS);
        addPane.add("Center", addPaneUp);
        addPane.add("South", addPaneDown);
        addPaneUp.setLayout(new GridLayout(6, 2));
        addPaneDown.setLayout(new GridLayout(1, 2));
        addPaneMS.setLayout(new GridLayout(1, 1));
        addPaneMS.add(ms, SwingConstants.CENTER);
        ms.setForeground(Color.red);
        ms.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20));
        addPaneUp.add(regDate);
        addPaneUp.add(regDateT);
        addPaneUp.add(workDate);
        addPaneUp.add(workDateT);
        addPaneUp.add(content);
        addPaneUp.add(contentT);
        addPaneUp.add(other);
        addPaneUp.add(otherT);
        addPaneUp.add(state);
        addPaneUp.add(stateT);
        addPaneDown.add(commit);
        addPaneDown.add(reset);
        commit.addActionListener(this);
        reset.addActionListener(this);
        CA.createConn_Direct();
        AlterInit();
        
        fAdd.setSize(400, 300);
        fAdd.show();
	}
	
	public void AlterInit() {
		String sql=null;
		
		RID = JOptionPane.showInputDialog("请输入要修改的记录编号:", null);
		sql = "select * from work where ID = " + RID;
		if (CA.exeSQL(sql)) {
			try {
				if (CA.rs.next()) {
					
					regDateT.setText(CA.rs.getString(4));
					workDateT.setText(CA.rs.getString(3));
					contentT.setText(CA.rs.getString(5));
					otherT.setText(CA.rs.getString(6));
					stateT.setText(CA.rs.getString(7));
				}
			}
			catch (Exception ex) {
				System.out.println("Error in AlterInit(): " + ex);
			}
		}
	}
	
	public void AlterCommit() {
		RecordType rt= new RecordType();
        
        if (workDateT.getText().length()==0 || contentT.getText().length()==0)
        	JOptionPane.showMessageDialog(null, "请将信息填写完整!");
        else {
        	rt.setID(RID);
	        rt.setRegDate(regDateT.getText());
	        rt.setWorkDate(workDateT.getText());
	        rt.setContent(contentT.getText());
	        rt.setOther(otherT.getText());
	        if (stateT.getText().startsWith("1"))
	        	rt.setState(1);
	        else rt.setState(0);
	    }  
		if (CA.alterData(rt))
			JOptionPane.showMessageDialog(null, "修改成功!");
		else
			JOptionPane.showMessageDialog(null, "修改失败!");
		
	}
	
	public void actionPerformed(ActionEvent e){
		if (e.getSource() == commit)
			AlterCommit();
		else if (e.getSource() == reset)
			AlterInit();
	}
	
	public static void main(String[] args) {
		Alter Add1 = new Alter();
	}
	
}

⌨️ 快捷键说明

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