演示图
演示图
Calendarapp.java
Kalenda paket; impor java.awt.borderlayout; impor java.awt.color; impor java.awt.flowlayout; import java.awt.font; import java.awt.gridlayout; import java.awt.event.actionevent; impor java.awt.event .ActionListener; import java.awt.event.mouseevent; impor java.awt.event.mouseListener; import java.io.file; import java.text.simpledateFormat; impor java.util.calendar; impor java.util.date; impor; java.util.gregoriancalendar; impor java.util.locale; impor javax.swing.japplet; import javax.swing.jbutton; impor javax.swing.jcombobox; import javax.swing.jframe; import javax.swing.jlabel; impor javax.swing.jpanel; impor javax.swing.swingutilities; impor javax.swing.border.titledborder; CalendARapp kelas publik memperluas jframe {private calendarpanel calendarpanel = calendarpanel baru (); private static Jlabel JlBlLearn = new jlabel ("开始准备记单词"); Private String VersiD = "欢迎使用版本 1.0.20150427"; Private Jlabel JlBlVersionId = JLabel baru (VersionID); private jbutton jbtprior = jbutton baru ("←"); private jbutton jbtNext = jbutton baru ("→"); private jbutton jbtdiary = jbutton baru ("写日记"); private jbutton jbtscandiary = jbutton baru ("看日记"); tahun int statis pribadi; public void init () {tahun = calendarpanel.getYear (); calendarpanel.setBackground (color.white); / ** * 添加功能性按钮到日历面板下方 */ jpanel jpbuttons = jpanel baru (flowlayout baru ()); // 设置按钮背景色为白色 JBTPrior.SetBackground (Color.White); jbtNext.setBackground (color.white); jbtDiary.setBackground (color.white); jbtscandiary.setBackground (color.white); / * * 给四个按钮添加鼠标事件 , 使其更加炫酷 */// 一、后退按钮 jbtprior.addmouseListener (mouseListener baru () {@Override public void mouseclicked (MouseEvent arg0) {// Metode yang dihasilkan secara otomatis TODO Auto Stub} @Override public void mouseEntered (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis Stub jbtprior.setForeground (color.green); setForeGround (Color.Black); // 二、前进按钮 jbtNext.addmouseListener (new mouseListener () {@Override public void mouseclicked (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis Stub} @Override public void mouseenter (mouseevent arg0) {// toO-generated public mouseenter (MouseEvent arg0) {// toO-generated public mouseNated (MouseEvent arg0) {/TODO Generated Metode Stub JBTNEXT.SetForeground (Color.Green); // TODO Metode yang dihasilkan otomatis Stub} @Override public void mousereleased (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis}}); // 三、写日记按钮 jbtDiary.addmouseListener (mouseListener baru () {@override public void mouseclicked (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis Stub} @Override public void mouseentered (MouseEvent arg0) {// TODO Auto- Metode yang dihasilkan Stub JBTDiary.setForeground (Color.green); {// TODO Metode yang dihasilkan otomatis Stub} @Override public void mousereLeased (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis}}); // 四、看日记按钮 jbtscandiary.addmouseListener (new mouseListener () {@override public void mouseclicked (MouseEvent arg0) {// TODO Metode yang dihasilkan otomatis Stub} @Override public void mouseEnterted (MouseEvent arg0) {// too auto- Metode yang Dihasilkan Stub JBTScandiary.setForeground (Color.Green); {// TODO Metode yang dihasilkan otomatis Stub} @Override public void mousereLeased (MouseEvent arg0) {// TODO Metode yang dihasilkan secara otomatis}}); jpbuttons.add (jbtprior); jpbuttons.add (jbtNext); jpbuttons.add (jbtdiary); jpbuttons.add (jbtscandiary); jpbuttons.setBackground (color.white); / ** * 添加日历主要组件 */ jpanel jpcalendar = jpanel baru (borderlayout baru ()); jpcalendar.add (calendarpanel, borderlayout.center); jpcalendar.add (jpbuttons, borderlayout.south); / ** * 添加背单词模块 */ jpanel jplearn = jpanel baru (flowlayout baru ()); jlearn.setborder (judul baru ("开心背单词")); jlearn.add (jlbllearn); jlearn.setBackground (color.white); / ** * 添加版本号信息 */ jpanel jpversionId = jpanel baru (flowlayout baru ()); Font font = font baru ("宋体", font.plain, 4); jpversionid.setfont (font); jpversionid.add (jlblversionId); jpversionid.setBackground (color.white); / ** * 容器面板 , 合并记单词与版本号模块 */ jpanel jpbelow = jpanel baru (BorderLayout baru (2,1)); jpbelow.add (jlearn, 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 (ActionListener baru () {@Override public void actionPerformed (actionEvent e) {thread baru (thread_scandiary baru ()). start ();}}); jbtDiary.addactionListener (ActionListener baru () {@Override public void actionPerformed (ActionEvent e) {// 获取本地系统时间 SimpleDateFormat df = new SimpleDateFormat ("yyyy-mm-dd-hh-mm-ss"); // 设置日期格式 string time = df.format (tanggal baru ()); JBTPrior.AddActionListener (ActionListener baru () {@Override public void actionPerformed (actionEvent e) {// TODO Metode yang dihasilkan secara otomatis stub int currentmonth = calendarpanel.setyarth (); if (currentmonth == 0) {calendarpanel.setyar (tahun); ; JBTNexT.AddActionListener (ActionListener baru () {@Override public void actionPerformed (ActionEvent e) {// TODO METODE AUTO-AUTOLETED Stub int Currentmonth = calendarpanel.setyarth (); if (currentMonth == 11) {calendarpanel.setyar (+++ (++ (if (lancar == 11) {calendarpanel.setyare (++ (++ (ifer = tahun); } public static void main (string [] args) melempar interruptedException {// toddo metode yang dihasilkan secara otomatis rintisan swingutilities.invokelater (runnable baru () {@override public void run () {// Todo Metode yang dihasilkan otomatis Stub new calendARapp () ) .init (); }} Calendarpanel.java
/** * 本程序功能是进行日历主面板布局 */Kalenda paket; impor java.awt.borderlayout; import java.awt.color; import java.awt.font; impor java.awt.gridlayout; import java.awt.event.mouseevent; impor java.awt.mouselistener; impor java.text .DateFormatsymbols; impor java.text.simpledateFormat; impor java.util.calendar; impor java.util.gregoriancalendar; impor java.util.locale; impor javax.swing.*; impor javax.swing.border.lineborder; Calendarpanel kelas publik memperluas jpanel { / ** * 声明数据变量 * / private static final long serialversionuid = 1l; private jlabel JlblHeader = new jlabel ("", jlabel.center); Private Jlabel [] jlblday = Jlabel baru [49]; Kalender Kalender Pribadi = GregorianCalendar baru (); private int year0 = calendar.get (calendar.year); private int month0 = calendar.get (calendar.month); private int day0 = calendar.get (calendar.day_of_month); Bulan int pribadi; tahun int pribadi; hari int pribadi; private jpanel jpdays = jpanel baru (gridlayout baru (0,7)); Font font1 = font baru ("宋体", font.italic, 20); Font font2 = font baru ("宋体", font.bold, 26); Font font3 = font baru ("宋体", font.bold, 30); calendarpanel publik () {// 设置日历头部件以及日期标签的背景色为白色 jlblheader.setBackground (color.white); jpdays.setbackground (color.hite); // 声明每个标签 untuk (int i = 0; i <49; i ++) {jlblday [i] = new jlabel (); jlblday [i] .setBorder (Lineborger baru (color.light_gray, 1)); jlblday [i] .sethorizontalAlignment (jlabel.right); jlblday [i] .setVerticalAlignment (jlabel.top); } calendar = new GregorianCalendar (); bulan = calendar.get (calendar.month); tahun = calendar.get (calendar.year); hari = calendar.get (calendar.date); // 更新日历 updateCalendar (); showheader (); showdays (); // 添加到主面板 this.setLayout (borderlayout baru ()); this.add (jlblheader, borderlayout.north); this.add (jpdays, borderlayout.center); } private void showheader () {SimpleDateFormat SDF = new SimpleDateFormat ("mmmm yyyy", locale.china); Header string = 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 (); untuk (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); Kalender clonecalendar = (kalender) kalender.clone (); clonecalendar.add (calendar.date, -1); int DaysInprecedingmonth = clonecalendar.getActualmaximum (calendar.day_of_month); untuk (int i = 0; i <startesdayofmonth-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); untuk (int i = 1; i <= daysincurrentmonth; i ++) {if (i == day0 && year == year0 && month == bulan0) {jlblday [i-2+startingdayOfmonth+7] .setForeground (color.red); jlblday [i-2+startdayofonth+7] .sethorizontalAlignment (jlabel.center); jlblday [i-2+startingdayofonth+7] .setText (i+""); jlblday [i-2+startdayofonth+7] .setFont (font2); jpdays.add (jlblday [i-2+startesdayofonth+7]); } else {jlblday [i-2+startingdayofmonth+7] .setForeground (color.darkgray); jlblday [i-2+startdayofonth+7] .sethorizontalAlignment (jlabel.center); jlblday [i-2+startingdayofonth+7] .setText (i+""); jlblday [i-2+startayofonth+7] .setFont (font1); jpdays.add (jlblday [i-2+startesdayofonth+7]); }} int j = 1; untuk (int i = DaysIncurrentmonth-1+startdayOfmonth+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, tahun); calendar.set (calendar.month, bulan); Calendar.set (Calendar.Date, 1); bulan = calendar.get (calendar.month); tahun = calendar.get (calendar.year); hari = calendar.get (calendar.date); } public int getMonth () {return month; } public int getYear () {return tahun; } public void setMonth (int month) {this.month = bulan; UpdateCalendar (); showheader (); showdays (); } public void setyear (int tahun) {this.year = tahun; UpdateCalendar (); showheader (); showdays (); }}Diary.java
/** * 本程序为日记类 * 最后修改日期为 2015-4-27 */Kalenda paket; impor java.io.file; impor java.io.fileInputStream; impor java.io.fileoutputStream; impor java.io.objectInputStream; import java.io.objectoutputStream; import java.io.serializable; impor javax.swing.joptionpane; buku harian kelas publik mengimplementasikan serial yang dapat diisi { /** * 数据域 * /// 私有变量 nama file string pribadi; tema string pribadi; konten string pribadi; // 含参构造方法 buku harian publik (nama file string, tema string, konten string) {if (tema.length () == 0) {jOptionPane.showmessageDialog (null, "无论心情如何 , 总得有个主题吧!") ; } else if (content.length () == 0) {joptionpane.showmessagealog (null, "把开心的不开心的都尽情写下吧!"); } else {file calendardiaryFile = file baru ("c:/calendar/diary"); if (! calendardiaryFile.exists ()) {calendardiaryfile.mkdirs (); } this.filename = "c:/calendar/diary/"+filename+". dat"; this.theme = tema; this.content = konten; }} public void write () melempar pengecualian {file file = file baru (nama file); FileOutputStream fos = baru fileOutputStream (file); ObjectOutputStream oos = ObjectOutputStream baru (FOS); oos.writeObject (ini); oos.close (); } buku harian public baca () melempar pengecualian {file file = file baru (nama file); FileInputStream fis = new fileInputStream (file); ObjectInputStream OIS = ObjectInputStream (FIS) baru; Buku harian d = (buku harian) ois.readObject (); ois.close (); kembali D; } / ** * 变量 get () 方法 * @return * / public string gettheme () {return this.theme; } public String getContent () {return this.content; } /** * 变量 set () 方法 * @param komentar * /}thread_keepdiary.java
/** * 备忘录线程 * 用于单击标签时可以存储日记 * 目前只考虑年月日时间点 , 不标记具体时间点 */Paket kalenda; impor java.awt.borderlayout; impor java.awt.event.actionevent; impor java.awt.event.actionlistener; impor java.io.file; impor java.nio.file.file; impor javax.swing.*; Public Class Thread_KeepDiary memperluas JFRame implement runnable {private jframe jf = this; private jTextArea jta = new jTextArea (); private jbutton jbtsave = jbutton baru ("保存"); private jlabel Jlbltitle = new jlabel ("主题"); Private JTextField Jtftitle = JTextField baru (16); ID string pribadi; Public Thread_KeepDiary (waktu string) {jpanel jptitle = jpanel baru (); jptitle.setLayout (borderlayout baru ()); jptitle.add (jlbltitle, borderlayout.west); jptitle.add (jtftitle, borderlayout.center); jta.setlinewrap (true); jta.setwrapstyleWord (true); Jscrollpane jsp = jscrollpane baru (jta); jsp.sethorizontalCrollBarpolicy (jscrollpane.horizontal_scrollbar_never); this.id = waktu; jbtsave.addactionListener (ActionListener baru () {@Override public void actionPerformed (actionEvent arg0) {// todo Metode yang dihasilkan secara otomatis tema string stub = jtftitle.getText (). trim (); string content = jta.gettext (); diary d_today = buku harian baru (id, konten); );}}}); 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
Kalenda paket; impor javax.swing.jlabel; Public Class Thread_mottosparkle mengimplementasikan runnable {private jlabel jlbl; thread public_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)); coba {thread.sleep (250); } catch (exception ex) {ex.printstacktrace (); } index ++; if (index == (l+1)) index = 0; }}}thread_scandiary.java
/*** 查看日记线程编写*/Paket kalenda; Impor java.awt.borderlayout; impor java.awt.color; impor java.awt.font; impor java.awt.event.actionevent; impor java.awt.event.actionlistener; impor java.io.file; impor java.awt.event.actionlistener; .FileInputStream; import java.io.objectInputStream; impor javax.swing.*; import javax.swing.table.defaulttableCellrenderer; import javax.swing.table.defaulttablemodel; import javax.swing.table.jtableHeader; Public Class Thread_Scandiary memperluas implement JFrame runnable { / ** * 声明变量区 * / private static final long serialVersionuid = 1l; // 日历数据库存放路径 Jalur string pribadi = "C:/Kalender/Diary"; // 日历总个数 NUM int statis pribadi; // 声明日历文件 file file pribadi; File pribadi [] buku harian; // 声明 jtable 模型 jtable pribadi; // 声明格言面板及标签及内容等 jpanel jpmotto pribadi = jpanel baru (); private jlabel Jlblmotto = new jlabel (); font pribadi = font baru ("宋体", font.italic, 20); Private String Wish = "唯有专注 , 才能让自己成功。"; // 增加弹出式菜单 2015-4-26 JPOPUPMENU JPOPUPMENU1 private private jpopupmenu baru (); // 声明菜单 JMenuitem Private JMiscan = JMenuitem baru ("查看"); private jMenuitem jmidelete = jMenuitem baru ("删除"); JMenuitem pribadi jmicomment = jMenuitem baru ("评论"); @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 = file baru (path); Buku harian = file.listFiles (); num = diary.length; String [] head = {"时间", "主题"}; Objek [] [] diary = objek baru [num] [2]; untuk (int i = 0; i <num; i ++) {coba {string time = diary [i] .getName (). ReplaceFirst (". Dat", ""); FileInputStream fis = new FileInputStream (Diary [i]); ObjectInputStream OIS = ObjectInputStream (FIS) baru; Buku harian d = (buku harian) ois.readObject (); ois.close (); Tema string = d.getTheme (); buku harian [i] [0] = waktu; buku harian [i] [1] = tema; } 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 = jtable baru (tablemodel); jtable.setBackground (color.white); Jtable.SetrowHeight (30); jtable.setDoublebuffered (false); jtable.setComponentPopupMenu (jpopupmenu1); jtable.setselectionMode (listSelectionModel.single_selection); DefaultTableCellRenderer TCR = New DefaultTableCellRenderer (); // 设置 Tabel 内容居中 tcr.sethorizontalAlignment (swingconstants.center); // 这句和上句作用一样 jtable.setDefaultrenderer (objek.class, tcr); Jscrollpane jsp = jscrollpane baru (jtable); /** * 弹出式菜单事件监听器编写 */// 查看菜单 jmiscan.addactionListener (ActionListener baru () {@Override public void actionPerformed (actionEvent e) {if (jtable.getSelectedRowR ()> = 0) {int index = Jtable.getSelectedRow (); OIS = ObjectInpenStream (FIS); "); JTextfield jtftitle = jtextfield baru (16); jpanel jptitle = jpanel baru (); jptitle.setlayout (borderlayout baru ()); jptitle.add (jlbltitle, borderlayout.west); jptitle.add (jlbltitle, borderlayout.west); jptitle.add (jlbltitle, borderlayout.west); jptitle.add (jtftitle, bordon, bordonut.west); jptitle.add (jlbltitle, borderout.west); jptitle.add (jtftitle, bordon, bordon-west.west); ); .getContent ()); 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.showmessagealog (null, "请先选中一个日记!"); }}}); // 删除菜单 jMidelete.addactionListener (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 = file baru (fileName); int option = joptionpane.showconfirmDialog (null," 你确定要删除日记 "+diary [index] .getName () +? "); else {}} else {joptionpane.showmessagealog (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); utas baru (thread_mottosparkle baru (jlblmotto)). start (); }}thread_showenglish.java
Kalenda paket; impor java.awt.color; impor java.awt.font; impor java.io.bufferedreader; impor java.io.filereader; impor java.io.linenumberreader; impor java.security.securerandom; impor java.util.random; impor javax.swing.jlabel; kelas publik thread_showenglish mengimplementasikan runnable {private static jlabel jlbl = new jlabel (); Font font = font baru ("��� ו, font.bold, 18); Public Thread_showenglish (jlabel jlbl) {this.jlbl = jlbl; jlbl.setForeground (color.magenta); jlbl.setfont (font); } @Override public void run () {// TODO METODE AUTO-AUTOLETED Stub int count = 0; coba {string file = "c: /calendar/learning/english_word.txt"; Input BufferedReader = BufferedReader baru (filereader baru (file)); while (input.readline ()! = null) {count ++; } input.close (); int [] word = int new [count]; Securerandom Random = SecureRandom baru (); untuk (int i = 0; i <count; i ++) {word [i] = random.nextInt (count); } int index = 0; Thread.sleep (1000); while (true) {bufferedReader input1 = new bufferedReader (filereader baru (file)); String content = ""; Int line = 0; while ((content = input1.readline ())! = null) {if (line == word [index]) {jlbl.setText (konten); } line ++; } if (index == count-1) index = 0; Lain indeks ++; Thread.sleep (3500); }} catch (exception ex) {ex.printstacktrace (); }}}以上所述就是本文的全部内容了 , 希望大家能够喜欢。