日历记事本
源代码在线查看: note.java
/*
* Note.java
*
* Created on 2007年5月2日, 上午10:01
*/
package outlook;
import java.util.*;
import javax.swing.WindowConstants;
/**
*
* @author yy
*/
public class Note extends javax.swing.JFrame {
String filename;
String dt=new String("m");
boolean have=false;
/** Creates new form Note */
public Note() {
initComponents();
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
}
public void noteShow(String n) {
filename=n;
this.setTitle(filename+"的日程安排");
if(Main.ht.containsKey(filename)) {
dt=((String)(Main.ht.get(filename))).substring(0,1);
txtNote.setText(((String)(Main.ht.get(filename))).substring(1));
have=true;
}
else {
txtNote.setText("");
have=false;
}
this.show();
}
/** 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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
txtNote = new javax.swing.JTextArea();
Menu = new javax.swing.JMenuBar();
File = new javax.swing.JMenu();
Save = new javax.swing.JMenuItem();
Choose = new javax.swing.JMenu();
bithday = new javax.swing.JMenuItem();
meeting = new javax.swing.JMenuItem();
game = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
txtNote.setColumns(20);
txtNote.setRows(5);
jScrollPane1.setViewportView(txtNote);
File.setText("\u6587\u4ef6");
Save.setText("\u4fdd\u5b58");
Save.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
SaveMouseClicked(evt);
}
});
File.add(Save);
Menu.add(File);
Choose.setText("\u7c7b\u578b");
bithday.setText("\u751f\u65e5");
bithday.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bithdayActionPerformed(evt);
}
});
Choose.add(bithday);
meeting.setText("\u4f1a\u8bae");
meeting.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
meetingActionPerformed(evt);
}
});
Choose.add(meeting);
game.setText("\u5a31\u4e50");
game.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gameActionPerformed(evt);
}
});
Choose.add(game);
Menu.add(Choose);
setJMenuBar(Menu);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// //GEN-END:initComponents
private void bithdayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bithdayActionPerformed
// TODO add your handling code here:
dt="b";
}//GEN-LAST:event_bithdayActionPerformed
private void meetingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_meetingActionPerformed
// TODO add your handling code here:
dt="m";
}//GEN-LAST:event_meetingActionPerformed
private void gameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gameActionPerformed
// TODO add your handling code here:
dt="g";
}//GEN-LAST:event_gameActionPerformed
private void SaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveMouseClicked
// TODO add your handling code here:
Save();
}//GEN-LAST:event_SaveMouseClicked
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
Save();
}//GEN-LAST:event_formWindowClosing
private void Save() {
if(have)
if(txtNote.getText().length()>0)
Main.ht.put(filename,dt+txtNote.getText());
else
Main.ht.remove(filename);
else
if(txtNote.getText().length()>0)
Main.ht.put(filename,dt+txtNote.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Note().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu Choose;
private javax.swing.JMenu File;
private javax.swing.JMenuBar Menu;
private javax.swing.JMenuItem Save;
private javax.swing.JMenuItem bithday;
private javax.swing.JMenuItem game;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JMenuItem meeting;
private javax.swing.JTextArea txtNote;
// End of variables declaration//GEN-END:variables
}