コード例 #1
1
ファイル: Game.java プロジェクト: cpetosky/o2d-lib
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
コード例 #2
1
ファイル: TankBattle.java プロジェクト: lamChuanJiang/LBD
 public void actionPerformed(ActionEvent ae) {
   // 响应用户点击
   if (ae.getActionCommand().equals("new_game")) {
     // 如果选择 “开始新游戏” 则跳转到游戏开始
     ae_panel = new GamePanel(false);
     Thread ae_thread = new Thread(ae_panel);
     ae_thread.start();
     // 先删除旧面板 -- 开始界面
     this.remove(start_panel);
     this.add(ae_panel);
     this.addKeyListener(ae_panel);
     this.setVisible(true); // 如果没有这句点击后不会出现新的游戏面板
   } else if (ae.getActionCommand().equals("qs_game")) {
     // 退出时保存游戏进度
     Recorder.set_enemies(ae_panel.enemies);
     Recorder.save_game_data();
     // 0 表示正常退出
     System.exit(0);
   } else if (ae.getActionCommand().equals("restart_old_game")) {
     // 恢复游戏数据 -- 如果曾经保存
     Recorder.recovery_position();
     ae_panel = new GamePanel(true);
     Thread ae_thread = new Thread(ae_panel);
     ae_thread.start();
     // 先删除旧面板 -- 开始界面
     this.remove(start_panel);
     this.add(ae_panel);
     this.addKeyListener(ae_panel);
     this.setVisible(true);
   } else if (ae.getActionCommand().equals("save_now")) {
     Recorder.set_enemies(ae_panel.enemies);
     Recorder.recovery_position();
   }
 }
コード例 #3
1
  /** Start the background thread. */
  public void start() {
    // create a random list of cities

    cities = new City[TravelingSalesman.CITY_COUNT];
    for (int i = 0; i < TravelingSalesman.CITY_COUNT; i++) {
      cities[i] =
          new City(
              (int) (Math.random() * (getBounds().width - 10)),
              (int) (Math.random() * (getBounds().height - 60)));
    }

    // create the initial chromosomes

    chromosomes = new Chromosome[TravelingSalesman.POPULATION_SIZE];
    for (int i = 0; i < TravelingSalesman.POPULATION_SIZE; i++) {
      chromosomes[i] = new Chromosome(cities);
      chromosomes[i].setCut(cutLength);
      chromosomes[i].setMutation(TravelingSalesman.MUTATION_PERCENT);
    }
    Chromosome.sortChromosomes(chromosomes, TravelingSalesman.POPULATION_SIZE);

    // start up the background thread
    started = true;
    map.update(map.getGraphics());

    generation = 0;

    if (worker != null) worker = null;
    worker = new Thread(this);
    // worker.setPriority(Thread.MIN_PRIORITY);
    worker.start();
  }
コード例 #4
0
ファイル: AppletPanel.java プロジェクト: FauxFaux/jdk9-jdk
  /*
   * Creates a thread to run the applet. This method is called
   * each time an applet is loaded and reloaded.
   */
  synchronized void createAppletThread() {
    // Create a thread group for the applet, and start a new
    // thread to load the applet.
    String nm = "applet-" + getCode();
    loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey());
    loader.grab(); // Keep this puppy around!

    // 4668479: Option to turn off codebase lookup in AppletClassLoader
    // during resource requests. [stanley.ho]
    String param = getParameter("codebase_lookup");

    if (param != null && param.equals("false")) loader.setCodebaseLookup(false);
    else loader.setCodebaseLookup(true);

    ThreadGroup appletGroup = loader.getThreadGroup();
    handler = new Thread(appletGroup, this, "thread " + nm, 0, false);
    // set the context class loader for this thread
    AccessController.doPrivileged(
        new PrivilegedAction<Object>() {
          @Override
          public Object run() {
            handler.setContextClassLoader(loader);
            return null;
          }
        });
    handler.start();
  }
コード例 #5
0
  private void doRun(final Test testSuite) {
    setButtonLabel(fRun, "Stop");
    fRunner =
        new Thread("TestRunner-Thread") {
          public void run() {
            UnitTestRunner.this.start(testSuite);
            postInfo("Running...");

            long startTime = System.currentTimeMillis();
            testSuite.run(fTestResult);

            if (fTestResult.shouldStop()) {
              postInfo("Stopped");
            } else {
              long endTime = System.currentTimeMillis();
              long runTime = endTime - startTime;
              postInfo("Finished: " + elapsedTimeAsString(runTime) + " seconds");
            }
            runFinished(testSuite);
            setButtonLabel(fRun, "Run");
            showIDE(true);
            fRunner = null;
            System.gc();
          }
        };
    // make sure that the test result is created before we start the
    // test runner thread so that listeners can register for it.
    fTestResult = createTestResult();
    fTestResult.addListener(UnitTestRunner.this);
    aboutToStart(testSuite);

    fRunner.start();
  }
 public void findLocationForInstance(ArchDescriptionInstances newInstance) {
   if (newInstance instanceof ArchDescriptionAnalogInstances) {
     final Resources parentResource = (Resources) editorField.getModel();
     final ArchDescriptionAnalogInstances analogInstance =
         (ArchDescriptionAnalogInstances) newInstance;
     Thread performer =
         new Thread(
             new Runnable() {
               public void run() {
                 InfiniteProgressPanel monitor =
                     ATProgressUtil.createModalProgressMonitor(
                         ApplicationFrame.getInstance(), 1000);
                 monitor.start("Gathering Containers...");
                 try {
                   analogInstance.setLocation(
                       parentResource.findLocationForContainer(
                           analogInstance.getTopLevelLabel(), monitor));
                 } finally {
                   monitor.close();
                 }
               }
             },
             "Performer");
     performer.start();
   }
 }
コード例 #7
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
コード例 #8
0
ファイル: BounceThread.java プロジェクト: 010239/java
 /** Adds a bouncing ball to the canvas and starts a thread to make it bounce */
 public void addBall() {
   Ball b = new Ball();
   comp.add(b);
   Runnable r = new BallRunnable(b, comp);
   Thread t = new Thread(r);
   t.start();
 }
コード例 #9
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
コード例 #10
0
ファイル: ImageJ.java プロジェクト: chrisp87/ImageJA
 /** Called by ImageJ when the user selects Quit. */
 public void quit() {
   quitMacro = IJ.macroRunning();
   Thread thread = new Thread(this, "Quit");
   thread.setPriority(Thread.NORM_PRIORITY);
   thread.start();
   IJ.wait(10);
 }
コード例 #11
0
ファイル: MainFrame.java プロジェクト: XaoZloHnH/hafen-client
 public void run() {
   if (Thread.currentThread() != this.mt)
     throw (new RuntimeException("MainFrame is being run from an invalid context"));
   Thread ui = new HackThread(p, "Haven UI thread");
   ui.start();
   try {
     try {
       Session sess = null;
       while (true) {
         UI.Runner fun;
         if (sess == null) {
           Bootstrap bill = new Bootstrap(Config.defserv, Config.mainport);
           if ((Config.authuser != null) && (Config.authck != null)) {
             bill.setinitcookie(Config.authuser, Config.authck);
             Config.authck = null;
           }
           fun = bill;
           setTitle(String.format("Amish Paradise %s", version));
         } else {
           fun = new RemoteUI(sess);
           setTitle(String.format("Amish Paradise %s \u2013 %s", version, sess.username));
         }
         sess = fun.run(p.newui(sess));
       }
     } catch (InterruptedException e) {
     }
     savewndstate();
   } finally {
     ui.interrupt();
     dispose();
   }
 }
コード例 #12
0
 public void actionPerformed(ActionEvent ae) {
   String action = ae.getActionCommand();
   if (action.equals("refresh")) {
     routerThread = new Thread(this);
     routerThread.start();
   }
 }
コード例 #13
0
  /** Second part of debugger start procedure. */
  private void startDebugger() {
    threadManager = new ThreadManager(this);

    setBreakpoints();
    updateWatches();
    println(bundle.getString("CTL_Debugger_running"), STL_OUT);
    setDebuggerState(DEBUGGER_RUNNING);

    virtualMachine.resume();

    // start refresh thread .................................................
    if (debuggerThread != null) debuggerThread.stop();
    debuggerThread =
        new Thread(
            new Runnable() {
              public void run() {
                for (; ; ) {
                  try {
                    Thread.sleep(5000);
                  } catch (InterruptedException ex) {
                  }
                  if (getState() == DEBUGGER_RUNNING) threadGroup.refresh();
                }
              }
            },
            "Debugger refresh thread"); // NOI18N
    debuggerThread.setPriority(Thread.MIN_PRIORITY);
    debuggerThread.start();
  }
コード例 #14
0
ファイル: Life.java プロジェクト: dragon66/icafe
 public void start() {
   if (firstTime) return;
   if (t == null) {
     t = new Thread(this);
     t.start();
   }
 }
コード例 #15
0
  Ccard() {
    OData.GenRnd(data, min, max, rnd_no); // 產生0~8亂數
    // 9個圖形物件
    for (i = 0; i <= 8; i++) {
      icon[i] = new ImageIcon("fig/p_" + i + ".jpg");
    }
    // 9個標籤亂數放圖
    k = 0;
    for (i = 0; i <= 2; i++) {
      for (j = 0; j <= 2; j++) {
        lbl[k] = new JLabel(icon[data[k]]);
        lbl[k].setBounds(10 + j * 160, 10 + i * 120, 160, 120);
        add(lbl[k]);
        lbl[k].addMouseListener(mouseObj); // 註冊傾聽者
        k++;
      }
    }

    lblCar.setSize(65, 43);
    add(lblCar);
    int width = 510, c_y = 375, c_time = 25;
    Thread ThCar = new Thread(new movePic(lblCar, width, c_y, c_time));
    ThCar.start();

    setTitle("3x3拼圖遊戲");
    setLayout(null);
    setBounds(100, 100, 510, 460);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
コード例 #16
0
    protected void openFromPath(final String path) {
      Thread t =
          new Thread(
              new Runnable() {
                public void run() {
                  final ArrayList<Airspace> airspaces = new ArrayList<Airspace>();
                  try {
                    loadAirspacesFromPath(path, airspaces);
                  } finally {
                    SwingUtilities.invokeLater(
                        new Runnable() {
                          public void run() {
                            setAirspaces(airspaces);
                            setEnabled(true);
                            getApp().setCursor(null);
                            getApp().getWwd().redraw();
                          }
                        });
                  }
                }
              });

      this.setEnabled(false);
      getApp().setCursor(new Cursor(Cursor.WAIT_CURSOR));
      t.start();
    }
コード例 #17
0
  public AnimationFrame() {
    ArrayComponent comp = new ArrayComponent();
    add(comp, BorderLayout.CENTER);

    final Sorter sorter = new Sorter(comp);

    JButton runButton = new JButton("Run");
    runButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            sorter.setRun();
          }
        });

    JButton stepButton = new JButton("Step");
    stepButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            sorter.setStep();
          }
        });

    JPanel buttons = new JPanel();
    buttons.add(runButton);
    buttons.add(stepButton);
    add(buttons, BorderLayout.NORTH);
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    Thread t = new Thread(sorter);
    t.start();
  }
コード例 #18
0
ファイル: JackPanel.java プロジェクト: hustbill/bounce
 private void startGame()
       // initialise and start the thread
     {
   if (animator == null || !running) {
     animator = new Thread(this);
     animator.start();
   }
 } // end of startGame()
コード例 #19
0
ファイル: IAppletGL2.java プロジェクト: JaredHalpern/iGeo
 public void start() {
   initObjects();
   running = true;
   if (thread == null) {
     thread = new Thread(this);
   }
   thread.start();
 }
コード例 #20
0
ファイル: Homework10.java プロジェクト: Sfhillier/YinYang
  public PanelForSquare() {
    setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
    setBackground(Color.white);

    Thread thread = new Thread(this);
    initTimer();
    thread.start();
  }
コード例 #21
0
 public void _notified(double sec, final String chars) {
   if (!isSecure(sec)) return;
   // decouple from JavaScript; thread join could hang it
   Thread thread =
       new Thread("_notified") {
         public void run() {
           AccessController.doPrivileged(
               new PrivilegedAction() {
                 public Object run() {
                   try {
                     // wait for release shift/altgraph to resolve
                     if (previousThread != null) {
                       previousThread.join();
                     }
                   } catch (Exception e) {
                   }
                   keystring += chars;
                   if (altgraph && !shift) {
                     shift = false;
                     // Set robot auto delay now that FF/Mac inited all of the keys.
                     // Good for DND.
                     robot.setAutoDelay(1);
                     try {
                       log(keystring);
                       int index = 0;
                       for (int i = 0; (i < vkKeys.size()) && (index < keystring.length()); i++) {
                         char c = keystring.charAt(index++);
                         _mapKey(c, i, false, false);
                       }
                       for (int i = 0; (i < vkKeys.size()) && (index < keystring.length()); i++) {
                         char c = keystring.charAt(index++);
                         _mapKey(c, i, true, false);
                       }
                       for (int i = 0; (i < vkKeys.size()) && (index < keystring.length()); i++) {
                         char c = keystring.charAt(index++);
                         _mapKey(c, i, false, true);
                       }
                       // notify DOH that the applet finished init
                       dohrobot.call("_onKeyboard", new Object[] {});
                     } catch (Exception e) {
                       e.printStackTrace();
                     }
                     return null;
                   } else if (!shift) {
                     shift = true;
                   } else {
                     shift = false;
                     altgraph = true;
                   }
                   pressNext();
                   // }
                   return null;
                 }
               });
         }
       };
   thread.start();
 }
コード例 #22
0
 void startPlaying() {
   playing = new Thread(this);
   playing.start();
   gui.play.setEnabled(false);
   gui.stop.setEnabled(true);
   gui.reset.setEnabled(false);
   gui.quickpick.setEnabled(false);
   gui.personal.setEnabled(false);
 }
コード例 #23
0
 private void messageStresser() throws HeadlessException {
   String res = JOptionPane.showInputDialog(this, "Number of messages to send");
   try {
     int count = Integer.parseInt(res);
     Thread t = new Thread(new Stresser(count));
     t.start();
   } catch (NumberFormatException nfe) {
   }
 }
コード例 #24
0
 @Override
 public void addNotify() {
   super.addNotify();
   if (thread == null) {
     thread = new Thread(this);
     addKeyListener(this);
     thread.start();
   }
 }
コード例 #25
0
ファイル: Senso.java プロジェクト: zale90/hg78ijavaprojects
 public void start(Game.Spiel senso) {
   this.setVisible(true);
   // new Senso();
   s = senso;
   neustarten(true);
   läuft = true;
   spiel = new Thread(this);
   spiel.start();
 }
コード例 #26
0
  /** Mutes or unmutes the associated <tt>Call</tt> upon clicking this button. */
  public void toggleMute() {
    if (muteRunner == null) {
      muteRunner = new Thread(this, getToolTipText());
      muteRunner.setDaemon(true);

      setEnabled(false);
      muteRunner.start();
    }
  }
コード例 #27
0
  public void paint(Graphics g) {
    super.paint(g);
    g.setFont(fotn);
    Random generator1 = new Random();
    height = bird.getBirdy();

    g.drawImage(Backgroundtop, 0, 0, 450, 644, null);
    g.drawImage(Bird, 100, height, 40, 30, null);

    if (firstrun == true) { // intiate threads
      pipethread[currentthreads].start();
      birdthread.start();
      firstrun = false;
    }

    for (int index = 0; index <= currentthreads; index++) {
      g.drawImage(Pipes, pipeob[index].getpipex(), pipeob[index].getpipey(), null);
    }

    g.drawImage(Backgroundbottom, 0, 644, 450, 156, null);

    g.setColor(Color.black);

    if (pipeob[currentthreads].getpipex() <= 550) {
      currentthreads++;
      pipethread[currentthreads].start();
      score++;
    }
    g.drawString("Score: " + score + "", 50, 50);

    for (int index = 0; index < currentthreads; index++) {
      if (((height < pipeob[index].getpipey() + 730) || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height < pipeob[index].getpipey() + 730)
                  || (height > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100))
          || ((height + 30 < pipeob[index].getpipey() + 730)
                  || (height + 30 > pipeob[index].getpipey() + 870))
              && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140))
          || ((height + 30 >= 644))) {
        g.drawImage(gameover, 125, 200, null);
        JOptionPane.showMessageDialog(
            null, "You Dead. \n you scored " + score, "Oh no!", JOptionPane.INFORMATION_MESSAGE);
      }
    }
    for (int counter = 0; counter <= 50000000; counter++) {
      counter++;
      counter--;
    }
    do {
      repaint();
    } while (replay = true);
  }
コード例 #28
0
 /**
  * This will be called when the user clicks the "Send" button or presses return in the text-input
  * box. It posts the contents of the input box to the transcript. If the thread is not running, it
  * creates and starts a new thread.
  */
 public void actionPerformed(ActionEvent evt) {
   postMessage("SENT: " + input.getText());
   input.selectAll();
   input.requestFocus();
   if (running == false) {
     runner = new Thread(this);
     running = true;
     runner.start();
   }
 }
コード例 #29
0
ファイル: TankGame3.java プロジェクト: yifei325325/TankGame
 public TankGame3() {
   // 坦克游戏的构造函数
   mp = new MyPanel();
   Thread t = new Thread(mp);
   t.start();
   this.add(mp);
   this.addKeyListener(mp);
   this.setSize(800, 600);
   this.setDefaultCloseOperation(EXIT_ON_CLOSE);
   this.setVisible(true);
 }
コード例 #30
0
ファイル: TankBattle.java プロジェクト: lamChuanJiang/LBD
 public TankBattle() {
   // 2. 创建游戏面板等组件
   start_panel = new StartPanel();
   menu_bar = new JMenuBar();
   menu_option = new JMenu("游戏选项(G)");
   menu_help = new JMenu("帮助(H)");
   menu_pause = new JMenu("【暂停游戏(P)】");
   menu_continue = new JMenu("【继续游戏(C)】");
   menu_option.setMnemonic('G');
   menu_help.setMnemonic('H');
   mi_new = new JMenuItem("开始新游戏(N)");
   mi_quit = new JMenuItem("存盘退出(Q)");
   mi_save = new JMenuItem("保存游戏进度(S)");
   mi_old_start = new JMenuItem("读取游戏进度(R)");
   mi_about = new JMenuItem("关于(A)");
   // 4. 响应菜单 -- 为 KeyListener 注册监听
   mi_new.addActionListener(this);
   mi_new.setActionCommand("new_game");
   mi_quit.addActionListener(this);
   mi_quit.setActionCommand("qs_game");
   mi_old_start.addActionListener(this);
   mi_old_start.setActionCommand("restart_old_game");
   mi_save.addActionListener(this);
   mi_save.setActionCommand("save_now");
   menu_option.add(mi_new);
   menu_option.add(mi_quit);
   menu_option.add(mi_save);
   menu_option.add(mi_old_start);
   menu_help.add(mi_about);
   menu_bar.add(menu_option);
   menu_bar.add(menu_help);
   menu_bar.add(menu_pause);
   menu_bar.add(menu_continue);
   Thread start_p = new Thread(start_panel);
   start_p.start();
   this.setJMenuBar(menu_bar);
   this.add(start_panel);
   // 3. 添加游戏面板组件到窗体
   this.add(start_panel);
   // 设置窗体标题
   this.setTitle("坦克大战");
   // 设置窗体图标 -- D:/workspace/TankBattle/src/com/tank_battle
   this.setIconImage((new ImageIcon("src/images/tank_battle.gif")).getImage());
   // 设置窗体大小
   this.setSize(800, 700);
   // 设置窗体可见
   this.setVisible(true);
   // 禁止用户修改窗体大小
   this.setResizable(false);
   // 设置窗体初始位置(像素)
   this.setLocation(250, 50);
   // 设置当窗体退出时, JVM 也退出,否则就算关闭了窗体,JVM 仍然有进程在运行
   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }