Exemple #1
0
  public void StaticObjNew(StaticObj so) {
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setColor(so_color);

    if (so instanceof Beacon) {
      g.drawOval(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Airfield) {
      int xa[] = new int[3], ya[] = new int[3];
      int l1 = grid_size / 2, l2 = grid_size / 6;
      xa[0] = convPos(so.pos.x);
      ya[0] = convPos(so.pos.y);
      xa[1] = convPos(so.pos.x) - l1 * so.dir.x - l2 * so.dir.y;
      ya[1] = convPos(so.pos.y) - l1 * so.dir.y + l2 * so.dir.x;
      xa[2] = convPos(so.pos.x) - l1 * so.dir.x + l2 * so.dir.y;
      ya[2] = convPos(so.pos.y) - l1 * so.dir.y - l2 * so.dir.x;
      g.drawPolygon(xa, ya, 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Exit) {
      g.drawRect(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Line) {
      g.setColor(line_color);
      g.drawLine(
          convPos(((Line) so).pos.x),
          convPos(((Line) so).pos.y),
          convPos(((Line) so).second_end.x),
          convPos(((Line) so).second_end.y));
    }

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back.setIcon(radarArea.backIcon);
  }
Exemple #2
0
  public void initUI(int x, int y) {
    setVisible(true);

    loadIcons();

    dx = x;
    dy = y;
    text_height = getFontMetrics(getFont()).getHeight();
    plane_width = icon_size;
    plane_height = icon_size + text_height + text_gap;
    radar_area_width = grid_size * dx;
    radar_area_height = grid_size * dy;

    getContentPane().setLayout(new BorderLayout());

    radarArea = new RadarPane();
    radarArea.setMinimumSize(new Dimension(radar_area_width, radar_area_height));
    radarArea.setPreferredSize(new Dimension(radar_area_width, radar_area_height));
    getContentPane().add(radarArea, BorderLayout.CENTER);

    radarArea.backImage =
        new BufferedImage(radar_area_width, radar_area_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setBackground(back_color);
    g.setColor(rim_color);
    g.fillRect(0, 0, radar_area_width, radar_area_height);
    g.setColor(back_color);
    g.fillRect(convPos(0), convPos(0), radar_area_width - grid_size, radar_area_height - grid_size);
    g.setColor(line_color);
    int i, j;
    for (i = 0; i < dx; i++)
      for (j = 0; j < dy; j++) g.draw(new Rectangle(convPos(i) - 1, convPos(j) - 1, 1, 1));

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back = new JLabel(radarArea.backIcon);
    radarArea.back.setBounds(0, 0, radar_area_width, radar_area_height);
    radarArea.add(radarArea.back, new Integer(0));

    infoArea = new JPanel();
    infoArea.setMinimumSize(new Dimension(info_area_width, radar_area_height));
    infoArea.setPreferredSize(new Dimension(info_area_width, radar_area_height));
    infoArea.setLayout(new GridLayout(27, 1));
    infoTopLine = new Label(" ");
    infoArea.add(infoTopLine);
    getContentPane().add(infoArea, BorderLayout.EAST);

    inputArea = new JLabel("          ");
    getContentPane().add(inputArea, BorderLayout.SOUTH);

    controlArea = new JPanel();
    newButton = new JButton("New");
    newButton.setActionCommand("New");
    newButton.addActionListener(this);
    newButton.setEnabled(false);
    newButton.setFocusable(false);
    exitButton = new JButton("Exit");
    exitButton.setActionCommand("Exit");
    exitButton.addActionListener(this);
    exitButton.setFocusable(false);
    controlArea.add(newButton);
    controlArea.add(exitButton);
    getContentPane().add(controlArea, BorderLayout.NORTH);

    pack();
  }