if((x1>x2)&&((x1-x2)>Math.abs(y2-y1))) { option=1;//移动的方向向左 System.out.println(\向左方向移动\ } if((x1
public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub do_label_keyPressed(e);// 调用处理方法 }
public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getActionCommand().equals(\ { if(jb1_flag2) { setJb1_flag(false); jb1_flag2=false; jb1.setIcon(new ImageIcon(\静音图标.jpg\ jb1.requestFocus(false);//让按钮失去焦点
24
} else { setJb1_flag(true); jb1_flag2=true; jb1.setIcon(new ImageIcon(\声音图标.jpg\ jb1.requestFocus(false);//让按钮失去焦点 } jb1.setFocusable(false);//设置焦点,不能用请求焦点 } } }
//记录类
class Recorder { //定义一个变量记录最高分 private static int maxscores_2048=0; public static int getMaxscores_2048() { return maxscores_2048; } public static void setMaxscores_2048(int maxscores_2048) { Recorder.maxscores_2048 = maxscores_2048; } //定义文件输入流变量 private static FileReader fr=null; private static BufferedReader br=null; private static FileWriter fw=null; private static BufferedWriter bw=null; //从文件中读取,记录 public static void getRecording() { boolean flag=false;//用于判断文件是否是新创建的 try { File f=new File(\ if(f.exists()) { fr=new FileReader(f); br=new BufferedReader(fr); String n=br.readLine(); maxscores_2048=Integer.parseInt(n); } else { flag=f.createNewFile();
25
} } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { try { //关闭文件流的顺序,先开的后关闭 if(!flag) { br.close(); fr.close(); } } catch (Exception e2) { // TODO: handle exception e2.printStackTrace(); } } }
//保存最高分纪录
public static void keepRecording() { //创建 try { File f=new File(\ fw=new FileWriter(f); bw=new BufferedWriter(fw); bw.write(maxscores_2048+\ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { //关闭流 try { bw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
26
} }
//播放声音的类
class AePlayWave extends Thread { private static String filename; public AePlayWave(String wavefile) { filename=wavefile; } public AePlayWave() {} public void run() { while(true) { File soundFile=new File(filename); AudioInputStream audioInputStream=null; try { audioInputStream=AudioSystem.getAudioInputStream(soundFile); } catch (Exception e) { // TODO: handle exception e.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(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ; } auline.start(); int nBytesRead=0; byte[]abData=new byte[1024]; try { while(nBytesRead!=-1) { nBytesRead=audioInputStream.read(abData); if(MyPanel.isJb1_flag())
27
{ if(nBytesRead>=0) }
}
}
{ auline.write(abData,0,nBytesRead); } } else { while(!MyPanel.isJb1_flag()); } }
} catch (Exception e) { // TODO: handle exception e.printStackTrace(); return ; }
finally { auline.drain(); auline.close(); }
28