Esempio n. 1
0
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == easy) {
      invSpeed = 50000;
      bombN = 1;
      timeDifficulty1 = 1000;
      distanceLimit = 400;
      monsterMultiplier = 1;
      multiplier = 1;
      setup();
    } else if (e.getSource() == hard) {
      invSpeed = 30000;
      bombN = 4;
      timeDifficulty1 = 500;
      distanceLimit = 200;
      monsterMultiplier = 2;
      multiplier = 2;
      setup();
    } else if (e.getSource() == back) {
      r = null;
      menu.setVisible(true);
      back.setVisible(false);
      this.revalidate();
      repaint();
    } else if (e.getSource() == howTo) {
      menu.removeAll();

      menu.add(howToBack);
      menu.add(howToIMGL);

      menu.revalidate();
      menu.repaint();
    } else if (e.getSource() == howToBack) {
      menu.remove(howToIMGL);
      menu.remove(howToBack);

      menu.add(keyboardSpeedL1);
      menu.add(keyboardSpeedL2);
      menu.add(easy);
      menu.add(hard);
      menu.add(howTo);
      menu.add(onePlayerRB);
      menu.add(twoPlayerRB);
      menu.add(mouseRB);
      menu.add(keyboardRB);
      menu.add(keyboardSpeedS1);
      menu.add(keyboardSpeedS2);
      menu.add(musicCB);
      menu.add(highscoreL);
      menu.add(menuIMGL);

      menu.revalidate();
      menu.repaint();
    }
  }
Esempio n. 2
0
  //    int frame = 0;
  public void paint(Graphics g) {
    // System.out.println("frame: " + (frame++));
    lStatus.setText(
        "t = "
            + df.format(md.dt * md.step)
            + ", "
            + "N = "
            + md.N
            + ", "
            + "E/N = "
            + df.format(md.E / md.N)
            + ", "
            + "U/N = "
            + df.format(md.U / md.N)
            + ", "
            + "K/N = "
            + df.format(md.K / md.N)
            + ", "
            + "p = "
            + df.format(md.p)
            + ";");
    tAvK.setText(df.format(md.avK.getAve() / md.N) + "  ");
    tAvU.setText(df.format(md.avU.getAve() / md.N) + "  ");
    tTemp.setText(df.format((2 * md.K) / (3 * (md.N - 1))) + "  ");
    tAvp.setText(df.format(md.avp.getAve()) + "  ");
    canvas.refresh(md.getXWrap(), md.N, true, false);
    cpnl.repaint();
    spnl.repaint();

    try {

      PrintWriter wavefunc =
          new PrintWriter(new FileOutputStream(new File("energyData.txt"), true));
      wavefunc.print(md.E / md.N + " " + md.K / md.N + " " + md.U / md.N);
      wavefunc.println();
      wavefunc.close();
    } catch (IOException ex) {
    }

    try {

      PrintWriter tempwriter =
          new PrintWriter(new FileOutputStream(new File("tempData.txt"), true));
      tempwriter.print(df.format((2 * md.K) / (3 * (md.N - 1))));
      tempwriter.println();
      tempwriter.close();
    } catch (IOException ex) {
    }
  }
Esempio n. 3
0
  public static void updateResultsTable(Object[][] data) {
    // remove old route table
    resultsPanel.removeAll();

    // create new route table
    String[] columnNames = {
      "Route #", "Carrier", "Dep. Airport", "Dep. Time", "Arr. Airport", "Arr. Time", "Price"
    };
    JScrollPane routeTable =
        new JScrollPane(
            new JTable(data, columnNames) {
              public boolean isCellEditable(int rowIndex, int vColIndex) {
                return false;
              };
            });
    // create the routes table in a scrollPane
    routeTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    routeTable.setPreferredSize(new Dimension(resultsPanelWidth, resultsPanelHeight));
    resultsPanel.add(routeTable); // add the table to the JPanel
    resultsPanel.setBorder(BorderFactory.createTitledBorder("Search Results"));

    // display new route table
    resultsPanel.revalidate();
    resultsPanel.repaint();
  }
Esempio n. 4
0
  protected void moveBall() {
    // System.out.println("I'm in the moveBall() function!");
    int width = getWidth();
    int height = getHeight();
    int min, max, randomX, randomY;
    min = 0;
    max = 200;
    randomX = min + (int) (Math.random() * ((max - min) + 1));
    randomY = min + (int) (Math.random() * ((max - min) + 1));
    // System.out.println(randomX + ", " + randomY);

    Rectangle ballBounds = ball.getBounds();
    //      //System.out.println(ballBounds.x + ", " + ballBounds.y);
    //      if (ballBounds.x + randomX < 0) {
    //          randomX = 200;
    //      } else if (ballBounds.x + ballBounds.width + randomX > width) {
    //          randomX = -200;
    //      }
    //      if (ballBounds.y + randomY < 0) {
    //          randomY = 200;
    //      } else if (ballBounds.y + ballBounds.height + randomY > height) {
    //          randomY = -200;
    //      }

    ballBounds.x = randomX;
    ballBounds.y = randomY;
    _ballXpos = ballBounds.x;
    _ballYpos = ballBounds.y;
    ball.setFrame(ballBounds);
    thePlacebo.repaint();
  }
  private void buildExternalsPanel() {

    FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:pref:grow", "p"));
    int row = 1;
    for (ExternalFileEntry efe : externals) {
      builder.add(efe.getPanel()).xy(1, row);
      builder.appendRows("2dlu, p");
      row += 2;
    }
    builder.add(Box.createVerticalGlue()).xy(1, row);
    builder.appendRows("2dlu, p, 2dlu, p");
    builder.add(addExtPan).xy(1, row + 2);
    builder.add(Box.createVerticalGlue()).xy(1, row + 2);

    // builder.getPanel().setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.green));
    // externalFilesPanel.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
    JScrollPane pane = new JScrollPane(builder.getPanel());
    pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    externalFilesPanel.setMinimumSize(new Dimension(400, 400));
    externalFilesPanel.setPreferredSize(new Dimension(400, 400));
    externalFilesPanel.removeAll();
    externalFilesPanel.add(pane, BorderLayout.CENTER);
    externalFilesPanel.revalidate();
    externalFilesPanel.repaint();
  }
Esempio n. 6
0
 public static void drawImage(int[][][] pixels, int startX, int startY) {
   // Key idea: draw a bunch (lots of rectangles) with the appropriate color
   DrawObject R = new DrawObject();
   R.pixels = pixels;
   R.startX = startX;
   R.startY = startY;
   R.sequenceNum = currentSequenceNum;
   images.add(R);
   // Rescale if needed.
   int leftX = startX;
   int rightX = startX + pixels.length;
   int lowY = startY;
   int highY = startY + pixels[0].length;
   if (minX > leftX) {
     minX = leftX;
   }
   if (maxX < rightX) {
     maxX = rightX;
   }
   if (minY > lowY) {
     minY = lowY;
   }
   if (maxY < highY) {
     maxY = highY;
   }
   drawArea.repaint();
 }
Esempio n. 7
0
 static void handleMouseClick(MouseEvent e) {
   double midX = (maxX + minX) / 2;
   double midXDist = midX - minX;
   double midY = (maxY + minY) / 2;
   double midYDist = midY - minY;
   // See if any of the navigation icons were under the mouse.
   if (withinBounds(e.getX(), e.getY(), D.width - 20, D.width - 15, 10, 20)) {
     // Plus.
     setXYRange(minX, midX, minY, midY);
   } else if (withinBounds(e.getX(), e.getY(), D.width - 20, D.width - 15, 40, 50)) {
     // Minus.
     setXYRange(minX, 2 * maxX, minY, 2 * maxY);
   } else if (withinBounds(e.getX(), e.getY(), D.width - 75, D.width - 65, 0, 20)) {
     //
     setXYRange(minX, maxX, minY + midYDist, maxY + midYDist);
   } else if (withinBounds(e.getX(), e.getY(), D.width - 75, D.width - 65, 30, 50)) {
     //
     setXYRange(minX, maxX, minY - midYDist, maxY - midYDist);
   } else if (withinBounds(e.getX(), e.getY(), D.width - 65, D.width - 45, 20, 30)) {
     //
     setXYRange(minX + midXDist, maxX + midXDist, minY, maxY);
   } else if (withinBounds(e.getX(), e.getY(), D.width - 95, D.width - 75, 20, 30)) {
     //
     setXYRange(minX - midXDist, maxX - midXDist, minY, maxY);
   }
   drawArea.repaint();
 }
Esempio n. 8
0
  public void drawPanel() {
    try {
      // System.out.println("right before the while loop of the thread");
      // layeredPane.add(background,99);

      panel.remove(layeredPane);
      Iterator<PlayerMob> allPlayers = players.iterator();
      PlayerMob aPlayer = null;
      /*while(allPlayers.hasNext()){
      	aPlayer = (PlayerMob) allPlayers.next();
      	//System.out.println("INTHELOOP:info.getUsername ="******" myChat.getUsername ="******"for loop index catch");
      	continue;
      }*/

    } catch (NullPointerException ed) {
      System.err.println("for loop null catch");
      // startDrawingPanelThread();
    } catch (Exception ev) {
      System.err.println("for loop catch");
      ev.printStackTrace();
    }
  }
Esempio n. 9
0
 static void handleMouseDragged(MouseEvent e) {
   DrawObject L = new DrawObject();
   L.scribbleX = e.getX();
   L.scribbleY = e.getY();
   L.scribbleNum = currentScribbleNum;
   scribbles.add(L);
   drawArea.repaint();
 }
 public void setValue(String key, JComponent value) {
   JPanel p = keyValueComponentMap.get(key);
   p.removeAll();
   p.add(value);
   p.add(Box.createHorizontalGlue());
   p.repaint();
   p.getParent().repaint();
 }
Esempio n. 11
0
 static void handleKeyTyped(KeyEvent e) {
   if (e.getKeyChar() == ' ') {
     currentSequenceNumDisplay++;
     scribbles = Collections.synchronizedList(new ArrayList<DrawObject>());
     currentScribbleNum = 0;
   }
   drawArea.repaint();
 }
Esempio n. 12
0
  private void repaintContent() {
    if (content != null) {
      remove(content);
    }
    content = new JPanel();

    content.setLayout(new GridBagLayout());
    content.setBackground(Colors.TEMPLATE);
    int gridY = 0;
    GridBagConstraints c;
    for (Parameter p : shownParams.getParamList()) {
      c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = gridY;
      c.anchor = GridBagConstraints.WEST;
      c.fill = GridBagConstraints.NONE;
      c.insets = new Insets(0, 0, 0, 8);
      content.add(new JLabel(p.getName()), c);

      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = gridY++;
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1;
      final Parameter pFinal = p;
      final JTextField jTextField = new DJTextField();
      jTextField.setText(p.getValue());
      jTextField.addKeyListener(
          new KeyListener() {
            public void keyTyped(KeyEvent keyEvent) {
              // TODO
            }

            public void keyPressed(KeyEvent keyEvent) {
              // TODO
            }

            public void keyReleased(KeyEvent keyEvent) {
              pFinal.setValue(jTextField.getText());
            }
          });
      content.add(jTextField, c);
    }

    GridBagConstraints nc = new GridBagConstraints();
    nc.gridx = 0;
    nc.gridy = 0;
    nc.weightx = 1;
    nc.fill = GridBagConstraints.HORIZONTAL;

    add(content, nc);

    content.updateUI();
    content.repaint();
    this.repaint();
  }
Esempio n. 13
0
 /**
  * Remove the currently display gui and insert the given one.
  *
  * @param comp The new gui.
  */
 private void addToContents(JComponent comp) {
   handlerHolder.removeAll();
   comp.setPreferredSize(new Dimension(200, 300));
   handlerHolder.add(comp, BorderLayout.CENTER);
   if (myContents != null) {
     myContents.invalidate();
     myContents.validate();
     myContents.repaint();
   }
 }
 /** Listener to handle button actions */
 public void actionPerformed(ActionEvent e) {
   // Check if the user pressed the remove button
   if (e.getSource() == remove_button) {
     int row = table.getSelectedRow();
     model.removeRow(row);
     table.clearSelection();
     table.repaint();
     valueChanged(null);
   }
   // Check if the user pressed the remove all button
   if (e.getSource() == remove_all_button) {
     model.clearAll();
     table.setRowSelectionInterval(0, 0);
     table.repaint();
     valueChanged(null);
   }
   // Check if the user pressed the filter button
   if (e.getSource() == filter_button) {
     filter.showDialog();
     if (filter.okPressed()) {
       // Update the display with new filter
       model.setFilter(filter);
       table.repaint();
     }
   }
   // Check if the user pressed the start button
   if (e.getSource() == start_button) {
     start();
   }
   // Check if the user pressed the stop button
   if (e.getSource() == stop_button) {
     stop();
   }
   // Check if the user wants to switch layout
   if (e.getSource() == layout_button) {
     details_panel.remove(details_soap);
     details_soap.removeAll();
     if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
       details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
     } else {
       details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
     }
     details_soap.setTopComponent(request_panel);
     details_soap.setRightComponent(response_panel);
     details_soap.setResizeWeight(.5);
     details_panel.add(details_soap, BorderLayout.CENTER);
     details_panel.validate();
     details_panel.repaint();
   }
   // Check if the user is changing the reflow option
   if (e.getSource() == reflow_xml) {
     request_text.setReflowXML(reflow_xml.isSelected());
     response_text.setReflowXML(reflow_xml.isSelected());
   }
 }
 private void resetPanel() {
   cal =
       new GregorianCalendar(
           Integer.parseInt(yearSpi.getValue().toString()),
           monthBox.getSelectedIndex(),
           Integer.parseInt(lastLabel.getText()));
   startPoint_x = 20;
   startPoint_y = 10;
   panel.removeAll();
   panel.repaint();
   initCalPanel();
 }
Esempio n. 16
0
 public void removeElement(PanelElementAbstract b) {
   int idx = panelElements.indexOf(b);
   if (idx >= 0) {
     panelElements.remove(idx);
     listPanel.remove(b.getPanel());
     listLayout.setRows(Math.max(panelElements.size() + 1, minNbRows));
     listPanel.revalidate();
     listPanel.repaint();
     setAddButtonColor();
     if (ml != null) b.unRegister(ml);
     for (int i = idx; i < panelElements.size(); i++) panelElements.get(i).setIdx(idx);
   }
 }
  private void showHelp(String help[]) {

    txtCommand.setText(help[0]);

    bHelp = true;

    pResult.removeAll();
    pResult.add(txtResultScroll, BorderLayout.CENTER);
    pResult.doLayout();
    txtResult.setText(help[1]);
    pResult.repaint();
    txtCommand.requestFocus();
    txtCommand.setCaretPosition(help[0].length());
  }
Esempio n. 18
0
 public static void drawLineFromEquation(double a, double b, double c) {
   // Draw the equation ax+by+c=0 in the available range.
   DrawObject L = new DrawObject();
   L.color = lineEqnColor;
   L.a = a;
   L.b = b;
   L.c = c;
   L.sequenceNum = currentSequenceNum;
   L.drawStroke = drawStroke;
   synchronized (eqnLines) {
     eqnLines.add(L);
   }
   drawArea.repaint();
 }
Esempio n. 19
0
  public void PlaneRemove(Plane p) {
    char id = p.getIdChar();
    UIPlane uiplane = null;
    synchronized (this) {
      uiplane = (UIPlane) (planes.get((Object) (new Character(id))));
    }
    if (uiplane == null) return;

    if (uiplane.radar_label != null) radarArea.remove(uiplane.radar_label);
    if (uiplane.info_label != null) infoArea.remove(uiplane.info_label);
    synchronized (this) {
      planes.remove((Object) (new Character(id)));
    }

    radarArea.repaint();
    infoArea.repaint();
  }
Esempio n. 20
0
 public static void drawLabel(double x, double y, String str) {
   DrawObject L = new DrawObject();
   L.color = labelColor;
   L.x = x;
   L.y = y;
   L.str = str;
   L.sequenceNum = currentSequenceNum;
   if (animationMode) {
     synchronized (animLabels) {
       animLabels.add(L);
     }
   } else {
     synchronized (labels) {
       labels.add(L);
     }
   }
   drawArea.repaint();
 }
Esempio n. 21
0
 public static void drawPoint(double x, double y) {
   DrawObject p = new DrawObject();
   p.color = pointColor;
   p.x = x;
   p.y = y;
   p.diameter = pointDiameter;
   p.sequenceNum = currentSequenceNum;
   if (animationMode) {
     synchronized (animPoints) {
       animPoints.add(p);
     }
   } else {
     synchronized (points) {
       points.add(p);
     }
   }
   drawArea.repaint();
 }
  TimerControls(ControlBar creator) {
    parent = creator;
    super.setPreferredSize(new Dimension(200, 172));
    setLayout(new BorderLayout());

    pausePlay = new JButton("Play");
    speed = makeJSlider();

    pausePlay.addActionListener(this);
    speed.addChangeListener(this);

    super.add(pausePlay, BorderLayout.WEST);
    super.add(speed, BorderLayout.EAST);
    super.add(new JLabel(" Simulation Speed Controls"), BorderLayout.NORTH);

    super.repaint();
    super.setVisible(true);
  }
Esempio n. 23
0
  public void chat(JPanel panel) {
    this.panel = panel;
    userInterface = new UI(player);
    userInterface.chat(panel);

    AddKeyListener keyListener = new AddKeyListener();
    keyListener.setPlayer(player);

    keyListenerLayer = new JLayeredPane();
    keyListenerLayer.add(keyListener, 10);

    panel.add(BorderLayout.CENTER, keyListenerLayer);
    keyListener.setFocusable(true);
    keyListener.requestFocusInWindow();

    panel.add(BorderLayout.CENTER, layeredPane);
    panel.add(BorderLayout.SOUTH, userInterface.getChatPanel());
    panel.validate();
    panel.repaint();

    // initialize
    networkStartup.InGameChatInitialize(userInterface.getOutgoing(), userInterface.getIncoming());

    panel.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            keyListener.setFocusable(true);
            keyListener.requestFocusInWindow();
          }
        });

    userInterface
        .getOutgoing()
        .addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                networkStartup.InGameChatSendButtonListener(
                    userInterface.getOutgoing(), userInterface.getIncoming());
              }
            });

    // startDrawingPanelThread();

  }
  ControlBar(MainWindow creator) {
    parent = creator;

    super.setPreferredSize(new Dimension(720, 172));
    setLayout(new BorderLayout());

    // add timer, save, and heatmap controls to the bar

    tc = new TimerControls(this);
    sc = new SaveControls(parent.getGrid(), this);
    hc = new HeatMapControls(this);
    add(tc, BorderLayout.WEST);
    add(hc, BorderLayout.CENTER);
    add(sc, BorderLayout.EAST);

    super.repaint();
    super.setVisible(true);
    System.out.println("Done Constucting");
  }
  /** Handle ui components events. */
  public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(saveButton)) {

      // fileChooser.setTitle("Save File");
      // fileChooser.setFilenameFilter(new InputFilterAWT());
      // fileChooser.setVisible(true);
      // fileChooser.setMode(FileDialog.SAVE);
      // OutputComposer excelComp = OutputComposer.create(Network.FileType.EXCEL_FILE);

      saveEvent();
    } else if (e.getSource().equals(openINPButton)) {
      openEvent();
    } else if (e.getSource().equals(runSimulationButton)) {
      runSimulation();
    } else if (e.getSource() == logoB) {
      browse(AWARE_P_WEBLINK);
    }
    network.repaint();
  }
  SaveControls(Grid currentGrid, ControlBar creator) {
    parent = creator;
    grid = currentGrid;
    super.setPreferredSize(new Dimension(200, 172));
    setLayout(new GridLayout(3, 0));

    fileName = new JTextField("SaveName");
    save = new JButton("Save");
    load = new JButton("Load");

    save.addActionListener(this);
    load.addActionListener(this);

    super.add(fileName);
    super.add(save);
    super.add(load);

    super.repaint();
    super.setVisible(true);
  }
Esempio n. 27
0
 public static void drawRectangle(double x1, double y1, double width, double height) {
   DrawObject R = new DrawObject();
   R.color = rectangleColor;
   R.x = x1;
   R.y = y1;
   R.width = width;
   R.height = height;
   R.sequenceNum = currentSequenceNum;
   R.drawStroke = drawStroke;
   if (animationMode) {
     synchronized (animRectangles) {
       animRectangles.add(R);
     }
   } else {
     synchronized (rectangles) {
       rectangles.add(R);
     }
   }
   drawArea.repaint();
 }
  private void updateResult() {

    if (iResult == 0) {

      // in case 'help' has removed the grid
      if (bHelp) {
        pResult.removeAll();
        pResult.add(gScrollPane, BorderLayout.CENTER);
        pResult.doLayout();
        gResult.fireTableChanged(null);
        pResult.repaint();

        bHelp = false;
      }
    } else {
      showResultInText();
    }

    txtCommand.selectAll();
    txtCommand.requestFocus();
  }
Esempio n. 29
0
 public static void drawLine(double x1, double y1, double x2, double y2, boolean isArrow) {
   DrawObject L = new DrawObject();
   L.color = lineColor;
   L.x = x1;
   L.y = y1;
   L.x2 = x2;
   L.y2 = y2;
   if (isArrow) {
     L.color = arrowColor;
     L.isArrow = true;
   }
   L.sequenceNum = currentSequenceNum;
   L.drawStroke = drawStroke;
   if (animationMode) {
     synchronized (animLines) {
       animLines.add(L);
     }
   } else {
     synchronized (lines) {
       lines.add(L);
     }
   }
   drawArea.repaint();
 }
 public void clear() {
   upgradePanel.removeAll();
   upgradePanel.add(doneButton);
   upgradePanel.add(cancelButton);
   upgradePanel.repaint();
 }