欢迎来到天天文库
浏览记录
ID:41037227
大小:95.00 KB
页数:9页
时间:2019-08-14
《Java实验项目四 Java高级编程 第1部分》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Java实验项目四Java高级编程第1部分输入输出流1学读汉字ChineseCharacters.javaimportjava.io.*;importjava.util.StringTokenizer;publicclassChineseCharacters{publicStringBuffergetChinesecharacters(Filefile){StringBufferhanzi=newStringBuffer();try{FileReaderinOne=【代码1】//创建指向文件f的inOne
2、的对象BufferedReaderinTwo=【代码2】//创建指向文件inOne的inTwo的对象Strings=null;inti=0;while((s=【代码3】)!=null)//inTwo读取一行{StringTokenizertokenizer=newStringTokenizer(s,",''");while(tokenizer.hasMoreTokens()){hanzi.append(tokenizer.nextToken());}}}catch(Exceptione){}retur
3、nhanzi;}}StudyFrame.javaimportjava.awt.*;importjava.awt.event.*;importjava.io.*;importjavax.sound.sampled.*;publicclassStudyFrameextendsFrameimplementsItemListener,ActionListener,Runnable{ChineseCharacterschinese;Choicechoice;ButtongetCharacters,voiceChar
4、acters;LabelshowCharacters;StringBuffertrainedChinese=null;Clipclip=null;ThreadvoiceThread;intk=0;PanelpCenter;CardLayoutmycard;TextAreatextHelp;MenuBarmenubar;Menumenu;MenuItemhelp;publicStudyFrame(){chinese=newChineseCharacters();choice=newChoice();choi
5、ce.add("training1.txt");choice.add("training2.txt");choice.add("training3.txt");showCharacters=newLabel("",Label.CENTER);showCharacters.setFont(newFont("宋体",Font.BOLD,72));showCharacters.setBackground(Color.green);getCharacters=newButton("下一个汉字");voiceCha
6、racters=newButton("发音");voiceThread=newThread(this);choice.addItemListener(this);voiceCharacters.addActionListener(this);getCharacters.addActionListener(this);PanelpNorth=newPanel();pNorth.add(newLabel("选择一个汉字字符组成的文件"));pNorth.add(choice);add(pNorth,Borde
7、rLayout.NORTH);PanelpSouth=newPanel();pSouth.add(getCharacters);pSouth.add(voiceCharacters);add(pSouth,BorderLayout.SOUTH);pCenter=newPanel();mycard=newCardLayout();pCenter.setLayout(mycard);textHelp=newTextArea();pCenter.add("hanzi",showCharacters);pCent
8、er.add("help",textHelp);add(pCenter,BorderLayout.CENTER);menubar=newMenuBar();menu=newMenu("帮助");help=newMenuItem("关于学汉字");help.addActionListener(this);menu.add(help);menubar.add(menu);setMenuBar(menubar);setSize(35
此文档下载收益归作者所有