/**
   * Method to display pixel information for the passed x and y
   *
   * @param pictureX the x value in the picture
   * @param pictureY the y value in the picture
   */
  private void displayPixelInformation(int pictureX, int pictureY) {
    // check that this x and y are in range
    if (isLocationInPicture(pictureX, pictureY)) {
      // save the current x and y index
      colIndex = pictureX;
      rowIndex = pictureY;

      // get the pixel at the x and y
      Pixel pixel = new Pixel(picture, colIndex, rowIndex);

      // set the values based on the pixel
      colValue.setText(Integer.toString(colIndex + numberBase));
      rowValue.setText(Integer.toString(rowIndex + numberBase));
      rValue.setText("R: " + pixel.getRed());
      gValue.setText("G: " + pixel.getGreen());
      bValue.setText("B: " + pixel.getBlue());
      colorPanel.setBackground(new Color(pixel.getRed(), pixel.getGreen(), pixel.getBlue()));

    } else {
      clearInformation();
    }

    // notify the image display of the current x and y
    imageDisplay.setCurrentX((int) (colIndex * zoomFactor));
    imageDisplay.setCurrentY((int) (rowIndex * zoomFactor));
  }
Exemplo n.º 2
0
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
 /** Method to clear the labels and current color and reset the current index to -1 */
 private void clearInformation() {
   colValue.setText("N/A");
   rowValue.setText("N/A");
   rValue.setText("R: N/A");
   gValue.setText("G: N/A");
   bValue.setText("B: N/A");
   colorPanel.setBackground(Color.black);
   colIndex = -1;
   rowIndex = -1;
 }
Exemplo n.º 4
0
 public static void writeTopString(String s) {
   if (s == null) {
     return;
   }
   statusLabel.setForeground(Color.black);
   statusLabel.setText("  " + s);
 }
Exemplo n.º 5
0
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    textLabel.setFont(table.getFont());
    textLabel.setText(Objects.toString(value, ""));
    textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder);

    FontMetrics fm = table.getFontMetrics(table.getFont());
    Insets i = textLabel.getInsets();
    int swidth =
        iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right;
    int cwidth = table.getColumnModel().getColumn(column).getWidth();
    dim.width = swidth > cwidth ? cwidth : swidth;

    if (isSelected) {
      textLabel.setOpaque(true);
      textLabel.setForeground(table.getSelectionForeground());
      textLabel.setBackground(table.getSelectionBackground());
      iconLabel.setIcon(sicon);
    } else {
      textLabel.setOpaque(false);
      textLabel.setForeground(table.getForeground());
      textLabel.setBackground(table.getBackground());
      iconLabel.setIcon(nicon);
    }
    return panel;
  }
Exemplo n.º 6
0
  public final void mouseMoved(MouseEvent e) {
    Point p = e.getPoint();

    if (odometer != null) {
      String output = " (" + p.x + ", " + p.y + ")";
      odometer.setText(output);
    }
  }
Exemplo n.º 7
0
 public static void writePrompt(String s) {
   if (s == null) {
     return;
   }
   outputLabel.setForeground(Color.black);
   outputLabel.setText("  " + s);
   hasEntered = false;
 }
Exemplo n.º 8
0
  public void mousePressed(MouseEvent e) {
    Point p = e.getPoint();
    int mods = e.getModifiers();

    if (odometer != null) {
      String output = " (" + p.x + ", " + p.y + ")";
      odometer.setText(output);
    }
  }
Exemplo n.º 9
0
 public void actionPerformed(ActionEvent e) {
   // Invoked when an action occurs.
   if (e.getSource().equals(singleSizeUp)) {
     singleSize = singleSize * 2;
     singleSizeLabel.setText("Image height=" + singleSize);
   }
   if (e.getSource().equals(singleSizeDown)) {
     singleSize = Math.max(64, singleSize / 2);
     singleSizeLabel.setText("Image height=" + singleSize);
   }
   if (e.getSource().equals(seqSizeUp)) {
     seqSize = seqSize * 2;
     seqSizeLabel.setText("Image height=" + seqSize);
   }
   if (e.getSource().equals(seqSizeDown)) {
     seqSize = Math.max(64, seqSize / 2);
     seqSizeLabel.setText("Image height=" + seqSize);
   }
 }
Exemplo n.º 10
0
  public final JLabel getOdometer() {
    if (odometer == null) {
      odometer = new JLabel();
      odometer.setVerticalAlignment(SwingConstants.CENTER);
      odometer.setHorizontalAlignment(SwingConstants.LEFT);
      odometer.setText(" ");
      addMouseListener(this);
      addMouseMotionListener(this);
    }

    return odometer;
  }
Exemplo n.º 11
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) {
    }
  }
 void connectionFailed() {
   login.setEnabled(true);
   logout.setEnabled(false);
   // whoIsIn.setEnabled(false);
   chatStatus.setText("Please login first");
   chatField.setText("");
   // reset port number and host name as a construction time
   tfPort.setText("" + defaultPort);
   tfServer.setText(defaultHost);
   // let the user change them
   tfServer.setEditable(false);
   tfPort.setEditable(false);
   // don't react to a <CR> after the username
   chatField.removeActionListener(this);
   connected = false;
 }
  public void validAuthenticate() {
    chatStatus.setText("Enter your message below");
    connected = true;

    // disable login button
    login.setEnabled(false);
    // enable the 2 buttons
    logout.setEnabled(true);
    // whoIsIn.setEnabled(true);
    // disable the Server and Port JTextField
    tfServer.setEditable(false);
    tfPort.setEditable(false);
    // Action listener for when the user enter a message
    chatField.addActionListener(this);

    switchCards("Menu");
  }
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
Exemplo n.º 15
0
 public void CommandUpdate(String cmd_str) {
   inputArea.setText(cmd_str);
 }
Exemplo n.º 16
0
 public void showLoginFailed() {
   loginTitle.setForeground(Color.red);
   loginTitle.setText("Cont nerecunoscut");
 }