コード例 #1
0
ファイル: Main.java プロジェクト: haydenmuhl/fractal
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Fractal");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout layout = new SpringLayout();
    frame.setLayout(layout);

    Orientation nw = new Orientation();
    nw.setOffset(0, 0);
    Orientation sw = new Orientation();
    sw.setOffset(0, regionSize);
    Orientation se = new Orientation();
    se.setOffset(regionSize, regionSize);

    Fractal fractal = new Fractal(regionSize);
    fractal.setOrientations(nw, sw, se);

    layout.putConstraint(SpringLayout.WEST, fractal, 5, SpringLayout.WEST, frame.getContentPane());
    layout.putConstraint(
        SpringLayout.NORTH, fractal, 5, SpringLayout.NORTH, frame.getContentPane());

    layout.putConstraint(SpringLayout.WEST, nw, 5, SpringLayout.EAST, fractal);
    layout.putConstraint(SpringLayout.NORTH, nw, 0, SpringLayout.NORTH, fractal);

    layout.putConstraint(SpringLayout.NORTH, sw, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, sw, 0, SpringLayout.WEST, nw);

    layout.putConstraint(SpringLayout.NORTH, se, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, se, 5, SpringLayout.EAST, sw);

    layout.putConstraint(
        SpringLayout.SOUTH, frame.getContentPane(), 5, SpringLayout.SOUTH, fractal);
    layout.putConstraint(SpringLayout.EAST, frame.getContentPane(), 5, SpringLayout.EAST, se);

    frame.add(nw);
    frame.add(sw);
    frame.add(se);

    frame.add(fractal);

    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
コード例 #2
0
ファイル: Fenetre.java プロジェクト: btrd/BatailleNavale
  private void majgrid1(Player player) {
    gridtest = new Grid();
    gridtest = player.getGridJoueur();

    ShipType type = ShipType.AIRCRAFT_CARRIER;
    Ship ship = new Ship(type);
    Orientation orient = Orientation.HORIZONTAL;
    for (int i = 0; i < 10; i++) // ligne
    {
      for (int j = 0; j < 10; j++) // colonne
      {
        if (gridtest.getCell(i, j) instanceof OceanCell) {
          tabbout1[i][j].setIcon(iconeau);
        }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(iconeautouch);
        //                }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(icondebristouch);
        //                }
        else if (gridtest.getCell(i, j) instanceof ShipCell) {
          ship = ((ShipCell) gridtest.getCell(i, j)).getShip();
          int size = ship.getSize();
          orient = ((ShipCell) gridtest.getCell(i, j)).getOrient();

          if (orient.isHorizontal()) {
            if (ship.getSize() == 2) {
              tabbout1[i][j].setIcon(iconsub1h);
              tabbout1[i][j + 1].setIcon(iconsub2h);
              tabbout1[i][j + 2].setIcon(iconsub3h);
              j = j + 2;

            } else if (ship.getSize() == 3) // battleship
            {
              tabbout1[i][j].setIcon(iconbattle1h);
              tabbout1[i][j + 1].setIcon(iconbattle2h);
              tabbout1[i][j + 2].setIcon(iconbattle3h);
              tabbout1[i][j + 3].setIcon(iconbattle4h);
              j = j + 3;
            } else {
              tabbout1[i][j].setIcon(iconair1h);
              tabbout1[i][j + 1].setIcon(iconair2h);
              tabbout1[i][j + 2].setIcon(iconair3h);
              tabbout1[i][j + 3].setIcon(iconair4h);
              tabbout1[i][j + 4].setIcon(iconair5h);
              j = j + 4;
            }
          }
        }
      }

      for (int i2 = 0; i2 < 10; i2++) // ligne
      {
        for (int j2 = 0; j2 < 10; j2++) // colonne
        {
          if (gridtest.getCell(i2, j2) instanceof ShipCell) {
            ship = ((ShipCell) gridtest.getCell(i2, j2)).getShip();
            orient = ((ShipCell) gridtest.getCell(i2, j2)).getOrient();

            if (!orient.isHorizontal()) {
              if (ship.getSize() == 2) {
                tabbout1[i2][j2].setIcon(iconsub1v);
                tabbout1[i2 + 1][j2].setIcon(iconsub2v);
                tabbout1[i2 + 2][j2].setIcon(iconsub3v);
                i2 = i2 + 2;
              } else if (ship.getSize() == 3) // battleship
              {
                tabbout1[i2][j2].setIcon(iconbattle1v);
                tabbout1[i2 + 1][j2].setIcon(iconbattle2v);
                tabbout1[i2 + 2][j2].setIcon(iconbattle3v);
                tabbout1[i2 + 3][j2].setIcon(iconbattle4v);
                i2 = i2 + 3;
              } else {
                tabbout1[i2][j2].setIcon(iconair1v);
                tabbout1[i2 + 1][j2].setIcon(iconair2v);
                tabbout1[i2 + 2][j2].setIcon(iconair3v);
                tabbout1[i2 + 3][j2].setIcon(iconair4v);
                tabbout1[i2 + 4][j2].setIcon(iconair5v);
                i2 = i2 + 4;
              }
            }
          }
        }
      }
    }
  }