Пример #1
0
  public static void mouseClicked(MouseEvent e) {
    GUI.closeAllMenus();
    if (e.getButton() == MouseEvent.BUTTON1) {
      switch (GUI.getCursor()
          .getName()) // if((this.getCursor().getName().equals("mano")) && (e.getButton() ==
      // MouseEvent.BUTTON1))
      {
        case "mano":
          if (seleccionado == null) {
            GUI.showSelectionMenu(e);
          } else {
            seleccionado.setState(Element.AVAILABLE);
            ;
            seleccionado.paint(panel.getGraphics());
            seleccionado = null;
          }

          break;
        case "lapiz":
          if ((seleccionado != null) && (seleccionado.getState() == Element.GETTINGPOINTS)) {
            System.out.println("desde1");
            seleccionado.setLast(e.getPoint());
            repaint();
          } else {
            GUI.showFigureMenu(e);
          }
          break;
      }
    }
  }
Пример #2
0
 public void move() {
   Graphics g = canvas.getGraphics();
   g.setColor(canvas.getBackground());
   g.fillOval(x, y, XSIZE, YSIZE);
   x += dx;
   y += dy;
   Dimension d = canvas.getSize();
   if (x < 0) {
     x = 0;
     dx = -dx;
   }
   if (x + XSIZE >= d.width) {
     x = d.width - XSIZE;
     dx = -dx;
   }
   if (y < 0) {
     y = 0;
     dy = -dy;
   }
   if (y + YSIZE >= d.height) {
     y = d.height - YSIZE;
     dy = -dy;
   }
   g.setColor(color);
   g.fillOval(x, y, XSIZE, YSIZE);
   g.dispose();
 }
Пример #3
0
  private void updateLevels() {
    Graphics2D g2 = (Graphics2D) panel.getGraphics();
    if (g2 == null) return;
    if (xPos < 10) {
      g2.setColor(Color.BLACK);
      g2.fillRect(0, 0, panel.getWidth(), panel.getHeight());
    }

    int newL = (int) sampleToDB(maxL);
    int newR = (int) sampleToDB(maxR);
    if (newL < -96) newL = -96;
    if (newR < -96) newR = -96;

    //		double db = sampleToDB(maxL);
    //		System.out.println("dB - L: " + newL + " - R: " + newR);
    //		System.out.println("height: " + heightL);
    //		g2.setColor(Color.BLACK);
    //		g2.fillRect(0, 0, panel.getWidth(), panel.getHeight());

    g2.setColor(Color.MAGENTA);
    g2.drawLine(xPos, -(oldL * 2), xPos + 1, -(newL * 2));
    g2.setColor(Color.CYAN);
    g2.drawLine(xPos, -(oldR * 2), xPos + 1, -(newR * 2));
    oldL = newL;
    oldR = newR;
    xPos++;
    if (xPos == panel.getWidth()) {
      xPos = 0;
    }
  }
Пример #4
0
 /** Color a particular square */
 private static void colorSquare(int row, int col, Color color) {
   Graphics g = jPanel0.getGraphics();
   g.setColor(color);
   g.fillRect(marginLeft + gridSize * col, marginTop + gridSize * row, gridSize, gridSize);
   g.setColor(Color.black);
   g.drawRect(marginLeft + gridSize * col, marginTop + gridSize * row, gridSize, gridSize);
 }
Пример #5
0
 private void setGraphicsProperties() {
   graphics = (Graphics2D) mapPanel.getGraphics();
   graphics.setFont(new Font("Tahoma", Font.PLAIN, 8));
   graphics.setStroke(
       new BasicStroke(
           2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2F, new float[] {3f}, 0f));
 }
Пример #6
0
 private static void drawKnight(int row, int col) {
   Graphics g = jPanel0.getGraphics();
   g.setColor(Color.red);
   g.fillOval(
       marginLeft + gridSize * col + gridSize / 2 - 10,
       marginTop + gridSize * row + gridSize / 2 - 10,
       20,
       20);
 }
Пример #7
0
 private static void drawNumber(int row, int col, int num) {
   Graphics g = jPanel0.getGraphics();
   g.setColor(Color.black);
   // drawString draws at the baseline of the specified coordinate.
   // Consider center - a little.
   g.drawString(
       Integer.toString(num),
       marginLeft + gridSize * col + gridSize / 2 - 5,
       marginTop + gridSize * row + gridSize / 2);
 }
Пример #8
0
 public void drawPool(int deepEnd, int shallEnd, int length) {
   Graphics paper = panel.getGraphics();
   paper.setColor(Color.WHITE);
   paper.fillRect(0, 0, 200, 175);
   paper.setColor(Color.BLACK);
   paper.drawLine(50, 50, 50 + length * 15, 50);
   paper.drawLine(50, 50 + deepEnd * 15, 50, 50);
   paper.drawLine(50 + length * 15, 50, 50 + length * 15, 50 + shallEnd * 15);
   paper.drawLine(50, 50 + deepEnd * 15, 50 + length * 15, 50 + shallEnd * 15);
 }
  /**
   * DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  public Dimension getCheckBoxOffset() {
    Graphics g = panel.getGraphics();
    int xoffset = 0;

    if (g != null) {
      try {
        FontMetrics fm = g.getFontMetrics();
        xoffset = fm.stringWidth(getText()) + strut.getPreferredSize().width;
      } finally {
        g.dispose();
      }
    }

    return new Dimension(xoffset, 0);
  }
Пример #10
0
 public static void mouseMoved(MouseEvent e) {
   if (seleccionado != null) {
     switch (seleccionado.getState()) {
       case Element.MOVING:
         seleccionado.move(e.getX(), e.getY());
         break;
       case Element.ROTATING:
         seleccionado.rotate(e.getPoint());
         break;
       case Element.GETTINGPOINTS:
         Point lastPoint = seleccionado.getLast();
         Graphics g = panel.getGraphics();
         g.drawLine(lastPoint.x, lastPoint.y, e.getX(), e.getY() + 30);
         // repaint();
         break;
     }
     repaint();
   }
 }
Пример #11
0
  public void actionPerformed(ActionEvent e) {
    JFrame fileFrame = new JFrame();
    JPanel filePanel = new JPanel();
    JFileChooser fileChooser = new JFileChooser();
    fileFrame.getContentPane().add(filePanel);
    filePanel.add(fileChooser);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int result = fileChooser.showOpenDialog(filePanel);
    if (result != JFileChooser.APPROVE_OPTION) {
      msg = new JLabel("No file selected");
      panel.add(msg);
      return;
    }

    File datafile = fileChooser.getSelectedFile();
    initialized = readFile(datafile);
    panel.update(panel.getGraphics());
    frame.pack();
    frame.setVisible(true);
  }
Пример #12
0
  public Window(Core core) {

    Dimension s = new Dimension((int) (core.getWidth()), (int) (core.getHeight()));
    gameArea = new JPanel();
    gameArea.setPreferredSize(s);
    gameArea.setMaximumSize(s);

    gameArea.setBackground(Color.WHITE);
    gameArea.setFocusable(true);
    gameArea.requestFocusInWindow();

    frame = new JFrame(core.getTitle());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setLayout(new BorderLayout());
    frame.add(gameArea, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.createBufferStrategy(2);
    g = gameArea.getGraphics();
  }
 public void showPage(JPanel _p) {
   mainPanel.removeAll();
   mainPanel.add(_p, BorderLayout.CENTER);
   mainPanel.update(mainPanel.getGraphics());
   VEWController2.this.pack();
 }
Пример #14
0
 public void stopBall() {
   Graphics g = canvas.getGraphics();
   g.setColor(canvas.getBackground());
   g.fillOval(x, y, XSIZE, YSIZE);
   stop = true;
 }
Пример #15
0
 /**
  * @param font
  * @return the font metrics of the specified font
  */
 public FontMetrics getFontMetrics() {
   return trackPanel.getGraphics().getFontMetrics();
 }
Пример #16
0
 /** Clear the entire board */
 private void clearBoard() {
   Graphics g = jPanel0.getGraphics();
   Rectangle bounds = jPanel0.getBounds();
   g.clearRect(0, 0, bounds.width, bounds.height);
 }