论坛首页 Java企业应用论坛

日语学习小工具(GUI版)(二)

浏览 3934 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-12-23  

RandomWord.java

package com.gary.util.japanese;

import java.util.Random;
/**
 * 随机,帮助记忆五十音图
 * @author gary
 *
 */
public class RandomWord {
	
	/**
	 * 随机平假名
	 * @return
	 */
	public static String randomHiranagana(){
		String word = null;
		try{
			word = JapaneseUtil.hiranagana_words[new Random().nextInt(12)][new Random().nextInt(6)];
			if(JapaneseUtil.emptyStr.equals(word)){
				word = randomHiranagana();
			}
		}catch(ArrayIndexOutOfBoundsException e){
			word = randomHiranagana();
		}
		return word;
	}
	
	
	/**
	 * 随机片假名
	 * @return
	 */
	public static String randomKatakana(){
		String word = null;
		try{
			word = JapaneseUtil.katakana_words[new Random().nextInt(12)][new Random().nextInt(6)];
			if(JapaneseUtil.emptyStr.equals(word)){
				word = randomKatakana();
			}
		}catch(ArrayIndexOutOfBoundsException e){
			word = randomKatakana();
		}
		return word;
	}

	/**
	 * 随机罗马音
	 * @return
	 */
	public static String randomSound(){
		String sound = null;
		try{
			sound = JapaneseUtil.sounds[new Random().nextInt(12)][new Random().nextInt(6)];
			if(JapaneseUtil.emptyStr.equals(sound)){
				sound = randomSound();
			}
		}catch(ArrayIndexOutOfBoundsException e){
			sound = randomSound();
		}
		return sound;
	}
	
	/**
	 * 随机平假名+片假名
	 * @return
	 */
	public static String randomAllWords(){
		int switchWords = new Random().nextInt(2);
		if(switchWords == 0){
			return randomHiranagana();
		}else{
			return randomKatakana();
		}
	}

	/**
	 * 随机全部
	 * @return
	 */
	public static String randomAll(){
		int flag = new Random().nextInt(3);
		if(flag == 0){
			return randomHiranagana();
		}else if(flag == 1){
			return randomKatakana();
		}else{
			return randomSound();
		}
	}
}

 RandomWords.java

package com.gary.util.japanese;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.gary.util.jxl.JXLUtil;
/**
 * 背单词辅助工具
 * @author gary
 *
 */
public class RandomWords {
	private static List<Map<String,String>> data;
	public static Random random;
	
	static{
		data = new JXLUtil().getImportData(new File("words.xls"), "japanese");
		random = new Random();
	}
	
	/**
	 * 随机取出日语
	 * @return
	 */
	public static String randomJapanese(){
		return ((Map<String,String>)data.get(random.nextInt(data.size()))).get("japanese");
	}
	
	/**
	 * 随机取出汉语
	 * @return
	 */
	public static String randomChinese(){
		return ((Map<String,String>)data.get(random.nextInt(data.size()))).get("chinese");
	}
	/**
	 * 随机取出单词
	 * @return
	 */
	public static String randomAll(){
		int flag = random.nextInt(2);
		if(flag == 0){
			return randomJapanese();
		}else{
			return randomChinese();
		}
	}
}

 JXLUtil.java

package com.gary.util.jxl;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jxl.Sheet;
import jxl.Workbook;
/**
 * 读取Excel
 * @author gary
 *
 */
public class JXLUtil {
	public List<Map<String,String>> getImportData(File file, String target){
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		try {
			Workbook book = Workbook.getWorkbook(file);
			Sheet sheet = book.getSheet(0);
			int rows = sheet.getRows();
			int columns = sheet.getColumns();
			boolean hasText = false;
			for (int i = 0; i < rows; i++) {
				for (int j = 0; j < columns; j++)
					if (sheet.getCell(j, i).getContents() != "") {
						hasText = true;
						break;
					}
				if (hasText) {
					Map<String, String> temp = new HashMap<String, String>();
					String excelKey = "japanese,chinese";
					String[] excelKeyArray = excelKey.split(",");
					for(int k = 0 ; k < excelKeyArray.length ; k++){
						temp.put(excelKeyArray[k], sheet.getCell(k, i).getContents());
					}
					data.add(temp);
				}
			}
			book.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}
}

 

 

 

 

   发表时间:2010-12-23  
日语学习小工具(GUI版)(一)
包含源码+exe版程序,地址:
http://gary0416.iteye.com/blog/850667
0 请登录后投票
   发表时间:2010-12-24  
看起来不错,没仔细看代码。有时间再看吧。
0 请登录后投票
   发表时间:2010-12-25  
用什么生成的EXE文件哈?
0 请登录后投票
   发表时间:2010-12-25  
liuyes 写道
用什么生成的EXE文件哈?


同求
0 请登录后投票
   发表时间:2010-12-25  
jar生成exe工具:exe4j
0 请登录后投票
   发表时间:2010-12-26  
学日语的朋友应该不多吧,呵呵
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics