📄 main.java
字号:
/* * StudentMainClass.java * * Created on 2008年5月12日, 上午10:42 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package 输入输出;import java.io.*;import java.awt.*;import java.awt.event.*;import java.util.StringTokenizer;import javax.sound.sampled.*;/** * * @author Administrator */public class Main{ /** Creates a new instance of StudentMainClass */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { new StudyFrame(); // TODO code application logic here } }class Chinese { public StringBuffer getChinesecharacters(File file) { StringBuffer hanzi=new StringBuffer(); try{ FileReader inOne=new FileReader(file);////////// BufferedReader inTow=new BufferedReader(inOne);///////// String s=null; int i=0; while((s=inTow.readLine())!=null)///////// { StringTokenizer tokenizer=new StringTokenizer(s,",'\n'"); while(tokenizer.hasMoreTokens()) { hanzi.append(tokenizer.nextToken()); } } } catch(Exception e){} return hanzi; }}class StudyFrame extends Frame implements ItemListener,ActionListener,Runnable { Chinese chinese; Choice choice; Button getCharacters,getPre,voiceCharacters;//.................. Label showCharacters; StringBuffer trainedChinese=null; Clip clip=null; Thread voiceThread; int k=1,b=0,n=0,a=0; boolean t_n=false,t_b=false,t_c=true,t_d=true; Panel pCenter; CardLayout mycard; TextArea textHelp; MenuBar menubar; Menu menu; MenuItem help; public StudyFrame() { chinese=new Chinese(); choice = new Choice(); choice.add("E:\\a.txt"); choice.add("E:\\b.txt"); choice.add("E:\\c.txt"); showCharacters=new Label("",Label.CENTER); showCharacters.setFont(new Font("宋体",Font.BOLD,72)); showCharacters.setBackground(Color.green); getPre=new Button("上一个汉字");//............. getCharacters=new Button("下一个汉字"); voiceCharacters=new Button("发音"); voiceThread=new Thread(this); choice.addItemListener(this); voiceCharacters.addActionListener(this); getPre.addActionListener(this);//................ getCharacters.addActionListener(this); Panel pNorth=new Panel(); pNorth.add(new Label("选择一个汉字字符组成的文件")); pNorth.add(choice); add(pNorth,BorderLayout.NORTH); Panel pSouth=new Panel(); pSouth.add(getPre);//............ pSouth.add(getCharacters ); pSouth.add(voiceCharacters ); add(pSouth,BorderLayout.SOUTH); pCenter=new Panel(); mycard=new CardLayout(); pCenter.setLayout(mycard); textHelp=new TextArea(); pCenter.add("hanzi",showCharacters); pCenter.add("help",textHelp); add(pCenter,BorderLayout.CENTER); menubar=new MenuBar(); menu=new Menu("帮助"); help=new MenuItem("关于学汉字"); help.addActionListener(this); menu.add(help); menubar.add(menu); setMenuBar(menubar); setSize(350,220); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); validate(); } public void itemStateChanged(ItemEvent e) { String fileName=choice.getSelectedItem(); File file=new File(fileName); trainedChinese=chinese.getChinesecharacters(file); k=1;b=trainedChinese.length(); mycard.show(pCenter,"hanzi"); } public void actionPerformed(ActionEvent e) { if(e.getSource()==getCharacters) { if(trainedChinese!=null) { if(t_c){ char c=trainedChinese.charAt(k-1); k++; if(k>trainedChinese.length()) k=1; n=k-2; showCharacters.setText(""+c); } else if(t_n){ char c=trainedChinese.charAt(a); a++; if(a>=trainedChinese.length()) a=0; n=a-2; showCharacters.setText(""+c); } } else { showCharacters.setText("请选择一个汉字字符文件"); } } else if(e.getSource()==getPre) { if(trainedChinese!=null) { t_c=false; if(n>0){ char c=trainedChinese.charAt(n-1); n--; if(n<1) n=trainedChinese.length(); showCharacters.setText(""+c); a=n+2; t_n=true; } else{ char c=trainedChinese.charAt(b-1); b--; if(b<=0) b=trainedChinese.length(); showCharacters.setText(""+c); t_b=true; } } else { showCharacters.setText("请选择一个汉字字符文件"); } } else if(e.getSource()==voiceCharacters) { if(!(voiceThread.isAlive())) { voiceThread=new Thread(this); } try{ voiceThread.start(); } catch(Exception exp){} } if(e.getSource()==help) { mycard.show(pCenter,"help"); try{ File helpFile=new File("E:\\help.txt"); FileReader inOne=new FileReader(helpFile); BufferedReader inTow=new BufferedReader(inOne); String s=null; while((s=inTow.readLine())!=null) { textHelp.append(s+"\n"); } inOne.close(); inTow.close(); } catch(IOException exp){} } } public void run() { voiceCharacters.setEnabled(false); try{ if(clip!=null) { clip.close(); } clip=AudioSystem.getClip(); File voiceFile=new File(showCharacters.getText().trim()+",wav"); clip.open(AudioSystem.getAudioInputStream(voiceFile)); } catch(Exception exp){} clip.start(); voiceCharacters.setEnabled(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -