www.pudn.com > newminesrc.zip > MainFrame.java, change:2002-07-10,size:34092b


//package mine; 
import javax.swing.JFrame; 
import java.awt.BorderLayout; 
import javax.swing.JPanel; 
import javax.swing.JLabel; 
import javax.swing.ImageIcon; 
import javax.swing.JButton; 
import javax.swing.JToolBar; 
import javax.swing.JMenu; 
import javax.swing.JMenuBar; 
import javax.swing.JMenuItem; 
import java.awt.Dimension; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JOptionPane; 
import java.awt.Rectangle; 
import java.awt.Insets; 
import javax.swing.*; 
import java.awt.event.MouseListener; 
import java.awt.event.MouseEvent; 
import java.util.*; 
import java.awt.Color; 
import javax.swing.BorderFactory; 
import javax.swing.border.EtchedBorder; 
import java.awt.Font; 
import java.io.*; 
import java.awt.Toolkit; 
 
public class MainFrame extends JFrame  
{ 
  TimeThread theTimeThread; 
  boolean isRestart = false; 
  int sumOfMine=0; 
  int sumOfNotMine=0; 
  String level = ""; 
  String curRecord = ""; 
  int sumOfButton = 0; 
  ImageIcon imageMineNotFound = new ImageIcon(MainFrame.class.getResource("mine.gif")); 
//  ImageIcon imageClose = new ImageIcon(MainFrame.class.getResource("closefile.gif")); 
//  ImageIcon imageOpen = new ImageIcon(MainFrame.class.getResource("openfile.gif")); 
  ImageIcon imageCurv = new ImageIcon(MainFrame.class.getResource("goldcurv.gif")); 
  ImageIcon imageMine = new ImageIcon(MainFrame.class.getResource("isMine.gif")); 
  ImageIcon imageNotSure = new ImageIcon(MainFrame.class.getResource("notsure.gif")); 
  ImageIcon imageNew = new ImageIcon(MainFrame.class.getResource("new.gif")); 
  ImageIcon imageRecieve = new ImageIcon(MainFrame.class.getResource("recieve.gif"));   
  ImageIcon imageWinner = new ImageIcon(MainFrame.class.getResource("winner.gif"));   
  ImageIcon imageErrMine = new ImageIcon(MainFrame.class.getResource("errmine.gif"));   
  ImageIcon imageBoom = new ImageIcon(MainFrame.class.getResource("boom.gif"));     
  JButton buttonOpen = new JButton(); 
  JToolBar toolBar = new JToolBar(); 
  JLabel statusBar = new JLabel(); 
  JMenuItem menuHelpAbout = new JMenuItem(); 
  JMenu menuHelp = new JMenu(); 
  JMenuItem menuFileExit = new JMenuItem(); 
  JMenu menuFile = new JMenu(); 
  JMenuBar menuBar1 = new JMenuBar(); 
  static  JPanel jPanel1 = new JPanel(); 
  BorderLayout borderLayout1 = new BorderLayout(); 
//  JButton jButton1 = new JButton(); 
  JMenuItem jMenuItem1 = new JMenuItem(); 
  MyButton mineButton[][] = new MyButton[20][20]; 
  JLabel jLabelTest[][] = new JLabel[20][20]; 
  JLabel jLabelTime = new JLabel(); 
  JLabel jLabelMineNum = new JLabel(); 
  JLabel jLabel1 = new JLabel(); 
  JLabel jLabelTestImage = new JLabel(); 
  JMenuItem jMenuPrime = new JMenuItem(); 
  JMenuItem jMenuMiddle = new JMenuItem(); 
  JMenuItem jMenuHigh = new JMenuItem(); 
  JLabel jLabel2 = new JLabel(); 
  RandomAccessFile accessFile; 
  JMenuItem jMenuItem2 = new JMenuItem(); 
 
///////////////////////////////////////////////////////////////////////* 
 
  public MainFrame() 
  { 
     
    theTimeThread = new TimeThread(this); 
    File infoFile = new File("D:\\info.dat"); 
    boolean tempFlag = false; 
    try 
    { 
      tempFlag = infoFile.createNewFile(); 
       
    } 
    catch(IOException ioe) 
    { 
      JOptionPane.showMessageDialog(null,"IOException occurred : "+ ioe); 
    } 
    if(tempFlag) 
    { 
      try 
      { 
        RandomAccessFile newFile = new RandomAccessFile(infoFile,"rw"); 
        newFile.writeBytes("[level]\n"); 
        newFile.writeBytes("primer\n"); 
        newFile.writeBytes("[primer]\n"); 
        newFile.writeBytes("anonymity           \n"); 
        newFile.writeBytes("9999\n"); 
        newFile.writeBytes("[middle]\n"); 
        newFile.writeBytes("anonymity           \n"); 
        newFile.writeBytes("9999\n"); 
        newFile.writeBytes("[high]\n"); 
        newFile.writeBytes("anonymity           \n"); 
        newFile.writeBytes("9999\n"); 
        newFile.close(); 
      } 
      catch(Exception ex) 
      { 
        JOptionPane.showMessageDialog(null,"Exception occurred here: "+ex); 
      } 
    } 
     
    try 
    { 
      accessFile = new RandomAccessFile(infoFile,"rw"); 
      accessFile.readLine(); 
      this.level = accessFile.readLine(); 
      if(level.startsWith("primer")) 
      { 
        this.sumOfButton = 10; 
        this.sumOfMine = 10; 
        this.sumOfNotMine = 90; 
        accessFile.readLine(); 
        accessFile.readLine(); 
      } 
      else 
        if(level.startsWith("middle")) 
        { 
          this.sumOfButton = 15; 
          this.sumOfMine = 40; 
          this.sumOfNotMine = 185; 
          accessFile.readLine(); 
          accessFile.readLine(); 
          accessFile.readLine(); 
          accessFile.readLine(); 
          accessFile.readLine(); 
        } 
        else 
          if(level.startsWith("high")) 
          { 
            this.sumOfButton = 20; 
            this.sumOfMine = 99; 
            this.sumOfNotMine = 301;  
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
            accessFile.readLine(); 
          } 
      this.curRecord = accessFile.readLine(); 
      curRecord = curRecord.trim(); 
    } 
     
    catch(Exception e) 
    { 
      JOptionPane.showMessageDialog(null,"IOException occurred here: " + e); 
    } 
     
     
    try 
    { 
      jbInit(); 
    } 
    catch(Exception e) 
    { 
      e.printStackTrace(); 
    } 
 
  } 
 
  private void jbInit() throws Exception 
  { 
    this.setJMenuBar(menuBar1); 
    this.getContentPane().setLayout(borderLayout1); 
    jPanel1.setLayout(null); 
    jPanel1.setForeground(new Color(11, 41, 121)); 
 
//    jButton1.setBounds(new Rectangle(0, 0, 16, 16)); 
//    jButton1.setMargin(new Insets(10, 10, 10, 10)); 
//    jButton1.setActionCommand("jButton00"); 
    jMenuItem1.setText("New"); 
    jMenuItem1.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onNew(e); 
        } 
      }); 
    jLabelTime.setBackground(new Color(63, 109, 160)); 
    jLabelTime.setForeground(new Color(61, 65, 155)); 
    jLabelTime.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 
    jLabelTime.setFont(new Font("华文中宋", 1, 14)); 
    jLabelTime.setToolTipText("time used"); 
    jLabelTime.setText("0000"); 
    jLabelTime.setBounds(new Rectangle(199, 3, 44, 26)); 
    jLabelMineNum.setText("0000"); 
    jLabelMineNum.setBackground(new Color(63, 109, 160)); 
    jLabelMineNum.setForeground(new Color(61, 65, 155)); 
    jLabelMineNum.setFont(new Font("华文中宋", 1, 14)); 
    jLabelMineNum.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 
    jLabelTestImage.setBounds(new Rectangle(45, 0, 55, 60)); 
    jLabelTestImage.setIcon(imageRecieve); 
    jLabelTestImage.setBackground(new Color(63, 109, 160)); 
    jLabelTestImage.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 
    jLabelTestImage.setToolTipText("freesoso@sina.com.cn"); 
    jMenuPrime.setText("初级"); 
    jMenuPrime.setFont(new Font("仿宋_GB2312", 0, 12)); 
    jMenuPrime.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onPrimer(e); 
        } 
      }); 
    jMenuMiddle.setText("中级"); 
    jMenuMiddle.setFont(new Font("仿宋_GB2312", 0, 12)); 
    jMenuMiddle.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onMiddle(e); 
        } 
      }); 
    jMenuHigh.setText("高级"); 
    jMenuHigh.setFont(new Font("仿宋_GB2312", 0, 12)); 
    jMenuHigh.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onHigh(e); 
        } 
      }); 
    jMenuItem2.setText("英雄榜"); 
    jMenuItem2.setFont(new Font("仿宋_GB2312", 0, 12)); 
    jMenuItem2.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onList(e); 
        } 
      }); 
 
 
//    this.setSize(new Dimension(1000,1000)); 
    this.setSize(new Dimension(145, 140)); 
    this.jLabel1.setText("  "); 
    this.jLabel2.setText("  "); 
    this.setTitle("MyMinetest"); 
    this.setResizable(false); 
    menuFile.setText("File"); 
    menuFileExit.setText("Exit"); 
    menuFileExit.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent ae) 
        { 
          fileExit_ActionPerformed(ae); 
        } 
      }); 
    menuHelp.setText("Help"); 
    menuHelpAbout.setText("About"); 
    menuHelpAbout.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent ae) 
        { 
          helpAbout_ActionPerformed(ae); 
        } 
      }); 
    statusBar.setText(""); 
    buttonOpen.setToolTipText("New Another Game"); 
    buttonOpen.setIcon(imageNew); 
    buttonOpen.addActionListener(new ActionListener() 
      { 
        public void actionPerformed(ActionEvent e) 
        { 
          onButtonOpen(e); 
        } 
      }); 
    toolBar.setMinimumSize(new Dimension(43, 31)); 
    toolBar.setMaximumSize(new Dimension(350, 31)); 
    menuFile.add(jMenuItem1); 
    menuFile.add(jMenuPrime); 
    menuFile.add(jMenuMiddle); 
    menuFile.add(jMenuHigh); 
    menuFile.add(jMenuItem2); 
    menuFile.add(menuFileExit); 
    menuBar1.add(menuFile); 
    menuHelp.add(menuHelpAbout); 
    menuBar1.add(menuHelp); 
    this.getContentPane().add(statusBar, BorderLayout.WEST); 
    toolBar.add(jLabelMineNum, null); 
    toolBar.add(jLabel2, null); 
    toolBar.add(buttonOpen); 
    toolBar.add(jLabel1, null); 
    toolBar.add(jLabelTime, null); 
 
    this.getContentPane().add(toolBar, BorderLayout.NORTH); 
//    jPanel1.add(jButton1, null); 
 
    jPanel1.add(jLabelTestImage, null); 
    this.getContentPane().add(jPanel1, BorderLayout.CENTER); 
     
     
  } 
 
  void fileExit_ActionPerformed(ActionEvent e) 
  { 
    System.exit(0); 
  } 
 
  void helpAbout_ActionPerformed(ActionEvent e) 
  { 
    JOptionPane.setDefaultLocale(Locale.CHINESE); 
    JOptionPane.showMessageDialog(this, new MainFrame_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE); 
  } 
 
  void onNew(ActionEvent e) 
  {  
//    this.remove(jPanel1); 
    buttonOpen.setIcon(imageNew); 
    if(isRestart) 
    { 
      isRestart = false; 
      try 
      { 
        theTimeThread.join(); 
      } 
      catch(InterruptedException ex) 
      { 
        JOptionPane.showMessageDialog(null,"InterruptedException occurred here: " + ex); 
      } 
    } 
    jPanel1.removeAll(); 
//    jPanel1.add(jLabelTestImage,null); 
 
    for(int i = 0;i < this.sumOfButton;i ++) 
      for(int j = 0;j < this.sumOfButton;j ++) 
      { 
        mineButton[i][j] = new MyButton(); 
        mineButton[i][j].setBounds(new Rectangle(j*16,i*16,16,16)); 
        jPanel1.add(mineButton[i][j],null); 
//        mineButton[i][j].addActionListener(new ClickButton(this,i,j)); 
        mineButton[i][j].addMouseListener(new ClickButton(this,i,j)); 
         
        jLabelTest[i][j] = new JLabel(); 
        jLabelTest[i][j].addMouseListener(new ClickLabel(this,i,j)); 
        jLabelTest[i][j].setBackground(new Color(63,109,160)); 
        jLabelTest[i][j].setForeground(new Color(61,65,155)); 
   //     testlabel.setFont(new Font("华文中宋",1,12)); 
        jLabelTest[i][j].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 
        jLabelTest[i][j].setBounds(j*16,i*16,16,16); 
        
     
       
      } 
    this.setSize(1000,1000);      
    if(level.startsWith("primer")) 
    { 
 
      this.setSize(167,237); 
//      this.sumOfButton=10; 
      this.sumOfMine = 10; 
      this.sumOfNotMine = 90; 
      this.jLabel1.setText("     "); 
      this.jLabel2.setText("     "); 
    } 
    else 
      if(level.startsWith("middle")) 
      { 
 
        this.setSize(249,320); 
//        this.sumOfButton=15; 
        this.jLabel1.setText("                   "); 
        this.jLabel2.setText("                   "); 
        this.sumOfMine = 40; 
        this.sumOfNotMine = 185; 
      } 
      else 
        if(level.startsWith("high")) 
        { 
 
          this.setSize(329,400); 
          this.jLabel1.setText("                                "); 
          this.jLabel2.setText("                                "); 
//          this.sumOfButton=20; 
          this.sumOfMine = 99; 
          this.sumOfNotMine = 301; 
        } 
     
     
    jLabelTime.setText("0000"); 
    jLabelMineNum.setText("00" + this.sumOfMine); 
 
    Random myrandom = new Random(); 
     
//随机的分配雷的位置 
    int tempNum = sumOfMine; 
//    int tempFlag = 0; 
     
    while(tempNum > 0) 
    { 
      for(int iflag = 0;iflag < this.sumOfButton;iflag ++) 
        for(int jflag = 0;jflag < this.sumOfButton;jflag++) 
        { 
          if(tempNum > 0) 
          { 
             
            if(myrandom.nextInt(25)==0) 
            { 
              if(mineButton[iflag][jflag].getFlag()) 
                break; 
              else 
              { 
                mineButton[iflag][jflag].setFlag(true); 
                tempNum--; 
              } 
            } 
          } 
          else 
            break; 
        } 
       
    } 
//end of distribute mine    
    repaint(); 
     
 
    //beginning of counting number of mine around everybutton 
    for(int icount = 0; icount < this.sumOfButton; icount++) 
      for(int jcount = 0; jcount < this.sumOfButton; jcount++) 
      {  
        if(icount > 0) 
        { 
          if(mineButton[icount-1][jcount].getFlag()) 
            mineButton[icount][jcount].addNumOfMine(); 
          if((jcount > 0)&&(mineButton[icount-1][jcount-1].getFlag())) 
            mineButton[icount][jcount].addNumOfMine(); 
          if((jcount < this.sumOfButton-1)&&(mineButton[icount-1][jcount+1].getFlag())) 
            mineButton[icount][jcount].addNumOfMine(); 
        } 
        if(icount < this.sumOfButton-1) 
        { 
          if(mineButton[icount+1][jcount].getFlag()) 
            mineButton[icount][jcount].addNumOfMine(); 
          if((jcount > 0)&&(mineButton[icount+1][jcount-1].getFlag())) 
            mineButton[icount][jcount].addNumOfMine(); 
          if((jcount < this.sumOfButton-1)&&(mineButton[icount+1][jcount+1].getFlag())) 
            mineButton[icount][jcount].addNumOfMine(); 
        } 
        if((jcount > 0)&&(mineButton[icount][jcount-1]).getFlag()) 
            mineButton[icount][jcount].addNumOfMine(); 
        if((jcount < this.sumOfButton-1)&&(mineButton[icount][jcount+1]).getFlag()) 
            mineButton[icount][jcount].addNumOfMine(); 
             
      } 
  } 
 
   
  void clickButton(int i,int j) 
  { 
    if(!mineButton[i][j].getEnable()) 
      return ; 
    if(!isRestart) 
    { 
      isRestart = true; 
       
      theTimeThread = new TimeThread(this); 
      theTimeThread.start(); 
    } 
    if(!mineButton[i][j].getFlag()) 
    { 
      this.sumOfNotMine--; 
      jPanel1.remove(mineButton[i][j]); 
      mineButton[i][j].setEnable(false); 
 
       
//      JLabel testlabel = new JLabel(); 
 
      if(mineButton[i][j].getNumofMine()== 0) 
      { 
        jLabelTest[i][j].setIcon(imageCurv); 
        //beginning process button around mineButton[i][j] 
        if((i > 0) &&(!mineButton[i-1][j].getFlag())&&(mineButton[i-1][j].getEnable())&&((mineButton[i-1][j].getNumOfClick()%3)!=1)) 
            clickButton(i-1,j); 
        if((i < this.sumOfButton-1) &&(!mineButton[i+1][j].getFlag())&&(mineButton[i+1][j].getEnable())&&((mineButton[i+1][j].getNumOfClick()%3)!=1)) 
            clickButton(i+1,j);       
        if((j > 0) &&(!mineButton[i][j-1].getFlag())&&(mineButton[i][j-1].getEnable())&&((mineButton[i][j-1].getNumOfClick()%3)!=1)) 
            clickButton(i,j-1); 
        if((j < this.sumOfButton-1) &&(!mineButton[i][j+1].getFlag())&&(mineButton[i][j+1].getEnable())&&((mineButton[i][j+1].getNumOfClick()%3)!=1)) 
            clickButton(i,j+1); 
        if((i > 0)&&(j > 0)&&(!mineButton[i-1][j-1].getFlag())&&(mineButton[i-1][j-1].getEnable())&&((mineButton[i-1][j-1].getNumOfClick()%3)!=1)&&(!mineButton[i-1][j].getEnable()||!mineButton[i][j-1].getEnable())) 
            clickButton(i-1,j-1); 
        if((i > 0)&&(j < this.sumOfButton-1)&&(!mineButton[i-1][j+1].getFlag())&&(mineButton[i-1][j+1].getEnable())&&((mineButton[i-1][j+1].getNumOfClick()%3)!=1)&&(!mineButton[i-1][j].getEnable()||!mineButton[i][j+1].getEnable())) 
            clickButton(i-1,j+1); 
        if((i < this.sumOfButton-1)&&(j > 0)&&(!mineButton[i+1][j-1].getFlag())&&(mineButton[i+1][j-1].getEnable())&&((mineButton[i+1][j-1].getNumOfClick()%3)!=1)&&(!mineButton[i][j-1].getEnable()||!mineButton[i+1][j].getEnable())) 
            clickButton(i+1,j-1); 
        if((i < this.sumOfButton-1)&&(j < this.sumOfButton-1)&&(!mineButton[i+1][j+1].getFlag())&&(mineButton[i+1][j+1].getEnable())&&((mineButton[i+1][j+1].getNumOfClick()%3)!=1)&&(!mineButton[i+1][j].getEnable()||!mineButton[i][j+1].getEnable())) 
            clickButton(i+1,j+1); 
      } 
      else 
      { 
        String strCount = " "+mineButton[i][j].getNumofMine(); 
        jLabelTest[i][j].setText(strCount); 
      } 
     
      jPanel1.add(jLabelTest[i][j],null); 
      if(sumOfNotMine==0) 
      { 
        isRestart = false; 
        try 
        { 
          theTimeThread.join(); 
        } 
        catch(InterruptedException ex) 
        { 
          JOptionPane.showMessageDialog(null,"InterruptedException occurred here: "+ex); 
        } 
         
        for(int iflag = 0;iflag < sumOfButton ; iflag++) 
          for(int jflag = 0; jflag < sumOfButton ; jflag++) 
          { 
            if(mineButton[iflag][jflag].getEnable()) 
            { 
              if((mineButton[iflag][jflag].getFlag())&&(mineButton[iflag][jflag].getNumOfClick()%3!=1)) 
              { 
                mineButton[iflag][jflag].setIcon(imageMine);  
                /* 
                sumOfMine--; 
                if(sumOfMine > 0) 
                { 
                  if(sumOfMine < 10) 
                    jLabelMineNum.setText("000"+sumOfMine); 
                  else 
                    jLabelMineNum.setText("00"+sumOfMine); 
                } 
                else 
                  jLabelMineNum.setText(""+sumOfMine);*/ 
              } 
              mineButton[iflag][jflag].setEnable(false); 
            } 
             
          } 
        sumOfMine=0; 
        jLabelMineNum.setText("0000"); 
        buttonOpen.setIcon(imageWinner); 
        this.repaint(); 
        JOptionPane.setDefaultLocale(Locale.CHINESE); 
        JOptionPane.showMessageDialog(null,"You Win!!!"); 
        String newrec = ""+this.theTimeThread.numOfSecond; 
        if((newrec.length() < this.curRecord.length())||((newrec.length() == this.curRecord.length())&&(newrec.compareTo(curRecord) < 0))) 
        { 
          String newName = JOptionPane.showInputDialog(null,"please input your name"); 
          int tempvar = newName.length(); 
          int tempint  = newrec.length(); 
          while(newName.length() < 20) 
            newName = newName + ' '; 
          while(newrec.length() < 4) 
            newrec = newrec + ' '; 
           
          try 
          { 
            this.accessFile.seek(0); 
            if(this.level.startsWith("primer")) 
            { 
              this.accessFile.readLine(); 
              this.accessFile.readLine(); 
              this.accessFile.readLine(); 
            } 
              else if(this.level.startsWith("middle")) 
              { 
                this.accessFile.readLine(); 
                this.accessFile.readLine(); 
                this.accessFile.readLine(); 
                this.accessFile.readLine(); 
                this.accessFile.readLine(); 
                this.accessFile.readLine(); 
              } 
                else if(this.level.startsWith("high")) 
                { 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                  this.accessFile.readLine(); 
                   
                } 
          //write file 
          accessFile.writeBytes(newName + "\n"); 
          accessFile.writeBytes(newrec + "\n"); 
          } 
          catch(Exception ex) 
          { 
            JOptionPane.showMessageDialog(null,"Exception occurred here: " + ex); 
          } 
        } 
 
      } 
       
       
    } 
    else 
    { 
      //mineButton[i][j].setIcon(imageMineNotFound); 
      jPanel1.remove(mineButton[i][j]); 
      mineButton[i][j].setEnable(false); 
      jLabelTest[i][j].setIcon(imageBoom); 
     
      jPanel1.add(jLabelTest[i][j],null); 
      isRestart = false; 
      try 
      { 
        theTimeThread.join(); 
      } 
      catch(InterruptedException ex) 
      { 
        JOptionPane.showMessageDialog(null,"InterruptedException occurred here: "+ex); 
      } 
      
       for(int iflag = 0;iflag < sumOfButton ; iflag++) 
          for(int jflag = 0; jflag < sumOfButton ; jflag++) 
          { 
            if(mineButton[iflag][jflag].getEnable()) 
            { 
              if((mineButton[iflag][jflag].getFlag())&&(mineButton[iflag][jflag].getNumOfClick()%3!=1)) 
              { 
                jPanel1.remove(mineButton[iflag][jflag]); 
                jLabelTest[iflag][jflag].setIcon(imageMineNotFound); 
                jPanel1.add(jLabelTest[iflag][jflag],null); 
              }   
              if((!mineButton[iflag][jflag].getFlag())&&(mineButton[iflag][jflag].getNumOfClick()%3==1)) 
              { 
                jPanel1.remove(mineButton[iflag][jflag]); 
                jLabelTest[iflag][jflag].setIcon(imageErrMine); 
                jPanel1.add(jLabelTest[iflag][jflag],null); 
              } 
              mineButton[iflag][jflag].setEnable(false); 
            } 
          }     
      this.repaint(); 
      JOptionPane.setDefaultLocale(Locale.CHINESE); 
      JOptionPane.showMessageDialog(null,"You Lose!!!"); 
    } 
//    JOptionPane.showMessageDialog(null,""+sumOfNotMine); 
  } 
  void twoButtonPressed(int i,int j) 
  { 
    if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3!=1)) 
      mineButton[i-1][j].setVisible(false); 
    if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j-1].setVisible(false); 
    if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j+1].setVisible(false); 
    // 
    if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3!=1)) 
      mineButton[i][j-1].setVisible(false); 
    if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3!=1)) 
      mineButton[i][j+1].setVisible(false); 
    // 
    if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3!=1)) 
      mineButton[i+1][j].setVisible(false); 
    if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j-1].setVisible(false); 
    if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j+1].setVisible(false); 
       
  } 
  void twoButtonReleased(int i,int j) 
  { 
    if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3!=1)) 
      mineButton[i-1][j].setVisible(true); 
    if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j-1].setVisible(true); 
    if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j+1].setVisible(true); 
    // 
    if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3!=1)) 
      mineButton[i][j-1].setVisible(true); 
    if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3!=1)) 
      mineButton[i][j+1].setVisible(true); 
    // 
    if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3!=1)) 
      mineButton[i+1][j].setVisible(true); 
    if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j-1].setVisible(true); 
    if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j+1].setVisible(true); 
  } 
  void twoButtonReleasedOnLabel(int i,int j) 
  { 
    if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3!=1)) 
      mineButton[i-1][j].setVisible(true); 
    if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j-1].setVisible(true); 
    if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i-1][j+1].setVisible(true); 
    // 
    if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3!=1)) 
      mineButton[i][j-1].setVisible(true); 
    if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3!=1)) 
      mineButton[i][j+1].setVisible(true); 
    // 
    if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3!=1)) 
      mineButton[i+1][j].setVisible(true); 
    if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j-1].setVisible(true); 
    if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3!=1)) 
      mineButton[i+1][j+1].setVisible(true); 
 
    ///////////////////////////////////////////////////////////////////////////////////////////////// 
    int numOfFindMine = 0; 
    if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    // 
    if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    // 
    if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3==1)) 
      numOfFindMine++; 
    if(numOfFindMine == mineButton[i][j].getNumofMine()) 
    { 
      if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3!=1)) 
        clickButton(i-1,j); 
      if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3!=1)) 
        clickButton(i-1,j-1); 
      if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3!=1)) 
        clickButton(i-1,j+1); 
      // 
      if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3!=1)) 
        clickButton(i,j-1); 
      if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3!=1)) 
        clickButton(i,j+1); 
      // 
      if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3!=1)) 
        clickButton(i+1,j); 
      if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3!=1)) 
        clickButton(i+1,j-1); 
      if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3!=1)) 
        clickButton(i+1,j+1); 
      this.repaint(); 
    } 
    else 
    { 
      if((i > 0)&&(mineButton[i-1][j].getEnable())&&(mineButton[i-1][j].getNumOfClick()%3!=1)) 
        mineButton[i-1][j].setVisible(true); 
      if((i > 0)&&(j > 0)&&(mineButton[i-1][j-1].getEnable())&&(mineButton[i-1][j-1].getNumOfClick()%3!=1)) 
        mineButton[i-1][j-1].setVisible(true); 
      if((i > 0)&&(j < sumOfButton-1)&&(mineButton[i-1][j+1].getEnable())&&(mineButton[i-1][j+1].getNumOfClick()%3!=1)) 
        mineButton[i-1][j+1].setVisible(true); 
      // 
      if((j > 0)&&(mineButton[i][j-1].getEnable())&&(mineButton[i][j-1].getNumOfClick()%3!=1)) 
        mineButton[i][j-1].setVisible(true); 
      if((j < sumOfButton-1)&&(mineButton[i][j+1].getEnable())&&(mineButton[i][j+1].getNumOfClick()%3!=1)) 
        mineButton[i][j+1].setVisible(true); 
      // 
      if((i < sumOfButton-1)&&(mineButton[i+1][j].getEnable())&&(mineButton[i+1][j].getNumOfClick()%3!=1)) 
        mineButton[i+1][j].setVisible(true); 
      if((i < sumOfButton-1)&&(j > 0)&&(mineButton[i+1][j-1].getEnable())&&(mineButton[i+1][j-1].getNumOfClick()%3!=1)) 
        mineButton[i+1][j-1].setVisible(true); 
      if((i < sumOfButton-1)&&(j < sumOfButton-1)&&(mineButton[i+1][j+1].getEnable())&&(mineButton[i+1][j+1].getNumOfClick()%3!=1)) 
        mineButton[i+1][j+1].setVisible(true); 
    } 
  } 
  void clickRightButton(int i,int j) 
  { 
    if(!mineButton[i][j].getEnable()) 
      return; 
    mineButton[i][j].rightButtonClick(); 
    int temp = mineButton[i][j].getNumOfClick(); 
    switch(temp%3) 
    { 
      case 1: mineButton[i][j].setIcon(imageMine);  
              sumOfMine--; 
              if(sumOfMine > 0) 
              { 
                if(sumOfMine < 10) 
                  jLabelMineNum.setText("000"+sumOfMine); 
                else 
                  jLabelMineNum.setText("00"+sumOfMine); 
              } 
              else 
                jLabelMineNum.setText(""+sumOfMine); 
              break; 
      case 2: mineButton[i][j].setIcon(imageNotSure); 
              sumOfMine++; 
              if(sumOfMine > 0) 
              { 
                if(sumOfMine < 10) 
                  jLabelMineNum.setText("000"+sumOfMine); 
                else 
                  jLabelMineNum.setText("00"+sumOfMine); 
              } 
              else 
                jLabelMineNum.setText(""+sumOfMine); 
              break; 
      case 0: mineButton[i][j].setIcon(null); 
              break; 
       
    } 
  } 
 
  void onButtonOpen(ActionEvent e) 
  { 
    onNew(e); 
  } 
 
 
  void onMiddle(ActionEvent e) 
  { 
    try 
    { 
      accessFile.seek(0); 
      accessFile.readLine(); 
 
      accessFile.writeBytes("middle"); 
      this.level = "middle"; 
      this.sumOfButton = 15; 
      this.sumOfMine = 40; 
      this.sumOfNotMine = 185; 
      onNew(e); 
       
    } 
    catch(Exception ex) 
    {} 
  } 
 
  void onHigh(ActionEvent e) 
  { 
    try 
    { 
      accessFile.seek(0); 
      accessFile.readLine(); 
 
      accessFile.writeBytes("high  "); 
      this.level = "high"; 
      this.sumOfButton = 20; 
      this.sumOfMine = 99; 
      this.sumOfNotMine = 301; 
      onNew(e); 
       
    } 
    catch(Exception ex) 
    {} 
  } 
 
  void onPrimer(ActionEvent e) 
  { 
    try 
    { 
      accessFile.seek(0); 
      accessFile.readLine(); 
 
      accessFile.writeBytes("primer"); 
      this.level = "primer"; 
      this.sumOfButton = 10; 
      this.sumOfMine = 10; 
      this.sumOfNotMine = 90; 
      onNew(e); 
       
    } 
    catch(Exception ex) 
    {} 
  } 
 
  void onList(ActionEvent e) 
  { 
    ListFrame theListFrame = new ListFrame(this.accessFile); 
    String name; 
    String numOfTime; 
    try 
      { 
      accessFile.seek(0); 
      accessFile.readLine(); 
      accessFile.readLine(); 
      accessFile.readLine(); 
      name = accessFile.readLine(); 
      name = name.trim(); 
      numOfTime = accessFile.readLine(); 
      theListFrame.jLabelPrimer.setText("初级        "+ numOfTime + "秒        " +name ); 
      accessFile.readLine(); 
      name = accessFile.readLine(); 
      name = name.trim(); 
      numOfTime = accessFile.readLine(); 
      theListFrame.jLabelMiddle.setText("中级        "+ numOfTime + "秒        " +name ); 
      accessFile.readLine(); 
      name = accessFile.readLine(); 
      name = name.trim(); 
      numOfTime = accessFile.readLine(); 
      theListFrame.jLabelHigh.setText("高级        "+ numOfTime + "秒        " +name); 
    } 
    catch(Exception ex) 
    { 
      JOptionPane.showMessageDialog(null,"Exception occurred here: " + e); 
    } 
    Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); 
    Dimension framesize = theListFrame.getSize(); 
    if(framesize.height > screensize.height) 
      framesize.height = screensize.height; 
    if(framesize.width > screensize.width) 
      framesize.width = screensize.width; 
    theListFrame.setLocation((screensize.width - framesize.width)/2,(screensize.height - framesize.height)/2); 
     
    theListFrame.setVisible(true); 
  } 
 
  
   
}