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

📄 remark.java

📁 电子日历
💻 JAVA
字号:
package re;

import re.Display;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.JOptionPane;



public class Remark extends Frame implements ActionListener
{
    Connection con;
    Statement stmt;
    ResultSet rs;
    Button btque,btupd,btinc,btdel,btvie,btext;
    TextField tfld1,tfld2,tfld3;
    String ke,nm,prc;
    String str1,str2,str3;
    
    public Remark()
    {
        super("备忘录");
        setLayout(null);
        setSize(340,300);
        setVisible(true);
        setBackground(Color.cyan);
        btque= new Button("查询");
        btupd= new Button("修改");
        btinc= new Button("添加");
        btdel= new Button("删除");
        btvie= new Button("显示");
        btext= new Button("退出");
        add(btque);add(btupd);add(btinc);
        add(btdel);add(btvie);add(btext);
        Label lb1 = new Label("密钥:");
        Label lb2 = new Label("日期:");
        Label lb3 = new Label("事件:");
        tfld1 =new TextField();
        tfld2 =new TextField();
        tfld3 =new TextField();
        add(lb1);add(lb2);add(lb3);
        add(tfld1);add(tfld2);add(tfld3);
        btque.setBounds(50,50,50,30);
        btupd.setBounds(140,50,50,30);
        btvie.setBounds(230,50,50,30);
        btinc.setBounds(50,110,50,30);
        btdel.setBounds(140,110,50,30);
        btext.setBounds(230,110,50,30);
        lb1.setBounds(30,170,40,20);
        lb2.setBounds(30,210,40,20);
        lb3.setBounds(30,250,40,20);
        tfld1.setBounds(80,170,200,20);
        tfld2.setBounds(80,210,200,20);
        tfld3.setBounds(80,250,200,40);
        btque.addActionListener(this);
        btupd.addActionListener(this);
        btinc.addActionListener(this);
        btdel.addActionListener(this);
        btvie.addActionListener(this);
        btext.addActionListener(this);
        addWindowListener(
                new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                dispose();
            }
        });
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            con = DriverManager.getConnection("jdbc:derby://localhost:1527/Calender");
            stmt = con.createStatement();
        }
        catch(Exception e){}
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==btque)
        {

            try
            {                         
                int rec=0;
                String sql = "SELECT \"key\" ,\"date\" ,\"event\" FROM \"Calender\"";
                ResultSet rs = stmt.executeQuery(sql);
                while (rs.next())
                {             
                    ke = rs.getString("key");
                    nm =rs.getString("date");
                    prc = rs.getString("event");
                    if(ke.equals(tfld1.getText().trim()))
                    {
                        tfld2.setText(nm);
                        tfld3.setText(prc);
                        rec = 1;
                        break;
                    }
                }
                if(rec == 0) tfld3.setText("没有记录事件.");
                rs.close();
                
                }
            catch(Exception e1)
                {
                    System.out.println(e1.toString());
            }
        }
        
        if(e.getSource()==btupd)
        {
            int rec=0;
            try
            {
                str1=tfld1.getText().trim();
                str2=tfld2.getText().trim();
                str3=tfld3.getText().trim();
                
                String strupd = "update \"Calender\" set \"date\"=" +
                        "'" +str2+ "'" + "where \"key\"=" + "'"  +str1+ "'";
                String strupd1 = "update \"Calender\" set \"event\"=" +
                        "'" +str3+ "'" + "where \"key\"=" + "'"  +str1+ "'";
                stmt.executeUpdate(strupd);
                stmt.executeUpdate(strupd1);
                rec=1;
            }
            catch(Exception e2){}
            if(rec==1)
               JOptionPane.showMessageDialog(null,"数据已经修改","修改数据",JOptionPane.QUESTION_MESSAGE);
        }
        if(e.getSource()==btinc)
        {
            int rec=0;
            try
            {
              
                str1="'"+tfld1.getText().trim()+"'";
                str2="'"+tfld2.getText().trim()+"'";
                str3="'"+tfld3.getText().trim()+"'";
                String strinc = "insert into \"Calender\" values(" +str1+","+str2+","+str3+")";
                stmt.executeUpdate(strinc);
                rec=1;
            }
            catch(Exception e3){}
            if(rec==1)
               JOptionPane.showMessageDialog(null,"数据已经添加","添加数据",JOptionPane.QUESTION_MESSAGE);
        }
        if(e.getSource()==btdel)
        {
            int rec=0;
            try
            {
                str1="'"+tfld1.getText().trim()+"'";
                String strdel = "delete  from \"Calender\" where" + "\"key\" = " +str1;
                stmt.executeUpdate(strdel);
                rec=1;
            }
            catch(Exception e4){}
            if(rec==1)
               JOptionPane.showMessageDialog(null,"数据已经删除","删除数据",JOptionPane.QUESTION_MESSAGE);
        }
         if(e.getSource()==btvie)
        {
            re.Display dlg =new re.Display();
         }
         if(e.getSource()==btext)
        {
            try
            {
                rs.close();
                stmt.close();
                con.close();
            }
            catch(Exception e6){}
            dispose();
         }
    }
    }

⌨️ 快捷键说明

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