【ACCESS精品源码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。
网学会员整理了ACCESS精品源码-java上机2参考代码 - 计算机等级的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
上机实践 2 输入输出流实验 1 学读汉字1.答案: :【代码 1】 new FileReaderfile :【代码 2】 new BufferedReaderinOne :【代码 3】 inTwo.readLine :【代码 4】 new FileReaderhelpFile :【代码 5】 new BufferedReaderinOne2.模板代码ChineseCharacters.java import java.io. import java.util.StringTokenizer public class ChineseCharacters public StringBuffer getChinesecharactersFile file StringBuffer hanzinew StringBuffer try FileReader inOne new FileReaderfile //创建指向文件 f 的 inOne 的对象 BufferedReader inTwo new BufferedReaderinOne //创建指向文件 inOne 的 inTwo 的 对象 String snull int i0 whiles inTwo.readLinenull //inTwo 读取一行 StringTokenizer tokenizernew StringTokenizers n whiletokenizer.hasMoreTokens hanzi.appendtokenizer.nextToken catchException e return hanzi StudyFrame.java import java.awt. import java.awt.event. import java.io. import javax.sound.sampled.public class StudyFrame extends Frame implements ItemListenerActionListenerRunnable ChineseCharacters chinese Choice choice Button getCharactersvoiceCharacters Label showCharacters StringBuffer trainedChinesenull Clip clipnull Thread voiceThread int k0 Panel pCenter CardLayout mycard TextArea textHelp MenuBar menubar Menu menu MenuItem help public StudyFrame chinesenew ChineseCharacters choicenew Choice choice.addtraining1.txt choice.addtraining2.txt choice.addtraining3.txt showCharactersnew LabelLabel.CENTER showCharacters.setFontnew Font宋体Font.BOLD72 showCharacters.setBackgroundColor.green getCharactersnew Button下一个汉字 voiceCharactersnew Button发音 voiceThreadnew Threadthis choice.addItemListenerthis voiceCharacters.addActionListenerthis getCharacters.addActionListenerthis Panel pNorthnew Panel pNorth.addnew Label选择一个汉字字符组成的文件 pNorth.addchoice addpNorthBorderLayout.NORTH Panel pSouthnew Panel pSouth.addgetCharacters pSouth.addvoiceCharacters addpSouthBorderLayout.SOUTH pCenternew Panel mycardnew CardLayout pCenter.setLayoutmycard textHelpnew TextArea pCenter.addhanzishowCharacters pCenter.addhelptextHelp addpCenterBorderLayout.CENTER menubarnew MenuBar menunew Menu帮助 helpnew MenuItem关于学汉字 help.addActionListenerthis menu.addhelp menubar.addmenu setMenuBarmenubar setSize350220 setVisibletrue addWindowListenernew WindowAdapter public void windowClosingWindowEvent e System.exit0 validatepublic void itemStateChangedItemEvent e String fileNamechoice.getSelectedItem File filenew FilefileName trainedChinesechinese.getChinesecharactersfile k0 mycard.showpCenterhanzi public void actionPerformedActionEvent e ife.getSourcegetCharacters iftrainedChinesenull char ctrainedChinese.charAtk k ifktrainedChinese.length k0 showCharacters.setTextc else showCharacters.setText请选择一个汉字字符文件 ife.getSourcevoiceCharacters ifvoiceThread.isAlive voiceThreadnew Threadthis try voiceThread.start catchException exp ife.getSourcehelp mycard.showpCenterhelp try File helpFilenew Filehelp.txt FileReader inOne new FileReaderhelpFile //创建指向文件 helpFile 的 inOne的对象 BufferedReader inTwo new BufferedReaderinOne //创建指向文件 inOne 的 inTwo的对象 String snull whilesinTwo.readLinenull textHelp.appendsn inOne.close inTwo.close catchIOException exp public void run voiceCharacters.setEnabledfalse try ifclipnull clip.close clipAudioSystem.getClip File voiceFilenew FileshowCharacters.getText.trim.wav clip.openAudioSystem.getAudioInputStreamvoiceFile catchException exp clip.start voiceCharacters.setEnabledtrue StudyMainClass.java public class StudyMainClass public static void mainString args new StudyFrame 实验 2 统计英文单词字1.答案: :【代码 1】 new RandomAccessFilefilerw :【代码 2】 new RandomAccessFilefilerw :【代码 3】 inOne.read :【代码 4】 inTwo.seekwordStarPostion :【代码 5】 inTwo.readFullycc2.模板代码WordStatistic.java import java.io. import java.util.Vector public class WordStatistic Vector allWorsdnoSameWord WordStatistic allWorsdnew Vector noSameWordnew Vector public void wordStatisticFile file try RandomAccessFile inOne new RandomAccessFilefilerw //创建指向文 件 file 的 inOne 的对象 RandomAccessFile inTwo new RandomAccessFilefilerw //创建指向文 件 file 的 inTwo 的对象 long wordStarPostion0wordEndPostion0 long lengthinOne.length int flag1 int c-1 forint k0k
上一篇:
【精品文档】浅析网站数据库的安全防范及对策计算机网络论文工学论文_8942
下一篇:
村落共同体的核心架构研究