Example #1
0
 /** 实现对打开文件的处理 */
 public void openAnswer() {
   if (answer == 0) {
     cb.canPlay = true;
     File file = null;
     JFileChooser fileChooser = new JFileChooser();
     fileChooser.setApproveButtonText("确定");
     fileChooser.setDialogTitle("打开文件");
     fileChooser.setCurrentDirectory(new File("SavaAndOpen"));
     int result = fileChooser.showOpenDialog(gc); // 显示选择框
     if (result == JFileChooser.APPROVE_OPTION) { // 选择的是确定按钮
       file = fileChooser.getSelectedFile(); // 得到选择的文件
       cb.repaint();
     }
     if (file != null) {
       try {
         DataInputStream dis = new DataInputStream(new FileInputStream(file));
         for (int i = 0; i < 8; i++) {
           for (int j = 0; j < 8; j++) {
             allChess[i][j] = dis.readInt();
           }
         }
         cb.message = dis.readUTF();
         cb.isBlack = dis.readBoolean();
         if (cb.isBlack == false) { // 如果是和电脑下且轮到白子下
           cb.ch.playWithCom();
         }
         cb.changeColor = dis.readBoolean();
         cb.isStop = dis.readBoolean();
         if (cb.computerPlay == false) { // 如果不和电脑下,发送信息
           cb.send(cc.dos);
         }
         dis.close();
         cb.repaint();
       } catch (Exception e1) {
       }
     }
   }
   if (answer != 0) {
     JOptionPane.showMessageDialog(cb, "对方拒绝了你的请求!");
   }
   answer = 3;
 }