演示图
演示图
Calendarapp.java
Календа дня упаковки; импорт java.awt.borderlayout; import java.awt.color; import java.awt.flowlayout; import java.awt.font; import java.awt.gridlayout; импорт java.awt.event.actionevent; import java.awt.event; .ActionListener; Import java.awt.event.mouseevent; import java.awt.event.mouselistener; импорт java.io.file; импорт java.text.simpledateformat; импорт java.util.calendar; импорт java.util.date; import. java.util.gregoriancalendar; импорт java.util.locale; Импорт javax.swing.japplet; import javax.swing.jbutton; import javax.swing.jcombobox; импорт javax.swing.jframe; импорт javax.swing.jlabel; импорт javax.swing.jpanel; импорт javax.swingtitieties; javax.swing.border.titledborder; Public Class CalendarApp Extends jFrame {Private CalendarPanel CalendarPanel = new CalendarPanel (); Частный статический jlabel jlbllearn = new jlabel ("开始准备记单词"); Private String versionId = "欢迎使用版本 1.0.20150427"; Частный jlabel jlblversionid = new jlabel (versionid); Частный JButton JBTPrior = new Jbutton ("←"); Частный jbutton jbtnext = new jbutton ("→"); Частный JButton JBTDIARY = new Jbutton ("写日记"); Частный jbutton jbtscandiary = new jbutton ("看日记"); частный статический год; public void init () {Год = 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); / * * 给四个按钮添加鼠标事件 , 使其更加炫酷 */// 一、后退按钮 jbtprior.addmouseListener (new MouseListener () {@Override public void mouseeClicked (mouseevent arg0) {// todo автоматически сгенерированный метод stub} @override public void mouseEnted (mouseevent arg0) {// todo автоматически генерируемый метод jbtprior.setfore (color.green); setforeground (color.black); // 二、前进按钮 jbtNext.AddMouseListener (new MouseListener () {@Override public void mouseeClicked (mouseevent arg0) {// todo Автогенерированный метод stub} @override public void mouseEnted (mouseevent arg0) {// todo Auto-Generated Метод stub jbtnext.setforeground (color.green); // TODO Автогенерированный метод stub} @Override public void mousereAlededued (mouseevent arg0) {// todo автоматически сгенерированный метод}}}); // 三、写日记按钮 jbtdiary.addmouseListener (new MouseListener () {@Override public void mouseeClicked (mouseevent arg0) {// todo автоматически генерируемый метод stub} @override public void mouseEnted (museeevent arg0) {// todo auto- Сгенерированный метод stub jbtdiary.setforeground (color.green); {// TODO Auto Generated Method stub} @Override public void mouserEleadeedEd (mouseevent arg0) {// todo Автогенерированный метод stub}}); // 四、看日记按钮 jbtscandiary.addmouseListener (new MouseListener () {@Override public void mouseeClicked (mouseevent arg0) {// todo автоматически генерируемый метод stub} Сгенерированный метод stub jbtscandiary.setforeground (color.green); {// TODO Auto Generated Method stub} @Override public void mouserEleadeedEd (mouseevent arg0) {// todo Автогенерированный метод 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 Treadborder ("开心背单词")); 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); это. setize (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 Threat_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 ()); jbtprior.addactionListener (new ActionListener () {@Override public void actionperformed (actionevent e) {// todo автоматически генерируемый метод int currentmonth = calendarpanel.getmonth (); if (currentMonth == 0) {calendarPanel.setyear (год); ; jbtnext.addactionListener (new ActionListener () {@Override public void actionperformed (actionevent e) {// todo автоматически сгенерированный метод int currentmonth = calendarpanel.getmonth (); if (currentmonth == 11) {calendarpanel.setyear (++; Год); } public static void main (string [] args) бросает прерывания. ) .init (); }} CalendarPanel.java
/** * 本程序功能是进行日历主面板布局 */CALENDA; Импорт java.awt.borderlayout; import java.awt.color; import java.awt.font; import java.awt.gridlayout; импорт java.awt.event.mouseevent; импорт java.awt.event.mouselistener; импорт java.text; .Dateformatsymbols; import java.text.simpledateformat; import java.util.calendar; импорт java.util.gregoriancalendar; импорт java.util.locale; Импорт javax.swing.*; импортировать javax.swing.border.lineborder; Public Class CalendarPanel Extends jPanel { / ** * 声明数据变量 * / Private Static Long Long SerialVersionUID = 1L; Частный jlabel jlblheader = new jlabel ("", jlabel.center); private jlabel [] jlblday = new jlabel [49]; Частный календарь календарь = новый gregoriancalendar (); private int year0 = calendar.get (calendar.year); private int month0 = calendar.get (calendar.month); private int day0 = calendar.get (calendar.day_of_month); частный месяц INT; частный год; частный день Int; private jpanel jpdays = new jpanel (new Gridlayout (0,7)); Font font1 = новый шрифт ("宋体", font.italic, 20); Font font2 = новый шрифт ("宋体", font.bold, 26); Font font3 = новый шрифт ("宋体", font.bold, 30); publicalendarpanel () {// 设置日历头部件以及日期标签的背景色为白色 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] .sethorizontalalInment (jlabel.right); jlblday [i] .setverticalAlignment (jlabel.top); } calendar = new GregorianCalendar (); месяц = календарь.get (calendar.month); Год = календарь.get (calendar.year); day = calendar.get (calendar.date); // 更新日历 UpdateCalendar (); ShowHeader (); showdays (); // 添加到主面板 this.setlayout (new Borderlayout ()); это. this.add (jpdays, borderlayout.center); } private void showheader () {simpleDateformat sdf = new SimpleDateFormat ("Mmmm yyyy", locale.china); String header = sdf.format (calendar.gettime ()); jlblheader.settext (заголовок); 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] .sethorizontalalInment (jlabel.center); jlblday [i] .setfont (font2); jpdays.add (jlblday [i]); }} public void showdays () {jpdays.removeall (); ShowdayNames (); int startdayOfmonth = calendar.get (calendar.day_of_week); Календарь клонекалендар = (календарь) Календарь.clone (); clonecalendar.add (calendar.date, -1); int DaysInprecedingMonth = cloneCalendar.getActualMaximum (calendar.day_of_month); for (int i = 0; i <startdayofmonth-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 && Год == Год 0 && месяц == месяц0) {jlblday [i-2+startdayOfmonth+7] .SetforeGhore (color.red); jlblday [i-2+startdayOfmonth+7] .SethorizontalAlignment (jlabel.center); jlblday [i-2+startdayOfmonth+7] .settext (i+""); jlblday [i-2+startdayOfmonth+7] .setFont (font2); jpdays.add (jlblday [i-2+startdayofmonth+7]); } else {jlblday [i-2+startdayOfmonth+7] .Setforeground (color.darkgray); jlblday [i-2+startdayOfmonth+7] .SethorizontalAlignment (jlabel.center); jlblday [i-2+startdayOfmonth+7] .settext (i+""); jlblday [i-2+startdayOfmonth+7] .setFont (font1); jpdays.add (jlblday [i-2+startdayofmonth+7]); }} int j = 1; for (int i = daysincurrentmonth-1+startdayOfmonth+7; i%7! = 0; i ++) {jlblday [i] .setforeground (color.light_gray); jlblday [i] .sethorizontalalInment (jlabel.center); jlblday [i] .settext (j +++""); jlblday [i] .setfont (font1); jpdays.add (jlblday [i]); } jpdays.repaint (); } public void updateCalendar () {calendar.set (calendar.year, Год); Calendar.Set (Calendar.Month, Month); Calendar.Set (Calendar.Date, 1); месяц = календарь.get (calendar.month); Год = календарь.get (calendar.year); day = calendar.get (calendar.date); } public int getMonth () {return Month; } public int getyear () {everate Год; } public void setMonth (int month) {this.Month = месяц; UpdateCalendar (); ShowHeader (); showdays (); } public void setyear (int Год) {this.year = Год; UpdateCalendar (); ShowHeader (); showdays (); }}Дневник. Ява
/** * 本程序为日记类 * 最后修改日期为 2015-4-27 */Calenda; Импорт java.io.file; import java.io.fileinputstream; import java.io.fileOutputStream; импорт java.io.objectInputStream; импорт java.io.objectOutputStream; импорт java.io.serializable; импортировать javax.swing.joptionpane; Дневник открытого класса реализует Serializable { /** * 数据域 * /// 私有变量 Private String Filename; Частная струнная тема; частный строковый контент; // 含参构造方法 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 Calendardariariarfile = new File ("c:/calendar/diary"); if (! calendardariarfile.exists ()) {calendardariariarfile.mkdirs (); } this.filename = "c:/calendar/diary/"+filename+". Dat"; this.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 (это); oos.close (); } public Diary Read () Throws Exception {file file = new File (fileName); FileInputStream fis = new FileInputStream (file); ObjectInputStream OIS = new ObjectInputStream (FIS); Дневник D = (дневник) OIS.ReadObject (); ois.close (); возврат D; } / ** * 变量 get () 方法 * @return * / public String getTheme () {return this.theme; } public String getContent () {return this.content; } /** * 变量 set () 方法 * @param comment * /}Threat_keepdiary.java
/** * 备忘录线程 * 用于单击标签时可以存储日记 * 目前只考虑年月日时间点 , 不标记具体时间点 */CALENDA; Импорт java.awt.borderlayout; импорт java.awt.event.actionevent; импорт java.awt.event.actionlistener; импорт java.io.file; импорт java.nio.file.files; импортировать javax.swing.*; public class thread_keepdiary extends jframe реализует runnable {private jframe jf = this; private jtextarea jta = new jtextarea (); Частный jbutton jbtsave = new jbutton ("保存"); Частный jlabel jlbltitle = new jlabel ("主题"); private Jtextfield Jtftitle = new JTextfield (16); Приватный идентификатор строки; public Think_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 = время; jbtsave.addactionListener (new ActionListener () {@Override public void actionPerformed (actionEvent arg0) {// todo автоматически генерируется метод Stub String Theme = jtftitle.getText (). Trim (); String content = jta.getText (); Diary d_today = новый дневник (ID, тема, контент); ); this.setTitle ("备忘录"+id); this.add (jsp, borderlayout.center); this.add (jptitle, borderlayout.north); это. это. Setize (500 500); this.SetLocationRelativeTo (null); this.setDefaultCloseoperation (dispose_on_close); } @Override public void run () {this.setVisible (true); }}thine_mottosparkle.java
Календа дня упаковки; импортировать javax.swing.jlabel; открытый класс Theth_mottosparkle реализует Runnable {private jlabel jlbl; public think_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
/*** 查看日记线程编写*/CALENDA; Импорт java.awt.borderlayout; import java.awt.color; import java.awt.font; import java.awt.event.actionevent; импорт java.awt.event.actionlistener; import java.io.file; импорт java.io .FileInputStream; импорт java.io.objectInputStream; Импорт javax.swing.*; import javax.swing.table.defaulttablecellrenderer; import javax.swing.table.defaulttablemodel; import javax.swing.table.jtableHeader; public class thread_scandiary extends jframe реализует runnable { / ** * 声明变量区 * / private static final long serialversionuid = 1l; // 日历数据库存放路径 Private String Path = "C:/Calendar/Diary"; // 日历总个数 Частный статический int num; // 声明日历文件 Частный файл файла; частный файл [] дневник; // 声明 JTable 模型 Private JTable JTable; // 声明格言面板及标签及内容等 Private JPanel JPMotto = new jPanel (); Частный jlabel jlblmotto = new jlabel (); частный шрифт font = новый шрифт ("宋体", font.italic, 20); Приватная строка weals = "唯有专注 , 才能让自己成功。"; // 增加弹出式菜单 2015-4-26 Private Jpopupmenu jpopupmenu1 = new jpopupmenu (); // 声明菜单 private jmenuitem jmiscan = new jmenuitem ("查看"); Частный jmenuitem jmidelete = new jmenuitem ("删除"); Частный 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 = новый объект [num] [2]; for (int i = 0; i <num; i ++) {try {string time = дневник [i] .getName (). replyfirst (". dat", ""); FileInputStream fis = new FileInputStream (Diary [i]); ObjectInputStream OIS = new ObjectInputStream (FIS); Дневник D = (дневник) OIS.ReadObject (); ois.close (); String Theme = D.GetTheme (); Дневник [i] [0] = время; Дневник [i] [1] = тема; } 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 (дневник, голова); 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 (); // 设置 Таблица 内容居中 tcr.sethorizontalAlignment (swingconstants.center); // 这句和上句作用一样 jtable.setDefaulderenderer (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 (); OIS = New ObjectStream (FIS); "); JTextField Jtftitle = new JTextField (16); JPanel jptitle = new jPanel (); jptitle.setLayout (new Borderlayout ()); Jptitle.Add (jlbltitle, borderlayout.west); jptitle.add (jtftitle, borderlayout.courter ); .getContent ()); jf.settitle ("日记"+дневник [index] .getName (). replyfirst (". 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 () +"?"); else {}} else {joptionpane.showmessageDialog (null, "请先选中一个日记!"); / ** * 主框架布局 */ this.add (jsp, borderlayout.center); this.add (jpmotto, borderlayout.south); это. setize (600, 500); this.setDefaultCloseoperation (dispose_on_close); this.SetLocationRelativeTo (null); this.setTitle ("日记列表"); this.setvisible (true); новая ветка (new Think_mottoSparkle (jlblmotto)). start (); }}thine_showenglish.java
Календа дня упаковки; Импорт java.awt.color; import java.awt.font; import java.io.bufferedReader; импорт java.io.filereader; import java.io.lineMumberReader; импорт java.security.securerandom; import java.util.random; импортировать javax.swing.jlabel; открытый класс Threat_ShowEnglish реализует runnable {private static jlabel jlbl = new jlabel (); Font font = новый шрифт ("��� ו", font.bold, 18); public think_showenglish (jlabel jlbl) {this.jlbl = jlbl; jlbl.setforeground (color.magenta); jlbl.setfont (font); } @Override public void run () {// todo автоматически генерируемый метод atub int count = 0; try {string file = "c: /calendar/learning/english_word.txt"; BufferedReader input = new BufferedReader (новый FileReader (файл)); 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 (файл)); 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 (); }}}以上所述就是本文的全部内容了 , 希望大家能够喜欢。