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

📄 addnote.java

📁 基于java开发的个人数字助理
💻 JAVA
字号:
/*
 * AddNote.java
 *
 * Created on 2008年4月3日, 下午4:48
 */

package pda;


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author  bzu
 */
public class AddNote extends javax.swing.JFrame {
    
    /** Creates new form AddNote */
    public AddNote() {
        super("添加事务");
        initComponents();
        time();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        thing = new javax.swing.JLabel();
        thingField = new javax.swing.JTextField();
        timeLabel = new javax.swing.JLabel();
        timeField = new javax.swing.JTextField();
        addButton = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        Menu = new javax.swing.JMenu();
        addMenuItem = new javax.swing.JMenuItem();

        thing.setText("\u4e8b\u52a1\u5185\u5bb9\uff1a");

        timeLabel.setText("\u63d0\u9192\u65f6\u95f4\uff1a");

        addButton.setText("\u6dfb\u52a0");
        addButton.setMaximumSize(new java.awt.Dimension(59, 25));
        addButton.setMinimumSize(new java.awt.Dimension(59, 25));
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        Menu.setText("\u529f\u80fd");
        addMenuItem.setText("\u6dfb\u52a0");
        addMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMenuItemActionPerformed(evt);
            }
        });

        Menu.add(addMenuItem);

        jMenuBar1.add(Menu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(thing, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(timeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(timeField, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(thingField, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                        .addGap(98, 98, 98))
                    .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(thingField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(thing))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(timeLabel)
                    .addComponent(timeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-422)/2, (screenSize.height-298)/2, 422, 298);
    }// </editor-fold>//GEN-END:initComponents

    private void addMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMenuItemActionPerformed
// TODO 将在此处添加您的处理代码:
        addnote();
        NoteBook nb=new NoteBook();
        nb.setVisible(true);
        //nb.Thingshow();
        this.setVisible(false);
    }//GEN-LAST:event_addMenuItemActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
// TODO 将在此处添加您的处理代码:
        addnote();
        NoteBook nb=new NoteBook();
        nb.setVisible(true);
        //nb.Thingshow();
        this.setVisible(false);
    }//GEN-LAST:event_addButtonActionPerformed
    
    public void addnote(){
        file=new File("src/database/pda.mdb");//经典所在:不用配置数据源
        path="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+file.getAbsolutePath();//获取绝对路径
        thingStr=thingField.getText();
        timeStr=timeField.getText();
        up="INSERT INTO notebook VALUES("+"'"+thingStr+"','"+timeStr+"')";
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:pda");
            //Connection con=DriverManager.getConnection(path);
            Statement stmt=con.createStatement();
            stmt.executeUpdate(up);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /**
     * @param args the command line arguments
     */
     /*public static void main(String args[]) {
        AddNote an=new AddNote();
        an.setVisible(true);
        an.time();
    }*/
     public void time(){
         t=new GregorianCalendar();
         n=t.get(t.YEAR)+"-"+(t.get(t.MONTH)+1)+"-"+t.get(t.DAY_OF_MONTH)+"  "+t.get(t.HOUR_OF_DAY)+":"+t.get(t.MINUTE)+":"+t.get(t.SECOND);
         timeField.setText(n);
     }
     public void fileF(){
         try {
            File f1=new File("note.txt");
            FileWriter fw1=new FileWriter(f1);
            BufferedWriter bw1=new BufferedWriter(fw1);
            String th=thingField.getText();
            bw1.write(th,0,th.length());
            bw1.flush();
            bw1.close();
            fw1.close();
            File f2=new File("time.txt");
            FileWriter fw2=new FileWriter(f2);
            BufferedWriter bw2=new BufferedWriter(fw2);
            String ti=timeField.getText();
            bw2.write(ti,0,ti.length());
            bw2.flush();
            bw2.close();
            fw2.close();
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        NoteBook nb=new NoteBook();
        nb.setVisible(true);
        //nb.Thingshow();
        this.setVisible(false);
     }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JMenu Menu;
    private javax.swing.JButton addButton;
    private javax.swing.JMenuItem addMenuItem;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JLabel thing;
    private javax.swing.JTextField thingField;
    private javax.swing.JTextField timeField;
    private javax.swing.JLabel timeLabel;
    // 变量声明结束//GEN-END:variables
    Calendar t;
    String n,thingStr,timeStr,up,path;
    File file;
}

⌨️ 快捷键说明

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