コード例 #1
0
 // Set up the quiz window
 Quiz() {
   initializeData();
   setTitle("FOSS Quiz App");
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setSize(440, 400);
   setLocation(300, 100);
   setResizable(true);
   Container cont = getContentPane();
   cont.setLayout(null);
   cont.setBackground(Color.WHITE);
   bg = new ButtonGroup();
   choice1 = new JRadioButton("Choice1", true);
   choice2 = new JRadioButton("Choice2", false);
   choice3 = new JRadioButton("Choice3", false);
   choice4 = new JRadioButton("Choice4", false);
   bg.add(choice1);
   bg.add(choice2);
   bg.add(choice3);
   bg.add(choice4);
   lblmess = new JLabel("Choose a correct anwswer");
   lblmess.setForeground(Color.BLACK);
   lblmess.setFont(new Font("Sans_Serif", Font.BOLD, 15));
   btnext = new JButton("Next");
   btnext.setForeground(Color.WHITE);
   btnext.setFont(new Font("Sans_Serif", Font.BOLD, 17));
   btnext.setBackground(Color.DARK_GRAY);
   btnext.addActionListener(this);
   panel = new JPanel();
   panel.setBackground(Color.WHITE);
   panel.setLocation(10, 60);
   panel.setSize(400, 300);
   panel.setLayout(new GridLayout(0, 1));
   title = new JPanel();
   title.setBackground(Color.WHITE);
   title.setLocation(10, 10);
   title.setSize(1000, 50);
   title.setLayout(new GridLayout(1, 0));
   title.add(lblmess);
   panel.add(choice1);
   panel.add(choice2);
   panel.add(choice3);
   panel.add(choice4);
   panel.add(btnext);
   cont.add(title);
   cont.add(panel);
   setVisible(true);
   quizAnswerID = 0;
   readQuestionAnswer(quizAnswerID);
 }
コード例 #2
0
  protected void layout1280() {
    // Resolution of the camera pictures divided by 2

    // 320x240, Creative camera for layout1280
    size_x = 320 / 2;
    size_y = 240 / 2;
    sizeCaptureWindow_x = size_x * 2;
    sizeCaptureWindow_y = size_y * 2;

    imagepanels = new WebcamCaptureAndFadeImagePanel[4];
    imagepanels[0] = new WebcamCaptureAndFadeImagePanel(3, 8, size_x, size_y);
    imagepanels[1] = new WebcamCaptureAndFadeImagePanel(2, 3, size_x, size_y);
    imagepanels[2] = new WebcamCaptureAndFadeImagePanel(2, 3, size_x, size_y);
    imagepanels[3] = new WebcamCaptureAndFadeImagePanel(3, 8, size_x, size_y);

    setLayout(new BorderLayout());
    setSize((4 + 2 + 4) * size_x, (6) * size_y);

    add(imagepanels[0], BorderLayout.WEST);

    JPanel middle = new JPanel(new BorderLayout());
    middle.add(imagepanels[1], BorderLayout.NORTH);
    if ((comp = player.getVisualComponent()) != null) {
      middle.add(comp, BorderLayout.CENTER);
    }
    middle.add(imagepanels[2], BorderLayout.SOUTH);
    middle.setSize(new Dimension(4 * size_x, 2 * size_y));
    add(middle, BorderLayout.CENTER);

    add(imagepanels[3], BorderLayout.EAST);

    enable_datetext = false;
    enable_forceNewImage = false;
    captureWindow = false;

    txt_location_x = txt_location_y = 0;
    txt_size_x = 18;
    txt_size_y = size_y;
  }
コード例 #3
0
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
コード例 #4
0
  private void setupComponents() {
    panel.removeAll();

    JScrollPane scrollPane1 =
        new JScrollPane(
            parametersTable,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane1.setOpaque(false);

    ActionPanel actionPanel1 = new ActionPanel(false);
    actionPanel1.setAddAction(addParameterAction);
    actionPanel1.setRemoveAction(removeParameterAction);
    actionPanel1.setAddToolTipText("Use this button to add an existing parameter to the prior");
    actionPanel1.setRemoveToolTipText("Use this button to remove a parameter from the prior");

    removeParameterAction.setEnabled(false);

    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.setOpaque(false);
    controlPanel1.add(actionPanel1);

    JPanel panel1 = new JPanel(new BorderLayout(0, 0));
    panel1.setOpaque(false);
    panel1.add(new JLabel("Linked parameters:"), BorderLayout.NORTH);
    panel1.add(scrollPane1, BorderLayout.CENTER);

    // removing the control panel for now. Not sure whether we really want adding and
    // removing of parameteres in this dialog.
    //        panel1.add(controlPanel1, BorderLayout.SOUTH);
    panel1.setSize(new Dimension(PREFERRED_TABLE_WIDTH, PREFERRED_TABLE_HEIGHT));
    panel1.setPreferredSize(new Dimension(PREFERRED_TABLE_WIDTH, PREFERRED_TABLE_HEIGHT));
    panel1.setMinimumSize(new Dimension(MINIMUM_TABLE_WIDTH, MINIMUM_TABLE_HEIGHT));

    OptionsPanel optionsPanel = new OptionsPanel(0, 6);
    if (parameter.getName() != null) {
      nameField.setText(parameter.getName());
    } else {
      nameField.setText("Untitled");
    }
    optionsPanel.addComponentWithLabel("Unique Name: ", nameField);
    //        optionsPanel.addComponentWithLabel("Initial Value: ", initialField);

    panel.setOpaque(false);
    panel.setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 0;
    c.anchor = GridBagConstraints.PAGE_START;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = 2;
    panel.add(optionsPanel, c);

    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.PAGE_START;
    c.fill = GridBagConstraints.VERTICAL;
    c.gridwidth = 1;
    panel.add(panel1, c);

    c.gridx = 1;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.PAGE_START;
    c.gridwidth = GridBagConstraints.REMAINDER;
    panel.add(priorSettingsPanel, c);
  }
コード例 #5
0
ファイル: StartChess.java プロジェクト: Vitvicky/java
  public void launchChess() {

    mainWindow = new JFrame("网络黑白棋	作者:张炀");
    jpWest = new JPanel();
    jpEast = new JPanel();
    jpNorth = new JPanel();
    jpSouth = new JPanel();
    jpCenter = new JPanel();

    turnLabel = new JLabel();
    blackNumberLabel = new JLabel("黑棋:\n" + black + "		");
    whiteNumberLabel = new JLabel("白棋:\n" + white + "		");
    timeLabel = new JLabel("时间:  " + time + "		s");
    noticeLabel = new JLabel();

    noticeLabel = new JLabel("请选择:");
    numberPane = new JPanel();
    readyPane = new JPanel();
    jt1 = new JTextField(18); // 发送信息框
    jt2 = new JTextArea(3, 30); // 显示信息框
    js = new JScrollPane(jt2);
    jt2.setLineWrap(true);
    jt2.setEditable(false);
    //		jt1.setLineWrap(true);

    send = new JButton("发送");
    cancel = new JButton("取消");
    regret = new JButton("悔棋");
    submit = new JButton("退出");
    begin = new JButton("开始");
    save = new JButton("存盘");

    save.setEnabled(true);
    begin.setEnabled(true);

    fighter = new JRadioButton("下棋");
    audience = new JRadioButton("观看");
    group = new ButtonGroup();
    group.add(audience);
    group.add(fighter);
    group.add(AIPlayer);

    submit.addActionListener(this);
    begin.addActionListener(this);
    save.addActionListener(this);
    send.addActionListener(this);
    cancel.addActionListener(this);
    regret.addActionListener(this);
    fighter.addActionListener(this);
    audience.addActionListener(this);

    jpNorth.setLayout(new BorderLayout());
    jpNorth.add(turnLabel, BorderLayout.NORTH);
    jpNorth.add(jpCenter, BorderLayout.CENTER);
    jpSouth.add(js);
    jpSouth.add(jt1);
    jpSouth.add(send);
    jpSouth.add(cancel);
    jpEast.setLayout(new GridLayout(3, 1));
    submit.setBackground(new Color(130, 251, 241));
    panel x = new panel();
    jpEast.add(x);
    jpEast.add(numberPane);
    jpEast.add(readyPane);

    numberPane.add(blackNumberLabel);
    numberPane.add(whiteNumberLabel);
    numberPane.add(timeLabel);
    numberPane.add(submit);
    numberPane.add(begin);
    numberPane.add(save);
    numberPane.add(regret);

    readyPane.add(noticeLabel);
    readyPane.add(fighter);
    readyPane.add(audience);
    //		readyPane.add(save);
    //		readyPane.add(regret);

    jpCenter.setSize(400, 400);
    jmb = new JMenuBar();
    document = new JMenu("游戏		");
    edit = new JMenu("设置		");
    insert = new JMenu("棋盘			");
    help = new JMenu("帮助		");
    jmb.add(document);
    jmb.add(edit);
    jmb.add(insert);
    jmb.add(help);
    // mainWindow.setJMenuBar(jmb);

    mainWindow.setBounds(80, 80, 600, 600);
    mainWindow.setResizable(false);

    jsLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jpNorth, jpSouth);
    jsBase = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jsLeft, jpEast);

    mainWindow.add(jsBase);
    mainWindow.setVisible(true);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jsBase.setDividerLocation(0.7);
    jsLeft.setDividerLocation(0.78);

    jpCenter.setLayout(new GridLayout(8, 8, 0, 0));
    ImageIcon key = new ImageIcon("chess1.jpg");
    for (int i = 0; i < cell.length; i++)
      for (int j = 0; j < cell.length; j++) {
        cell[i][j] = new ChessBoard(i, j);
        cell[i][j].addMouseListener(this);
        jpCenter.add(cell[i][j]);
      }

    cell[3][3].state = cell[4][4].state = '黑';
    cell[4][3].state = cell[3][4].state = '白';
    cell[3][3].taken = cell[4][4].taken = true;
    cell[4][3].taken = cell[3][4].taken = true;

    RememberState();

    new Thread(new TurnLabel(this)).start();

    file = new File("D:/" + myRole);
    try {
      fout = new FileOutputStream(file);
      out = new ObjectOutputStream(fout);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    Connect();

    try {
      out99 = new ObjectOutputStream(socket99.getOutputStream());
      in99 = new ObjectInputStream(socket99.getInputStream());

      out66 = new ObjectOutputStream(socket66.getOutputStream());
      in66 = new ObjectInputStream(socket66.getInputStream());

      out88 = new DataOutputStream(socket88.getOutputStream());
    } catch (IOException e) {
      e.printStackTrace();
    }

    new Thread(new Client9999(this)).start();
    new Thread(new Client6666(this)).start();
  }
コード例 #6
0
  /**
   * setupNoLandPermPanel.
   *
   * @param p a {@link javax.swing.JPanel} object.
   * @param list a {@link java.util.ArrayList} object.
   * @param stack a boolean.
   */
  private static void setupNoLandPermPanel(JPanel p, ArrayList<Card> list, boolean stack) {

    int maxY = 0;
    int maxX = 0;

    Card c;

    if (stack) {
      // add all Cards in list to the GUI, add arrows to Local Enchantments

      ArrayList<Card> planeswalkers = getPlaneswalkers(list);
      ArrayList<Card> equippedEnchantedCreatures =
          getEquippedEnchantedCreatures(
              list); // this will also fetch the equipment and/or enchantment
      ArrayList<Card> nonTokenCreatures = getNonTokenCreatures(list);
      ArrayList<Card> tokenCreatures = getTokenCreatures(list);

      // sort tokenCreatures by name (TODO: fix the warning message somehow)
      Collections.sort(
          tokenCreatures,
          new Comparator<Card>() {
            public int compare(Card c1, Card c2) {
              return c1.getName().compareTo(c2.getName());
            }
          });

      ArrayList<Card> artifacts = getNonCreatureArtifacts(list);
      ArrayList<Card> enchantments = getGlobalEnchantments(list);
      // ArrayList<Card> nonBasics = getNonBasics(list);

      list = new ArrayList<Card>();
      list.addAll(planeswalkers);
      list.addAll(equippedEnchantedCreatures);
      list.addAll(nonTokenCreatures);
      list.addAll(tokenCreatures);
      list.addAll(artifacts);
      list.addAll(enchantments);

      int atInStack = 0;

      int marginX = 5;
      int marginY = 5;

      int x = marginX;

      int cardOffset = Constant.Runtime.stackOffset[0];

      String color = "";
      ArrayList<JPanel> cards = new ArrayList<JPanel>();

      ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>();

      boolean nextEquippedEnchanted = false;
      int nextXIfNotStacked = 0;
      Card prevCard = null;
      for (int i = 0; i < list.size(); i++) {
        JPanel addPanel;
        c = list.get(i);
        addPanel = new CardPanel(c);

        boolean startANewStack = false;

        if (!isStackable(c)) {
          startANewStack = true;
        } else {
          String newColor = c.getName(); // CardUtil.getColor(c);

          if (!newColor.equals(color)) {
            startANewStack = true;
            color = newColor;
          }
        }

        if (i == 0) {
          startANewStack = false;
        }

        if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) {
          startANewStack = true;
        }

        if ((c.isEquipment() || c.isAura())
            && (c.isEquipping() || c.isEnchanting())
            && !nextEquippedEnchanted) startANewStack = false;
        else if ((c.isEquipment() || c.isAura()) && (c.isEquipping() || c.isEnchanting())) {
          startANewStack = true;
          nextEquippedEnchanted = false;
        }

        if (c.isCreature() && (c.isEquipped() || c.isEnchanted())) {
          startANewStack = false;
          nextEquippedEnchanted = true;
        }
        // very hacky, but this is to ensure equipment stacking occurs correctly when a token is
        // equipped/enchanted, and there are more tokens of that same name
        else if ((prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && (prevCard.isEquipped() || prevCard.isEnchanted())
            && prevCard.getName().equals(c.getName()))) startANewStack = true;
        else if (prevCard != null
            && c.isCreature()
            && prevCard.isCreature()
            && !prevCard.getName().equals(c.getName())) startANewStack = true;

        if (((c.isAura() && c.isEnchanting()) || (c.isEquipment() && c.isEquipping()))
            && prevCard != null
            && prevCard.isPlaneswalker()) startANewStack = true;

        if (startANewStack) {
          setupConnectedCards(connectedCards);
          connectedCards.clear();

          // Fixed distance if last was a stack, looks a bit nicer
          if (atInStack > 1) {
            x +=
                Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height)
                    + marginX;
          } else {
            x = nextXIfNotStacked;
          }

          atInStack = 0;
        } else {
          if (i != 0) {
            x += cardOffset;
          }
        }

        nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width;

        int xLoc = x;

        int yLoc = marginY;
        yLoc += atInStack * cardOffset;

        addPanel.setLocation(new Point(xLoc, yLoc));
        addPanel.setSize(addPanel.getPreferredSize());

        cards.add(addPanel);

        connectedCards.add((CardPanel) addPanel);

        atInStack++;
        prevCard = c;
      }

      setupConnectedCards(connectedCards);
      connectedCards.clear();

      for (int i = cards.size() - 1; i >= 0; i--) {
        JPanel card = cards.get(i);
        // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX);
        maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY);
        p.add(card);
      }

      maxX = nextXIfNotStacked;

      if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) {
        p.setPreferredSize(new Dimension(maxX, maxY));
      }

    } else {
      JPanel addPanel;
      for (int i = 0; i < list.size(); i++) {
        c = list.get(i);
        addPanel = new CardPanel(c);

        p.add(addPanel);
      }
    }
  } // setupPanel()
コード例 #7
0
  /**
   * setupPanel.
   *
   * @param p a {@link javax.swing.JPanel} object.
   * @param list a {@link java.util.ArrayList} object.
   * @param stack a boolean.
   */
  private static void setupPanel(JPanel p, ArrayList<Card> list, boolean stack) {

    int maxY = 0;
    int maxX = 0;
    // remove all local enchantments

    Card c;
    /*
    for(int i = 0; i < list.size(); i++)
    {
      c = (Card)list.get(i);
      if(c.isLocalEnchantment())
        list.remove(i);
    }

    //add local enchantments to the permanents
    //put local enchantments "next to" the permanent they are enchanting
    //the inner for loop is backward so permanents with more than one local enchantments are in the right order
    Card ca[];
    for(int i = 0; i < list.size(); i++)
    {
      c = (Card)list.get(i);
      if(c.hasAttachedCards())
      {
        ca = c.getAttachedCards();
        for(int inner = ca.length - 1; 0 <= inner; inner--)
          list.add(i + 1, ca[inner]);
      }
    }
    */

    if (stack) {
      // add all Cards in list to the GUI, add arrows to Local Enchantments

      ArrayList<Card> manaPools = getManaPools(list);
      ArrayList<Card> enchantedLands = getEnchantedLands(list);
      ArrayList<Card> basicBlues = getBasics(list, Constant.Color.Blue);
      ArrayList<Card> basicReds = getBasics(list, Constant.Color.Red);
      ArrayList<Card> basicBlacks = getBasics(list, Constant.Color.Black);
      ArrayList<Card> basicGreens = getBasics(list, Constant.Color.Green);
      ArrayList<Card> basicWhites = getBasics(list, Constant.Color.White);
      ArrayList<Card> badlands = getNonBasicLand(list, "Badlands");
      ArrayList<Card> bayou = getNonBasicLand(list, "Bayou");
      ArrayList<Card> plateau = getNonBasicLand(list, "Plateau");
      ArrayList<Card> scrubland = getNonBasicLand(list, "Scrubland");
      ArrayList<Card> savannah = getNonBasicLand(list, "Savannah");
      ArrayList<Card> taiga = getNonBasicLand(list, "Taiga");
      ArrayList<Card> tropicalIsland = getNonBasicLand(list, "Tropical Island");
      ArrayList<Card> tundra = getNonBasicLand(list, "Tundra");
      ArrayList<Card> undergroundSea = getNonBasicLand(list, "Underground Sea");
      ArrayList<Card> volcanicIsland = getNonBasicLand(list, "Volcanic Island");

      ArrayList<Card> nonBasics = getNonBasics(list);

      ArrayList<Card> moxEmerald = getMoxen(list, "Mox Emerald");
      ArrayList<Card> moxJet = getMoxen(list, "Mox Jet");
      ArrayList<Card> moxPearl = getMoxen(list, "Mox Pearl");
      ArrayList<Card> moxRuby = getMoxen(list, "Mox Ruby");
      ArrayList<Card> moxSapphire = getMoxen(list, "Mox Sapphire");
      // ArrayList<Card> moxDiamond = getMoxen(list, "Mox Diamond");

      list = new ArrayList<Card>();
      list.addAll(manaPools);
      list.addAll(enchantedLands);
      list.addAll(basicBlues);
      list.addAll(basicReds);
      list.addAll(basicBlacks);
      list.addAll(basicGreens);
      list.addAll(basicWhites);
      list.addAll(badlands);
      list.addAll(bayou);
      list.addAll(plateau);
      list.addAll(scrubland);
      list.addAll(savannah);
      list.addAll(taiga);
      list.addAll(tropicalIsland);
      list.addAll(tundra);
      list.addAll(undergroundSea);
      list.addAll(volcanicIsland);

      list.addAll(nonBasics);

      list.addAll(moxEmerald);
      list.addAll(moxJet);
      list.addAll(moxPearl);
      list.addAll(moxRuby);
      list.addAll(moxSapphire);
      // list.addAll(moxDiamond);

      int atInStack = 0;

      int marginX = 5;
      int marginY = 5;

      int x = marginX;

      int cardOffset = Constant.Runtime.stackOffset[0];

      String color = "";
      ArrayList<JPanel> cards = new ArrayList<JPanel>();

      ArrayList<CardPanel> connectedCards = new ArrayList<CardPanel>();

      boolean nextEnchanted = false;
      Card prevCard = null;
      int nextXIfNotStacked = 0;
      for (int i = 0; i < list.size(); i++) {
        JPanel addPanel;
        c = list.get(i);

        addPanel = new CardPanel(c);

        boolean startANewStack = false;

        if (!isStackable(c)) {
          startANewStack = true;
        } else {
          String newColor = c.getName(); // CardUtil.getColor(c);

          if (!newColor.equals(color)) {
            startANewStack = true;
            color = newColor;
          }
        }

        if (i == 0) {
          startANewStack = false;
        }

        if (!startANewStack && atInStack == Constant.Runtime.stackSize[0]) {
          startANewStack = true;
        }

        if (c.isAura() && c.isEnchanting() && !nextEnchanted) startANewStack = false;
        else if (c.isAura() && c.isEnchanting()) {
          startANewStack = true;
          nextEnchanted = false;
        }

        if (c.isLand() && c.isEnchanted()) {
          startANewStack = false;
          nextEnchanted = true;
        }

        // very hacky, but this is to ensure enchantment stacking occurs correctly when a land is
        // enchanted, and there are more lands of that same name

        else if ((prevCard != null
            && c.isLand()
            && prevCard.isLand()
            && prevCard.isEnchanted()
            && prevCard.getName().equals(c.getName()))) startANewStack = true;
        else if (prevCard != null
            && c.isLand()
            && prevCard.isLand()
            && !prevCard.getName().equals(c.getName())) startANewStack = true;

        /*
        if (c.getName().equals("Squirrel Nest")) {
            startANewStack = true;
            System.out.println("startANewStack: " + startANewStack);
        }
        */
        if (c.isAura() && c.isEnchanting() && prevCard != null && prevCard instanceof ManaPool)
          startANewStack = true;
        if (c instanceof ManaPool && prevCard instanceof ManaPool && prevCard.isSnow())
          startANewStack = false;

        if (startANewStack) {
          setupConnectedCards(connectedCards);
          connectedCards.clear();

          // Fixed distance if last was a stack, looks a bit nicer
          if (atInStack > 1) {
            x +=
                Math.max(addPanel.getPreferredSize().width, addPanel.getPreferredSize().height)
                    + marginX;
          } else {
            x = nextXIfNotStacked;
          }

          atInStack = 0;
        } else {
          if (i != 0) {
            x += cardOffset;
          }
        }

        nextXIfNotStacked = x + marginX + addPanel.getPreferredSize().width;

        int xLoc = x;

        int yLoc = marginY;
        yLoc += atInStack * cardOffset;

        addPanel.setLocation(new Point(xLoc, yLoc));
        addPanel.setSize(addPanel.getPreferredSize());

        cards.add(addPanel);

        connectedCards.add((CardPanel) addPanel);

        atInStack++;
        prevCard = c;
      }

      setupConnectedCards(connectedCards);
      connectedCards.clear();

      for (int i = cards.size() - 1; i >= 0; i--) {
        JPanel card = cards.get(i);
        // maxX = Math.max(maxX, card.getLocation().x + card.getSize().width + marginX);
        maxY = Math.max(maxY, card.getLocation().y + card.getSize().height + marginY);
        p.add(card);
      }

      maxX = nextXIfNotStacked;

      // System.out.println("x:" + maxX + ", y:" + maxY);
      if (maxX > 0 && maxY > 0) { // p.getSize().width || maxY > p.getSize().height) {
        //        p.setSize(new Dimension(maxX, maxY));
        p.setPreferredSize(new Dimension(maxX, maxY));
      }

    } else {
      // add all Cards in list to the GUI, add arrows to Local Enchantments
      JPanel addPanel;
      for (int i = 0; i < list.size(); i++) {
        c = list.get(i);
        /*if(c.isLocalEnchantment())
          addPanel = getCardPanel(c, "<< " +c.getName());
        else
          addPanel = getCardPanel(c);
          */
        addPanel = new CardPanel(c);

        p.add(addPanel);
      }
    }
  } // setupPanel()
コード例 #8
0
ファイル: ConvexHullGUI.java プロジェクト: goldsmcb/CS335
  public ConvexHullGUI() {

    points = new ArrayList<Point2D>();

    JFrame f = new JFrame("Convex Hull Finder");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setSize(new Dimension(600, 500));

    // Add the components
    JPanel mainPanel = new JPanel();
    mainPanel.setBackground(Color.LIGHT_GRAY);
    mainPanel.setLayout(new BorderLayout());

    // On the center we add the convex hull panel and add the even listener to it
    final ConvexHullPanel chp = new ConvexHullPanel();
    chp.setPreferredSize(new Dimension(400, 400));
    chp.setBackground(Color.WHITE);
    chp.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent e) {
            // TODO Auto-generated method stub
            super.mouseReleased(e);

            points.add(e.getPoint());
            chp.setPoints(points);
          }
        });

    mainPanel.add(chp, BorderLayout.CENTER);

    // On the left we add another panel that contains the controls
    JPanel controlPanel = new JPanel();
    controlPanel.setBackground(Color.LIGHT_GRAY);
    controlPanel.setSize(new Dimension(100, 500));
    controlPanel.setLayout(new GridLayout(6, 1));
    // controlPanel.setLayout(new FlowLayout());

    JLabel numPointsLab = new JLabel("     # of points     ");
    controlPanel.add(numPointsLab);

    final JTextField numPoints = new JTextField(10);
    controlPanel.add(numPoints);

    JButton genPoints = new JButton("Generate Points");
    controlPanel.add(genPoints);
    genPoints.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            // Assume the text entered is an actual number
            int numberOfPoints = Integer.parseInt(numPoints.getText());

            // Make the List of Point2Ds
            points = new ArrayList<Point2D>();

            /*
            //Hard Code Points
            points.add(new Point2D.Double(200, 350));
            points.add(new Point2D.Double(100, 300));
            points.add(new Point2D.Double(200, 125));
            points.add(new Point2D.Double(100, 200));
            points.add(new Point2D.Double(300, 160));
            points.add(new Point2D.Double(350, 225));
            points.add(new Point2D.Double(230, 280));
            points.add(new Point2D.Double(190, 210));
            */

            // Generate Points
            int width = chp.getWidth();
            int height = chp.getHeight();

            for (int i = 0; i < numberOfPoints; i++) {
              // Generate 2 random numbers in the range set by the hull panel
              // and not too close to the edges so it looks good
              int x = (int) (Math.random() * (width - 50)) + 25;
              int y = (int) (Math.random() * (height - 50)) + 25;

              points.add(new Point2D.Double(x, y));
            }

            // Display them on the panel
            chp.setPoints(points);
            chp.setHull(new ArrayList<Point2D>()); // Zero out any hull that was there
          }
        });

    JRadioButton quickButton = new JRadioButton("QuickHull");
    quickButton.setSelected(true);
    theConvexHullFinder = new QuickHull();
    quickButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            theConvexHullFinder = new QuickHull();
          }
        });
    controlPanel.add(quickButton);

    JRadioButton mergeButton = new JRadioButton("MergeHull");
    mergeButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            theConvexHullFinder = new MergeHull();
          }
        });
    controlPanel.add(mergeButton);

    ButtonGroup hullChoice = new ButtonGroup();
    hullChoice.add(quickButton);
    hullChoice.add(mergeButton);

    JButton genHull = new JButton("Generate Hull");
    genHull.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            // Generate the hull
            List<Point2D> hullPoints = theConvexHullFinder.computeHull(points);

            // Show the results on the screen
            chp.setHull(hullPoints);
          }
        });
    controlPanel.add(genHull);

    mainPanel.add(controlPanel, BorderLayout.WEST);

    // Replace the content pane of the frame with the main panel we built
    f.setContentPane(mainPanel);
    f.setVisible(true);
  }
コード例 #9
0
  public LoginPanel(Image img, ActionListener listener) {
    super(null);
    this.listener = listener;
    if (img == null) {
      InputStream inData = getClass().getResourceAsStream("/resources/background.gif");
      BufferedImage back = null;
      if (inData != null)
        try {
          back = ImageIO.read(inData);
        } catch (IOException e) {
          loger.finest("LoginPanel class can't get the background image");
        }
      this.background = back;
    }

    setLayout(null);
    JPanel logingPanel = new JPanel();
    loginTitle = new JLabel("Autentificare");
    logingPanel.setSize(250, 150);
    logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2));
    logingPanel.setLayout(null);
    loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20);
    logingPanel.add(loginTitle);
    JLabel loginUser = new JLabel("Utilizator");
    loginUser.setBounds(
        80 - loginUser.getPreferredSize().width,
        40,
        loginUser.getPreferredSize().width,
        loginUser.getPreferredSize().height);
    logingPanel.add(loginUser);
    user = new JTextField(10);
    user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height);
    // user.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(user);
    JLabel loginPass = new JLabel("Parola");
    loginPass.setBounds(
        80 - loginPass.getPreferredSize().width,
        80,
        loginPass.getPreferredSize().width,
        loginPass.getPreferredSize().height);
    logingPanel.add(loginPass);
    // JTextField pass = new JTextField(10);
    pass = new JPasswordField(10);
    pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height);
    pass.addKeyListener(this);
    // pass.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(pass);
    JButton loginButton = new JButton("Start");
    loginButton.setActionCommand("LOGIN");
    loginButton.setBounds(
        60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height);
    // loginButton.setOpaque(false);
    loginButton.setFocusPainted(false);
    // loginButton.setContentAreaFilled(false);
    // loginButton.setBorderPainted(false);
    loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    loginButton.addActionListener(listener);
    logingPanel.add(loginButton);

    add(logingPanel);
  }