p align="left">Polekeys.curind=0; } //System.out.println(Polekeys.curind+" "+Polekeys.mindex); for(int j=0;j<Polekeys.length();j++){ if(polekey[j].index==Polekeys.curind){ doLclick(j); return; } } } if(e.getKeyCode()==KeyEvent.VK_LEFT | e.getKeyCode()==KeyEvent.VK_BACK_SPACE){ setKey(true); if(Polekeys.curind>0) { Polekeys.curind--; } else { Polekeys.curind=Polekeys.mindex; } //System.out.println(Polekeys.curind+" "+Polekeys.mindex); for(int j=0;j<Polekeys.length();j++){ if(polekey[j].index==Polekeys.curind){ doLclick(j); return; } } } } } }); } timer =new Timer(500, new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if(cursor) { cursor=false; } else { cursor=true; } pole.repaint(); } }); timer.stop(); return pole; } private void doLclick(int i){ Polekeys.cur=polekey[i].n; // System.out.println(polekey[i].n); //iskey=true; //button.setEnabled(false); rePaint(); } private void initPole(){ if(Main.words.isStarted()){ int in = 0; Polekeys.mindex=-1; boolean fi = true; Polekeys.c = Main.words.getCurword(); for(int i=0;i<Polekeys.length();i++){ polekey[i]=new Polekeys(); polekey[i].n=i; if(!Polekeys.getIndexchr(i).matches(question)){ polekey[i].is=false; } else { polekey[i].is=true; polekey[i].index=in; if(fi) { Polekeys.curind=in; fi=false; setKey(true); Polekeys.cur=i; } Polekeys.mindex++; in++; } } } } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.setPreferredSize(new Dimension(820, 40)); jPanel.setBackground(bg); jPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGH); jPanel.add(getButton(), gridBagConstraints); } return jPanel; } /** * This method initializes instructionMenuItem * * @return javax.swing.JMenuItem */ private JMenuItem getInstructionMenuItem() { if (instructionMenuItem == null) { instructionMenuItem = new JMenuItem(); instructionMenuItem.setText("Інструкція"); instructionMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { Main.showHelp(); } }); } return instructionMenuItem; } /** * Launches this application */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Test application = new Test(); application.getJFrame().setVisible(true); } }); } void setKey(boolean b){ iskey=b; if(b){ timer.start(); } else { timer.stop(); } pole.repaint(); } void doSumary(){ int g = 0; int b = 0; String word = ""; for(int i=0;i<Polekeys.length();i++){ if(polekey[i].is){ word=word+polekey[i].ch; if(polekey[i].ch.matches(Main.words.getOrigchr(i))){ g++; } b++; } else { word=word+Polekeys.getIndexchr(i); } } Main.words.setShots(g, b); Main.words.setDone(word); } } class Polekeys { static public int cur = -1; static public String c; static public int mindex = 0; static public int curind; public int x1; public int x2; public int n; public boolean is = false; public String ch = "?"; public int index = -1; public String getChr(){ return getIndexchr(n); } static public String getIndexchr(int i){ return c.substring(i,i+1); } static int length(){ int l; l=c.length(); if(l>Main.max_length) { l=Main.max_length; } return l; } } Лістинг Timer.java: package mahno.masha.smallenglish; class Timer extends Thread { final static int sec=1000; int ntimes = 0; int curtime = 0; int cur_test = -1; Timer(int c,int n){ ntimes = n; curtime = n; cur_test = c; setTime(); } public void run() { while(curtime>0 && Main.words.getCurent()==cur_test){ try { Thread.sleep(sec); Step(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(Main.words.getCurent()==cur_test) Done(); } void setTime(){ Main.words.setTime(curtime); } void Step() { curtime--; setTime(); Main.test.rePaint(); } void Done(){ Main.test.Click(); } } Лістинг Wave.java: package mahno.masha.smallenglish; import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.UnsupportedAudioFileException; public class Wave extends Thread { private String filename; private Position curPosition; private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb enum Position { LEFT, RIGHT, NORMAL }; public Wave(String wavfile) { filename = wavfile; curPosition = Position.NORMAL; } public Wave(String wavfile, Position p) { filename = wavfile; curPosition = p; } public void run() { File soundFile = new File(filename); if (!soundFile.exists()) { System.err.println("Wave file not found: " + filename); return; } AudioInputStream audioInputStream = null; try { audioInputStream = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); return; } catch (IOException e1) { e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); SourceDataLine auline = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); try { auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); } catch (LineUnavailableException e) { e.printStackTrace(); return; } catch (Exception e) { e.printStackTrace(); return; } if (auline.isControlSupported(FloatControl.Type.PAN)) { FloatControl pan = (FloatControl) auline .getControl(FloatControl.Type.PAN); if (curPosition == Position.RIGHT) pan.setValue(1.0f); else if (curPosition == Position.LEFT) pan.setValue(-1.0f); } auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { e.printStackTrace(); return; } finally { auline.drain(); auline.close(); } } } Лістинг Words.java: package mahno.masha.smallenglish; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Image; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.util.Date; import javax.imageio.ImageIO; class Words { final static int max = 100; final static String imgdir = "images/"; final static String snddir = "sounds/"; Timer timer; static int n = 0; static int orig; static int cur_test = -1; static String workdir; static String ldir; int all_clear = 0; int all = 0; String name; String ftxt; String[] word_rus = new String[max]; String[] word_orig = new String[max]; String[] word_test = new String[max]; String[] word_done = new String[max]; String[] image = new String[max]; String[] wav = new String[max]; int[] time = new int[max]; int[] clear_shots = new int[max]; int[] bad_shots = new int[max]; final static String defimg = "system/logo.jpg"; final static String defwav = "system/none.wav"; final static String lisimg = "system/listen.jpg"; boolean bwav=false; int cur_time; Image img; Image listen;
Страницы: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|