网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  一个java写的背单词程序     
  文章作者:未知  文章来源:水木森林  
  查看:119次  录入:管理员--2007-11-17  
 
  俺看了一些java, 写个程序出来玩玩。由于界面是用jbuilder生成的,可能代码比较乱,而且还没合起来。 目前版本是0.00001 /* * word.java * * created on 2004-9-26 * */ package com.henry.vocabulary; import java.util.*; import java.text.*; public class word { private static final simpledateformat format = new simpledateformat( "yyyy-m-dd hh:mm:ss"); private static final int[] memorycurve = { 1, 2, 4, 8, 12, 20, 36, 54, 87, 160, 360 }; // every "tomorrow" starts from 5am, not from middle night. private static final int houradjust = -5; static calendar today = calendar.getinstance(); { today.add(calendar.hour, houradjust); today.set(calendar.hour,12); today.set(calendar.minute,0); today.set(calendar.second,0); } private string _wordvalue; date _nextreviewtime; int _reviewtimes; int _forgettimes; /** * @param _wordvalue the _wordvalue to set. */ public void setwordvalue(string _wordvalue) { this._wordvalue = _wordvalue; } /** * @return returns the _wordvalue. */ public string getwordvalue() { return _wordvalue; } public word(string wordvalue, string nextreviewtime, int reviewtimes, int forgettimes) { try { setwordvalue(wordvalue); _nextreviewtime = format.parse(nextreviewtime); _reviewtimes = reviewtimes; _forgettimes = forgettimes; } catch (parseexception pe) { system.out.println("the input is not a date!"); throw new runtimeexception(pe); } } public word(string strword) { try { string[] values = strword.split(","); setwordvalue(values[0]); _nextreviewtime = format.parse(values[1]); _reviewtimes = integer.parseint(values[2].trim()); if(values.length == 4) { // for compatible to the old version _forgettimes = integer.parseint(values[3]); } else { _forgettimes = 0; } } catch (parseexception pe) { system.out.println("the input is not a date!"); throw new runtimeexception(pe); } } public void forget() { _nextreviewtime = today.gettime(); _reviewtimes = 0; _forgettimes++; } public void remember() { calendar nexttime = (calendar) today.clone(); nexttime.add(calendar.date, memorycurve[_reviewtimes]); _nextreviewtime = nexttime.gettime(); _reviewtimes++; } public string tostring() { final simpledateformat format2 = new simpledateformat( "yyyy-m-dd hh:mm:ss"); string s = getwordvalue() + "," + format2.format(_nextreviewtime) + "," + _reviewtimes + "," + _forgettimes; return s; } /** * judge if this word need to be reviewed today. * comment for isneedreview */ public boolean isneedreview() { if(this._nextreviewtime.after(today.gettime())) { return false; } return true; } public static void main(string[] args) { word w = new word("test", "2004-8-30", 2, 3); word w1 = new word("test,2004-8-30,2,3"); system.out.println(w); w.remember(); system.out.println(w); w.forget(); system.out.println(w); system.out.println(w1); w1.remember(); system.out.println(w1); w1.forget(); system.out.println(w1); } } /* * wordsreview.java * * created on 2004-9-26 * */ package com.henry.vocabulary; import java.util.*; import java.io.*; /** * @author henry * */ public class wordsreview { list wordlist = new arraylist(); list wordneedreviewlist = new arraylist(); word currentword; /** * @param filename */ public void readfromfile(string filename){ try{ stringbuffer sb = new stringbuffer(); bufferedreader br = new bufferedreader(new filereader(filename)); string s; while ((s = br.readline()) != null) { this.currentword = new word(s); this.wordlist.add(this.currentword); if(this.currentword.isneedreview()){ this.wordneedreviewlist.add(this.currentword); } } this.currentword = null; } catch (filenotfoundexception e) { system.out.println(e); system.out.println(e.getstacktrace()); } catch (ioexception ioe) { system.out.println(ioe); system.out.println(ioe.getstacktrace()); } } /** * @param filename */ public void savetofile(string filename){ } /** * get a word, which needs to be reviewed. * @return */ public string getword(){ if(this.wordneedreviewlist.isempty()){ return null; } random random = new random(); int ramdonindex = random.nextint() % this.wordneedreviewlist.size(); currentword = (word)this.wordneedreviewlist.get(ramdonindex); return currentword.getwordvalue(); } public void saveword(boolean isforget){ if(this.currentword == null){ system.out.println("should not come here!"); system.out.println("when you call saveword to save the word, "); system.out.println(" you should get the word first."); return; } if(isforget) { this.currentword.forget(); } else { this.currentword.remember(); this.wordneedreviewlist.remove(currentword); } } public static void main(string[] args) { wordsreview wr = new wordsreview(); wr.readfromfile("henrypan.txt"); string s = wr.getword(); wr.saveword(false); } } // mainframe.java package app2; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** *
title:

*
description:

*
copyright: copyright (c) 2004

*
company:

* @author henry * @version 1.0 */ public class mainframe extends jframe { jpanel contentpane; gridbaglayout gridbaglayout1 = new gridbaglayout(); jtextfield word = new jtextfield(); jradiobutton remember = new jradiobutton(); jradiobutton forget = new jradiobutton(); jbutton next = new jbutton(); buttongroup buttongroup1 = new buttongroup(); //construct the frame public mainframe() { enableevents(awtevent.window_event_mask); try { jbinit(); } catch(exception e) { e.printstacktrace(); } } //component initialization private void jbinit() throws exception { contentpane = (jpanel) this.getcontentpane(); word.setfont(new java.awt.font("dialog", 0, 16)); word.setselectionstart(0); word.settext(""); contentpane.setlayout(gridbaglayout1); this.setsize(new dimension(560, 463)); this.settitle("tafu vocabulary"); remember.setfont(new java.awt.font("dialog", 0, 16)); remember.settext("i remember it well."); forget.setfont(new java.awt.font("dialog", 0, 16)); forget.setselected(true); forget.settext("i forget it."); next.setfont(new java.awt.font("dialog", 0, 16)); next.settext("next"); next.addactionlistener(new frame1_next_actionadapter(this)); contentpane.add(word, new gridbagconstraints(0, 0, 2, 1, 0.0, 0.0 ,gridbagconstraints.center, gridbagconstraints.none, new insets(17, 9, 0, 31), 494, 39)); contentpane.add(remember, new gridbagconstraints(0, 1, 1, 1, 0.0, 0.0 ,gridbagconstraints.southwest, gridbagconstraints.none, new insets(26, 0, 1, 0), 0, 0)); contentpane.add(forget, new gridbagconstraints(1, 1, 1, 2, 0.0, 0.0 ,gridbagconstraints.southwest, gridbagconstraints.none, new insets(25, 0, 37, 0), 0, 0)); contentpane.add(next, new gridbagconstraints(1, 3, 1, 1, 0.0, 0.0 ,gridbagconstraints.center, gridbagconstraints.none, new insets(0, 9, 59, 13), 44, 11)); buttongroup1.add(forget); buttongroup1.add(remember); } //overridden so we can exit when window is closed protected void processwindowevent(windowevent e) { super.processwindowevent(e); if (e.getid() == windowevent.window_closing) { system.exit(0); } } void next_actionperformed(actionevent e) { system.out.println("next action perform!"); if(this.forget.isselected()){ } } } class frame1_next_actionadapter implements java.awt.event.actionlistener { mainframe adaptee; frame1_next_actionadapter(mainframe adaptee) { this.adaptee = adaptee; } public void actionperformed(actionevent e) { adaptee.next_actionperformed(e); } } // mainwin.java package app2; import javax.swing.uimanager; import java.awt.*; /** *
title:

*
description:

*
copyright: copyright (c) 2004

*
company:

* @author not attributable * @version 1.0 */ public class mainwin { boolean packframe = false; //construct the application p
 
 
上一篇: 一个javabean轻松实现对数据库的各种操作    下一篇: 一个操作数据库的java bean……
  相关文档
如何在tomcat配置web在线后台管理 11-17
j2se综合:java语言关于字符串替换的思考 01-29
在java中利用jcom实现仿excel编程详解 11-16
java本地接口工作方式初探 11-20
jsq(sql测试工具) 11-17
让java说话-用java实现语音引擎 11-16
[webservices]xfire web服务的单元测试 11-17
初学者如何开发出一个高质量的j2ee系统 03-06
如何在java中消除实现继承和面向接口编程 03-18
第一次接触ejb 11-17
实例解析:php程序开发中的中文编码问题 06-30
如何用jdo开发数据库应用(11) 11-17
java 2 新的焦点子系统 11-17
在eclipse中使用ant来自动编译j2me程序 11-17
j2me综合--j2me应用程序内存优化三招 02-27
writeblanklines 方法 11-16
java无线开发教程之一 11-16
按位“非”运算符 (~) 11-16
j2se综合--关于字符串的一些处理技巧 03-03
理解jtwi的具体内容和作用 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息