一个简单的java记事本程序

这是一个用Java编写的简易日记本程序,包含了标题、日期、天气和心情输入,支持日记的保存、查看、新建和检索功能。用户可以选择天气并添加表情,程序能够根据输入的天气进行日记数量的统计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

               

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import java.io.*;

 

 

public class diary extends JFrame{

 
  static String file="a.ou";
  JFrame f=new JFrame("日记本");
  Container p=f.getContentPane();
  Calendar c1=Calendar.getInstance();
  File iconDir = new File("心情表情");
  JOptionPane jop=new JOptionPane();
  File file1=null;
  final File[] iconFiles = iconDir.listFiles(new FileFilter() {
            public boolean accept(File file)
             {
              return file.getName().toLowerCase().endsWith(".gif");
                 }
                 });

  JLabel jlabel1=new JLabel("标 题"),         //建立标签
         jlabel2= new JLabel("日 期"),
         jlabel3=new JLabel("天 气"),
         jlabel4=new JLabel("心 情");
      
        
 
  JTextArea
     t4=new JTextArea(1,8),
     t3=new JTextArea(1,8),
     t2=new JTextArea(1,20),
     t1=new JTextArea(40,80);
   
  String[] description={       
      "阴天","晴天","下雨了","起风了",        //天气组合框
      "下雪了","有点热","有点冷"};
  JComboBox c=new JComboBox(); 
  final JComboBox comboBox = new JComboBox(iconFiles);
  JPanel
    pp=new JPanel(),
    pa=new JPanel(),
    ppanel=new JPanel();
  FileDialog fd;
  JButton                //建立按钮             
  
     save=new JButton("保存日记"),
     open=new JButton("查看日记"),
     newFile =new JButton("新建日记"),
     about=new JButton("关于"),
     search=new JButton("检索日记");
 
 
 
  JScrollPane jscrollpane=new JScrollPane(t1);//建立滚动条
  

  public diary(){           //把组件加入到面板中
        ppanel.add(newFile);
        ppanel.add(save);
        ppanel.add(open);
        ppanel.add(search);
        ppanel.add(about);
     
        pa.add(jlabel1);
        pa.add(t2);
        pa.add(jlabel3);
        pa.add(c);
        pa.add(jlabel4);
        pa.add(comboBox);
        pa.add(jlabel2);
        pa.add(t3);
 
        pp.add(t4);
        t3.append(c1.get(Calendar.YEAR)+
                 " 年 "+(c1.get(Calendar.MONTH)+1)+
                 " 月 " + c1.get(Calendar.DATE)+"日");
        t4.append(c1.get(Calendar.YEAR)+
                 "."+(c1.get(Calendar.MONTH)+1)+
                 "." + c1.get(Calendar.DATE));
        newFile.addActionListener(new ActionListener(){  //新建日记
            public void actionPerformed(ActionEvent e){
                    save.setEnabled(true);
                    t1.setText(" ");
                    t2.setText(" ");
 &nb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值