程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Java完成超等適用的日志本

Java完成超等適用的日志本

編輯:關於JAVA

Java完成超等適用的日志本。本站提示廣大學習愛好者:(Java完成超等適用的日志本)文章只能為提供參考,不一定能成為您想要的結果。以下是Java完成超等適用的日志本正文


演示圖

演示圖

CalendarApp.java

package calenda;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
 
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
 
public class CalendarApp extends JFrame{
   
  private CalendarPanel calendarPanel=new CalendarPanel();
  private static JLabel jlblLearn=new JLabel("開端預備記單詞");
  private String versionID="迎接應用版本1.0.20150427";
  private JLabel jlblVersionID=new JLabel(versionID);
  private JButton jbtPrior=new JButton("←");
  private JButton jbtNext=new JButton("→");
  private JButton jbtDiary=new JButton("寫日志");
  private JButton jbtScanDiary=new JButton("看日志");
  private static int year;
  public void init()
  {
    year=calendarPanel.getYear();
    calendarPanel.setBackground(Color.WHITE);
    /**
     * 添加功效性按鈕到日歷面板下方
     */
    JPanel jpButtons=new JPanel(new FlowLayout());
    //設置按鈕配景色為白色
    jbtPrior.setBackground(Color.WHITE);
    jbtNext.setBackground(Color.WHITE);
    jbtDiary.setBackground(Color.WHITE);
    jbtScanDiary.setBackground(Color.WHITE);
    /*
     * 給四個按鈕添加鼠標事宜,使其加倍炫酷
     */
    //1、撤退退卻按鈕
    jbtPrior.addMouseListener(new MouseListener(){
 
      @Override
      public void mouseClicked(MouseEvent arg0) {
        // TODO Auto-generated method stub
         
      }
 
      @Override
      public void mouseEntered(MouseEvent arg0) {
        // TODO Auto-generated method stub
        jbtPrior.setForeground(Color.GREEN);
      }
 
      @Override
      public void mouseExited(MouseEvent arg0) {
        // TODO Auto-generated method stub
        jbtPrior.setForeground(Color.BLACK);
      }
 
      @Override
      public void mousePressed(MouseEvent arg0) {
        // TODO Auto-generated method stub
         
      }
 
      @Override
      public void mouseReleased(MouseEvent arg0) {
        // TODO Auto-generated method stub
         
      }
       
    });
    //2、進步按鈕
        jbtNext.addMouseListener(new MouseListener(){
 
          @Override
          public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtNext.setForeground(Color.GREEN);
          }
 
          @Override
          public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtNext.setForeground(Color.BLACK);
          }
 
          @Override
          public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
           
        });
        //3、寫日志按鈕
        jbtDiary.addMouseListener(new MouseListener(){
 
          @Override
          public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtDiary.setForeground(Color.GREEN);
          }
 
          @Override
          public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtDiary.setForeground(Color.BLACK);
          }
 
          @Override
          public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
           
        });
        //4、看日志按鈕
        jbtScanDiary.addMouseListener(new MouseListener(){
 
          @Override
          public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtScanDiary.setForeground(Color.GREEN);
          }
 
          @Override
          public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub
            jbtScanDiary.setForeground(Color.BLACK);
          }
 
          @Override
          public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
 
          @Override
          public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub
             
          }
           
        });
    jpButtons.add(jbtPrior);
    jpButtons.add(jbtNext);
    jpButtons.add(jbtDiary);
    jpButtons.add(jbtScanDiary);
    jpButtons.setBackground(Color.WHITE);
    /**
     * 添加日歷重要組件
     */
    JPanel jpCalendar=new JPanel(new BorderLayout());
    jpCalendar.add(calendarPanel,BorderLayout.CENTER);
    jpCalendar.add(jpButtons,BorderLayout.SOUTH);
     
    /**
     * 添加背單詞模塊
     */
    JPanel jpLearn=new JPanel(new FlowLayout());
    jpLearn.setBorder(new TitledBorder("高興背單詞"));
    jpLearn.add(jlblLearn);
    jpLearn.setBackground(Color.WHITE);
    /**
     * 添加版本號信息
     */
    JPanel jpVersionID=new JPanel(new FlowLayout());
    Font font=new Font("宋體",Font.PLAIN,4);
    jpVersionID.setFont(font);
    jpVersionID.add(jlblVersionID);
    jpVersionID.setBackground(Color.WHITE);
    /**
     * 容器面板,歸並記單詞與版本號模塊
     */
    JPanel jpBelow=new JPanel(new BorderLayout(2,1));
    jpBelow.add(jpLearn,BorderLayout.CENTER);
    jpBelow.add(jpVersionID,BorderLayout.SOUTH);
     
    this.add(jpCalendar,BorderLayout.CENTER);
    this.add(jpBelow,BorderLayout.SOUTH);
    this.setBackground(Color.WHITE);
    this.setSize(700, 500);
    this.setLocationRelativeTo(null);
    this.setTitle("多功效日歷");
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setVisible(true);
     
    jbtScanDiary.addActionListener(new ActionListener()
    {
      @Override
      public void actionPerformed(ActionEvent e) {
          new Thread(new thread_scanDiary()).start();
      }
    });
    jbtDiary.addActionListener(new ActionListener()
    {
 
      @Override
      public void actionPerformed(ActionEvent e) {
        //獲得當地體系時光
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");//設置日期格局
        String time=df.format(new Date());
        new Thread(new thread_keepDiary(time)).start();
      }
    });
     
     
     
    jbtPrior.addActionListener(new ActionListener()
    {
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        int currentMonth=calendarPanel.getMonth();
        if(currentMonth==0)
        {
          calendarPanel.setYear(year);
          year--;
        }
        calendarPanel.setMonth((currentMonth-1)%12);
      }
    });
     
    jbtNext.addActionListener(new ActionListener()
    {
 
      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        int currentMonth=calendarPanel.getMonth();
        if(currentMonth==11)
        {
          calendarPanel.setYear(++year);
        }
        calendarPanel.setMonth((currentMonth+1)%12);
      }
    });
  }
   
 
  public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub
    SwingUtilities.invokeLater(new Runnable(){
      @Override
      public void run() {
        // TODO Auto-generated method stub
        new CalendarApp().init();
        new Thread(new thread_showEnglish(jlblLearn)).start();
      }
    });
  }
   
 
}

CalendarPanel.java

/**
 * 本法式功效是停止日歷主面板結構
 */
package calenda;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
 
import javax.swing.*;
import javax.swing.border.LineBorder;
 
public class CalendarPanel extends JPanel {
  /**
   * 聲明數據變量
   */
  private static final long serialVersionUID = 1L;
  private JLabel jlblHeader=new JLabel(" ",JLabel.CENTER);
  private JLabel[] jlblDay=new JLabel[49];
  private Calendar calendar=new GregorianCalendar();
  private int year0=calendar.get(Calendar.YEAR);
  private int month0=calendar.get(Calendar.MONTH);
  private int day0=calendar.get(Calendar.DAY_OF_MONTH);
  private int month;
  private int year;
  private int day;
  private JPanel jpDays=new JPanel(new GridLayout(0,7));
  Font font1=new Font("宋體",Font.ITALIC,20);
  Font font2=new Font("宋體",Font.BOLD,26);
  Font font3=new Font("宋體",Font.BOLD,30);
  public CalendarPanel()
  {
    //設置日歷頭部件和日期標簽的配景色為白色
    jlblHeader.setBackground(Color.WHITE);
    jpDays.setBackground(Color.WHITE);
    //聲明每一個標簽
    for(int i=0;i<49;i++)
    {
      jlblDay[i]=new JLabel();
      jlblDay[i].setBorder(new LineBorder(Color.LIGHT_GRAY,1));
      jlblDay[i].setHorizontalAlignment(JLabel.RIGHT);
      jlblDay[i].setVerticalAlignment(JLabel.TOP);
    }
    calendar=new GregorianCalendar();
    month=calendar.get(Calendar.MONTH);
    year=calendar.get(Calendar.YEAR);
    day=calendar.get(Calendar.DATE);
    //更新日歷
    updateCalendar();
    showHeader();
    showDays();
    //添加到主面板
    this.setLayout(new BorderLayout());
    this.add(jlblHeader, BorderLayout.NORTH);
    this.add(jpDays, BorderLayout.CENTER);
  }
  private void showHeader()
  {
    SimpleDateFormat sdf=new SimpleDateFormat("MMMM yyyy",Locale.CHINA);
    String header=sdf.format(calendar.getTime());
    jlblHeader.setText(header);
    jlblHeader.setForeground(Color.BLUE);
    jlblHeader.setFont(font3);
  }
  private void showDayNames()
  {
    DateFormatSymbols dfs=new DateFormatSymbols(Locale.CHINA);
    String dayNames[]=dfs.getWeekdays();
    for(int i=0;i<7;i++)
    {
      jlblDay[i].setText(dayNames[i+1]);
      jlblDay[i].setForeground(Color.BLUE);
      jlblDay[i].setHorizontalAlignment(JLabel.CENTER);
      jlblDay[i].setFont(font2);
      jpDays.add(jlblDay[i]);
    }
  }
  public void showDays()
  {
    jpDays.removeAll();
    showDayNames();
    int startingDayOfMonth=calendar.get(Calendar.DAY_OF_WEEK);
    Calendar cloneCalendar=(Calendar)calendar.clone();
    cloneCalendar.add(Calendar.DATE, -1);
    int daysInPrecedingMonth=cloneCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    for(int i=0;i<startingDayOfMonth-1;i++)
    {
      jlblDay[i+7].setForeground(Color.LIGHT_GRAY);
      jlblDay[i+7].setHorizontalAlignment(JLabel.CENTER);
      jlblDay[i+7].setText(daysInPrecedingMonth-startingDayOfMonth+2+i+"");
      jlblDay[i+7].setFont(font1);
      jpDays.add(jlblDay[i+7]);
    }
    int daysInCurrentMonth=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    for(int i=1;i<=daysInCurrentMonth;i++)
    {
      if(i==day0&&year==year0&&month==month0)
      {
        jlblDay[i-2+startingDayOfMonth+7].setForeground(Color.red);
        jlblDay[i-2+startingDayOfMonth+7].setHorizontalAlignment(JLabel.CENTER);
        jlblDay[i-2+startingDayOfMonth+7].setText(i+"");
        jlblDay[i-2+startingDayOfMonth+7].setFont(font2);
        jpDays.add(jlblDay[i-2+startingDayOfMonth+7]);
      }
      else
      {
        jlblDay[i-2+startingDayOfMonth+7].setForeground(Color.darkGray);
        jlblDay[i-2+startingDayOfMonth+7].setHorizontalAlignment(JLabel.CENTER);
        jlblDay[i-2+startingDayOfMonth+7].setText(i+"");
        jlblDay[i-2+startingDayOfMonth+7].setFont(font1);
        jpDays.add(jlblDay[i-2+startingDayOfMonth+7]);
      }
    }
    int j=1;
    for(int i=daysInCurrentMonth-1+startingDayOfMonth+7;i%7!=0;i++)
    {
      jlblDay[i].setForeground(Color.LIGHT_GRAY);
      jlblDay[i].setHorizontalAlignment(JLabel.CENTER);
      jlblDay[i].setText(j++ +"");
      jlblDay[i].setFont(font1);
      jpDays.add(jlblDay[i]);
    }
    jpDays.repaint();
  }
  public void updateCalendar()
  {
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DATE, 1);
    month=calendar.get(Calendar.MONTH);
    year=calendar.get(Calendar.YEAR);
    day=calendar.get(Calendar.DATE);
  }
  public int getMonth()
  {
    return month;
  }
  public int getYear()
  {
    return year;
  }
  public void setMonth(int month)
  {
    this.month=month;
    updateCalendar();
    showHeader();
    showDays();
  }
  public void setYear(int year)
  {
    this.year=year;
    updateCalendar();
    showHeader();
    showDays();
  }
}

Diary.java

/**
 * 本法式為日志類
 * 最初修正日期為2015-4-27
 */
package calenda;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
 
import javax.swing.JOptionPane;
 
public class Diary implements Serializable {
 
  /**
   * 數據域
   */
  //公有變量
  private String filename;
  private String theme;
  private String content;
  //含參結構辦法
  public Diary(String filename,String theme,String content)
  {
    if(theme.length()==0)
    {
      JOptionPane.showMessageDialog(null, "不管心境若何,總得有個主題吧!");
    }
    else if(content.length()==0)
    {
      JOptionPane.showMessageDialog(null, "把高興的不高興的都縱情寫下吧!");
    }
    else
    {
      File CalendarDiaryFile=new File("C:/Calendar/Diary");
      if(!CalendarDiaryFile.exists())
      {
        CalendarDiaryFile.mkdirs();
      }
    this.filename="C:/Calendar/Diary/"+filename+".dat";
    this.theme=theme;
    this.content=content;
    }
  }
  public void write() throws Exception
  {
    File file=new File(filename);
    FileOutputStream fos = new FileOutputStream(file);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(this);
    oos.close();
  }
  public Diary read() throws Exception
  {
    File file=new File(filename);
    FileInputStream fis=new FileInputStream(file);
    ObjectInputStream ois = new ObjectInputStream(fis);
    Diary d=(Diary) ois.readObject();
    ois.close();
    return d;
  }
  /**
   * 變量get()辦法
   * @return
   */
  public String getTheme()
  {
    return this.theme;
  }
  public String getContent()
  {
    return this.content;
  }
  /**
   * 變量set()辦法
   * @param comment
   */
}

thread_keepDiary.java

/**
 * 備忘錄線程
 * 用於單擊標簽時可以存儲日志
 * 今朝只斟酌年代日時光點,不標志詳細時光點
 */
package calenda;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.nio.file.Files;
 
import javax.swing.*;
 
public class thread_keepDiary extends JFrame implements Runnable {
 
  private JFrame jf=this;
  private JTextArea jta=new JTextArea();
  private JButton jbtSave=new JButton("保留");
  private JLabel jlblTitle=new JLabel("主題");
  private JTextField jtfTitle=new JTextField(16);
  private String id;
  public thread_keepDiary(String time)
  {
     
    JPanel jpTitle=new JPanel();
    jpTitle.setLayout(new BorderLayout());
    jpTitle.add(jlblTitle, BorderLayout.WEST);
    jpTitle.add(jtfTitle,BorderLayout.CENTER);
    jta.setLineWrap(true);
    jta.setWrapStyleWord(true);
    JScrollPane jsp=new JScrollPane(jta);
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    this.id=time;
    jbtSave.addActionListener(new ActionListener()
    {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
         
        String theme=jtfTitle.getText().trim();
        String content=jta.getText();
         
        Diary d_today=new Diary(id,theme,content);
        try
        {
          d_today.write();
          JOptionPane.showMessageDialog(null, "保留勝利!");
          jf.dispose();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }
    });
    this.setTitle("備忘錄"+id);
    this.add(jsp,BorderLayout.CENTER);
    this.add(jpTitle, BorderLayout.NORTH);
    this.add(jbtSave, BorderLayout.SOUTH);
    this.setSize(500,500);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
     
  }
  @Override
  public void run() {
    this.setVisible(true);
  }
 
}

thread_mottoSparkle.java

package calenda;
 
import javax.swing.JLabel;
 
public class thread_mottoSparkle implements Runnable{
  private JLabel jlbl;
  public thread_mottoSparkle(JLabel jlbl)
  {
    this.jlbl=jlbl;
  }
  @Override
  public void run() {
    String content=jlbl.getText();
    int L=content.length();
    int index=0;
    while(true)
    {
      jlbl.setText(content.substring(0, index));
      try
      {
        Thread.sleep(250);
      }
      catch(Exception ex)
      {
        ex.printStackTrace();
      }
      index++;
      if(index==(L+1))
        index=0;
    }
  }
 
}

thread_scanDiary.java

/**
* 檢查日志線程編寫
*/
package calenda;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
 
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
 
public class thread_scanDiary extends JFrame implements Runnable{
  /**
   * 聲明變量區
   */
  private static final long serialVersionUID = 1L;
  //日歷數據庫寄存途徑
  private String path="C:/Calendar/Diary";
  //日歷總個數
  private static int num;
  //聲明日歷文件
  private File file;
  private File[] Diary;
  //聲明JTable模子
  private JTable jtable;
  //聲明格言面板及標簽及內容等
  private JPanel jpMotto=new JPanel();
  private JLabel jlblMotto=new JLabel();
  private Font font=new Font("宋體",Font.ITALIC,20);
  private String wish="惟有專注,能力讓本身勝利。";
  //增長彈出式菜單2015-4-26
  private JPopupMenu jPopupMenu1=new JPopupMenu();
  //聲明菜單
  private JMenuItem jmiScan=new JMenuItem("檢查");
  private JMenuItem jmiDelete=new JMenuItem("刪除");
  private JMenuItem jmiComment=new JMenuItem("評論");
  @Override
  public void run() {
    //測驗考試彈出式菜單增長子菜單
    jmiScan.setForeground(Color.RED);
    jmiDelete.setForeground(Color.RED);
    jmiComment.setForeground(Color.RED);
    jPopupMenu1.add(jmiScan);
    jPopupMenu1.addSeparator();
    jPopupMenu1.add(jmiDelete);
    jPopupMenu1.addSeparator();
    jPopupMenu1.add(jmiComment);
    /**
     * 智能獲得文件列表
     */
    file = new File(path);
    Diary=file.listFiles();
    num=Diary.length;
    String[] head={"  時光  ","   主題   "};
    Object[][] diary=new Object[num][2];
    for(int i=0;i<num;i++)
    {
        try{
           String time=Diary[i].getName().replaceFirst(".dat",  "");
           FileInputStream fis=new FileInputStream(Diary[i]);
           ObjectInputStream ois = new ObjectInputStream(fis);
           Diary d=(Diary) ois.readObject();
           ois.close();
           String theme=d.getTheme();
           diary[i][0]=time;
           diary[i][1]=theme;
        }
        catch(Exception ex)
        {
          ex.printStackTrace();
        }
    }
    /**
     * 格言面板取
     */
    jlblMotto.setText(wish);
    jlblMotto.setFont(font);
    jlblMotto.setForeground(Color.RED);
    jpMotto.add(jlblMotto);
    jpMotto.setBackground(Color.WHITE);
    /**
     * 日歷列外面板區
     */
    final DefaultTableModel tableModel=new DefaultTableModel(diary,head);
    jtable=new JTable(tableModel);
    jtable.setBackground(Color.WHITE);
    jtable.setRowHeight(30);
    jtable.setDoubleBuffered(false);
    jtable.setComponentPopupMenu(jPopupMenu1);
    jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// 設置table內容居中
    tcr.setHorizontalAlignment(SwingConstants.CENTER);// 這句和上句感化一樣
    jtable.setDefaultRenderer(Object.class, tcr);
    JScrollPane jsp=new JScrollPane(jtable);
     
    /**
     * 彈出式菜單事宜監聽器編寫
     */
    //檢查菜單
    jmiScan.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
        if(jtable.getSelectedRow()>=0)
        {
          int index=jtable.getSelectedRow();
          String filename="C:/Calendar/Diary/"+Diary[index].getName();
          File file=new File(filename);
          try
          {
            FileInputStream fis=new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Diary d=(Diary) ois.readObject();
            ois.close();
            JFrame jf=new JFrame();
            JTextArea jta=new JTextArea();
            JLabel jlblTitle=new JLabel("主題");
            JTextField jtfTitle=new JTextField(16);
            JPanel jpTitle=new JPanel();
            jpTitle.setLayout(new BorderLayout());
            jpTitle.add(jlblTitle, BorderLayout.WEST);
            jpTitle.add(jtfTitle,BorderLayout.CENTER);
            jta.setLineWrap(true);
            jta.setWrapStyleWord(true);
            JScrollPane jsp=new JScrollPane(jta);
            jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            jtfTitle.setText(d.getTheme());
            jta.setText(d.getContent());
            jtfTitle.setEditable(false);
            jta.setEditable(false);
            jf.setTitle("日志 "+Diary[index].getName().replaceFirst(".dat",  ""));
            jf.add(jsp,BorderLayout.CENTER);
            jf.add(jpTitle, BorderLayout.NORTH);
            jf.setSize(400,400);
            jf.setLocationRelativeTo(null);
            jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jf.setVisible(true);
          }
          catch(Exception ex)
          {
            ex.printStackTrace();
          }
        }
        else
        {
          JOptionPane.showMessageDialog(null, "請先選中一個日志!");
        }
      }
    });
    //刪除菜單
    jmiDelete.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
        if(jtable.getSelectedRow()>=0)
        {
          int index=jtable.getSelectedRow();
          String filename="C:/Calendar/Diary/"+Diary[index].getName();
          File file=new File(filename);
          int option=JOptionPane.showConfirmDialog(null, "你肯定要刪除日志"+Diary[index].getName()+"?"); 
           if(option==JOptionPane.YES_OPTION)
           {
             file.delete();
             tableModel.removeRow(index);
            SwingUtilities.updateComponentTreeUI(jtable);
            JOptionPane.showMessageDialog(null, "刪除勝利!");
           }
           else
           {
           }
        }
        else
        {
          JOptionPane.showMessageDialog(null, "請先選中一個日志!");
        }
      }
       
    });
    /**
     * 主框架結構
     */
    this.add(jsp,BorderLayout.CENTER);
    this.add(jpMotto, BorderLayout.SOUTH);
    this.setSize(600, 500);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.setLocationRelativeTo(null);
    this.setTitle("日志列表");
    this.setVisible(true);
    new Thread(new thread_mottoSparkle(jlblMotto)).start();
  }
}

thread_showEnglish.java

package calenda;
 
import java.awt.Color;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.LineNumberReader;
import java.security.SecureRandom;
import java.util.Random;
 
import javax.swing.JLabel;
 
public class thread_showEnglish implements Runnable {
  private static JLabel jlbl=new JLabel();
  Font font=new Font("���ו",Font.BOLD,18);
  public thread_showEnglish(JLabel jlbl)
  {
    this.jlbl=jlbl;
    jlbl.setForeground(Color.MAGENTA);
    jlbl.setFont(font);
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    int count=0;
    try
    {
      String file="C:/Calendar/Learning/english_word.txt";
      BufferedReader input = new BufferedReader(new FileReader(file));
      while(input.readLine()!=null)
      {
        count++;
      }
      input.close();
      int[] word = new int[count];
      SecureRandom random = new SecureRandom();
      for(int i=0;i<count;i++)
      {
        word[i]=random.nextInt(count);
      }
      int index=0;
      Thread.sleep(1000);
      while(true)
      {
        BufferedReader input1 = new BufferedReader(new FileReader(file));
        String content="";
        int line=0;
        while((content=input1.readLine())!=null)
        {
          if(line==word[index])
          {
            jlbl.setText(content);
          }
          line++;
        }
        if(index==count-1)
          index=0;
        else
          index++;
        Thread.sleep(3500);
      }
    }
    catch(Exception ex)
    {
      ex.printStackTrace();
    }
  }
}

以上所述就是本文的全體內容了,願望年夜家可以或許愛好。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved