Пример #1
1
 public void run(String local, String remote, InputStream pin, OutputStream pout) {
   try {
     microphone = SoundMixerEnumerator.getInputLine(pcmformat, DefaultPhonePCMBlockSize);
   } catch (LineUnavailableException lue) {
     System.out.println(
         "\3b"
             + getClass().getName()
             + ".<init>:\n\tCould not create microphone input stream.\n\t"
             + lue);
   }
   try {
     speaker = SoundMixerEnumerator.getOutputLine(pcmformat, DefaultPhonePCMBlockSize);
   } catch (LineUnavailableException lue) {
     microphone.close();
     System.out.println(
         "\3b"
             + getClass().getName()
             + ".<init>:\n\tCould not create speaker output stream.\n\t"
             + lue);
   }
   if ((speaker == null) || (microphone == null)) {
     super.run(local, remote, pin, pout);
     return;
   }
   try {
     recorder = new Recorder(pout);
     recorder.start();
     gui = openMonitorGUI("Remote " + remote + " Local " + local);
     pin.skip(pin.available()); // waste whatever we couldn't process in time
     super.run(local, remote, new PhoneCallMonitorInputStream(pin), pout);
     recorder.interrupt();
     gui.dispose();
   } catch (Exception e) {
     System.out.println("3\b" + getClass().getName() + ".run:\n\t" + e);
     e.printStackTrace();
   } finally {
     deactivate();
     microphone.close();
     speaker.close();
     if (gui != null) {
       gui.dispose();
     }
   }
 }
Пример #2
0
  @Override
  public void actionPerformed(ActionEvent e) {
    // 对用户不同的选择做出不同的处理
    if (e.getActionCommand().equals("new game")) {
      // 创建游戏界面面板
      mp = new MyPanel("newGame");
      // 启动MyPanel线程
      Thread t = new Thread(mp);
      t.start();
      // 先删除旧Panel
      this.remove(msp);
      this.add(mp);
      // 注册监听
      this.addKeyListener(mp);
      // 显示(刷新JFrame)
      this.setVisible(true);

    } else if (e.getActionCommand().equals("exit")) {
      // 用户点击了退出系统菜单
      // 保存击毁敌人数量.
      Recorder.SaveRecord();

      System.exit(0);
    } // 对存盘退出做处理
    else if (e.getActionCommand().equals("saveExit")) {
      Recorder rd = new Recorder();
      rd.setEts(mp.enemyTanks);
      // 保存击毁敌人的数量和敌人的坐标
      rd.SaveRecAndEnemy();

      // 退出(0代表正常退出,1代表异常退出)
      System.exit(0);
    } else if (e.getActionCommand().equals("continue")) {
      //
      // 创建游戏界面面板
      mp = new MyPanel("con");
      //            mp.flag="con";

      // 启动MyPanel线程
      Thread t = new Thread(mp);
      t.start();
      // 先删除旧Panel
      this.remove(msp);
      this.add(mp);
      // 注册监听
      this.addKeyListener(mp);
      // 显示(刷新JFrame)
      this.setVisible(true);
    }
  }
Пример #3
0
 void finishPolygon() {
   if (xpf != null) {
     FloatPolygon poly = new FloatPolygon(xpf, ypf, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     bounds = poly.getFloatBounds();
     float xbase = (float) bounds.getX();
     float ybase = (float) bounds.getY();
     for (int i = 0; i < nPoints; i++) {
       xpf[i] -= xbase;
       ypf[i] -= ybase;
     }
   } else {
     Polygon poly = new Polygon(xp, yp, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     for (int i = 0; i < nPoints; i++) {
       xp[i] = xp[i] - x;
       yp[i] = yp[i] - y;
     }
     bounds = null;
   }
   if (nPoints < 2
       || (!(type == FREELINE || type == POLYLINE || type == ANGLE)
           && (nPoints < 3 || width == 0 || height == 0))) {
     if (imp != null) imp.deleteRoi();
     if (type != POINT) return;
   }
   state = NORMAL;
   if (imp != null && !(type == TRACED_ROI)) imp.draw(x - 5, y - 5, width + 10, height + 10);
   oldX = x;
   oldY = y;
   oldWidth = width;
   oldHeight = height;
   if (Recorder.record
       && userCreated
       && (type == POLYGON
           || type == POLYLINE
           || type == ANGLE
           || (type == POINT && Recorder.scriptMode() && nPoints == 3)))
     Recorder.recordRoi(getPolygon(), type);
   if (type != POINT) modifyRoi();
   LineWidthAdjuster.update();
 }
Пример #4
0
  // 画出提示信息的函数
  public void showInfo(Graphics g) {
    // 画出提示信息坦克(该坦克只是提示)
    this.drawTank(80, 330, g, 0, 1);
    g.setColor(Color.blue);
    g.drawString(Recorder.getEnNum() + "", 110, 350);
    this.drawTank(130, 330, g, 0, 0);
    g.setColor(Color.blue);
    g.drawString(Recorder.getMyLife() + "", 165, 350);

    // 画出玩家的总成绩
    g.setColor(Color.BLACK);
    Font f = new Font("娃娃體-繁", Font.BOLD, 20);
    g.setFont(f);
    g.drawString("您的總成績", 420, 30);

    this.drawTank(420, 60, g, 0, 1);

    g.setColor(Color.BLACK);
    g.drawString(Recorder.getAllEnNum() + "", 460, 80);
  }
Пример #5
0
  // 判断我的子弹是否击中敌人坦克
  public void hitEnemyTank() {
    // 判断是否击中敌人坦克(遍历)
    for (int i = 0; i < myTank.bb.size(); i++) {
      // 取出子弹
      Bullet mb = myTank.bb.get(i);
      // 判断子弹是否有效,存活
      if (mb.alive) {
        // 取出每个敌人坦克,与子弹判断
        for (int j = 0; j < enemyTanks.size(); j++) {
          // 取出坦克
          EnemyTank et = enemyTanks.get(j);

          if (et.alive) {
            if (this.hitTank(mb, et)) {
              // 减少敌人数量
              Recorder.reduceEnNum();
              // 增加我方战绩
              Recorder.addEnNumRec();
            }
          }
        }
      }
    }
  }
Пример #6
0
  // 构造函数
  public MyPanel(String flag) {
    apw.start();

    // 恢复记录
    Recorder.getRecord();
    //        bombs.add(new Bomb(0,0));
    // 括号里的是初始位置
    myTank = new MyTank(100, 100);

    if (flag.equals("newGame")) {
      // 初始化敌方坦克
      for (int i = 0; i < enemySize; i++) {
        // 创建一辆敌人的坦克
        EnemyTank et = new EnemyTank((i + 1) * 50, 0);
        et.setColor(1);
        et.setDirect(2);
        // 將MyPanel的敵人坦克向量交給該敵人坦克
        et.setEts(enemyTanks);

        // 启动敌人的坦克
        Thread t = new Thread(et);
        t.start();
        // 给敌人坦克添加一颗子弹
        Bullet b = new Bullet(et.x + 10, et.y + 30, 2);
        // 加入敌人坦克
        et.bb.add(b);
        Thread t2 = new Thread(b);
        t2.start();
        // 加入
        enemyTanks.add(et);
      }
    } else {

      nodes = new Recorder().getNodesAndEnNums();
      // 初始化敌方坦克
      for (int i = 0; i < nodes.size(); i++) {
        Node node = nodes.get(i);
        // 创建一辆敌人的坦克
        EnemyTank et = new EnemyTank(node.x, node.y);
        et.setColor(1);
        et.setDirect(node.direct);
        // 將MyPanel的敵人坦克向量交給該敵人坦克
        et.setEts(enemyTanks);

        // 启动敌人的坦克
        Thread t = new Thread(et);
        t.start();
        // 给敌人坦克添加一颗子弹
        Bullet b = new Bullet(et.x + 10, et.y + 30, 2);
        // 加入敌人坦克
        et.bb.add(b);
        Thread t2 = new Thread(b);
        t2.start();
        // 加入
        enemyTanks.add(et);
      }
    }
    // 初始化爆炸图片

    //        try {
    //            image1= ImageIO.read(new File("/3.png"));
    //            image2= ImageIO.read(new File("/2.png"));
    //            image3= ImageIO.read(new File("/1.png"));
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }
    image1 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/3.png"));
    image2 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/2.png"));
    image3 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/1.png"));
    bombs.add(new Bomb(0, 0));
  }
Пример #7
0
 public void windowClosing(WindowEvent e) {
   if (e.getSource() == this) {
     close();
     if (Recorder.record) Recorder.record("run", "Close");
   }
 }
Пример #8
0
 public void itemStateChanged(ItemEvent e) {
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp == null) return;
   if (!imp.isComposite()) {
     int channels = imp.getNChannels();
     if (channels == 1 && imp.getStackSize() <= 4) channels = imp.getStackSize();
     if (imp.getBitDepth() == 24 || (channels > 1 && channels < CompositeImage.MAX_CHANNELS)) {
       GenericDialog gd = new GenericDialog(imp.getTitle());
       gd.addMessage("Convert to multi-channel composite image?");
       gd.showDialog();
       if (gd.wasCanceled()) return;
       else IJ.doCommand("Make Composite");
     } else {
       IJ.error(
           "Channels",
           "A composite image is required (e.g., "
               + moreLabel
               + " Open HeLa Cells),\nor create one using "
               + moreLabel
               + " Make Composite.");
       return;
     }
   }
   if (!imp.isComposite()) return;
   CompositeImage ci = (CompositeImage) imp;
   Object source = e.getSource();
   if (source == choice) {
     int index = ((Choice) source).getSelectedIndex();
     switch (index) {
       case 0:
         ci.setMode(IJ.COMPOSITE);
         break;
       case 1:
         ci.setMode(IJ.COLOR);
         break;
       case 2:
         ci.setMode(IJ.GRAYSCALE);
         break;
     }
     ci.updateAndDraw();
     if (Recorder.record) {
       String mode = null;
       switch (index) {
         case 0:
           mode = "composite";
           break;
         case 1:
           mode = "color";
           break;
         case 2:
           mode = "grayscale";
           break;
       }
       Recorder.record("Stack.setDisplayMode", mode);
     }
   } else if (source instanceof Checkbox) {
     for (int i = 0; i < checkbox.length; i++) {
       Checkbox cb = (Checkbox) source;
       if (cb == checkbox[i]) {
         if (ci.getMode() == IJ.COMPOSITE) {
           boolean[] active = ci.getActiveChannels();
           active[i] = cb.getState();
           if (Recorder.record) {
             String str = "";
             for (int c = 0; c < ci.getNChannels(); c++) str += active[c] ? "1" : "0";
             Recorder.record("Stack.setActiveChannels", str);
             Recorder.record("//Stack.toggleChannel", imp.getChannel());
           }
         } else {
           imp.setPosition(i + 1, imp.getSlice(), imp.getFrame());
           if (Recorder.record) Recorder.record("Stack.setChannel", i + 1);
         }
         ci.updateAndDraw();
         return;
       }
     }
   }
 }