示例#1
0
 public void doLayout() {
   if (isStuck()) {
     Dimension size = getSize();
     Dimension unStickSize = unstickButton.getPreferredSize();
     int x = size.width - unStickSize.width;
     int y = size.height / 2 - unStickSize.height / 2;
     unstickButton.setSize(unStickSize);
     unstickButton.setLocation(x, y);
   }
 }
示例#2
0
  public Abschluss(String wahl, Sudoku s, Sudoku2 s2) {
    super("Sudoku-Abschluss");
    this.setSize(270, 135);
    this.setLocation(250, 300);
    this.setLayout(null);
    this.setAlwaysOnTop(true);
    this.setResizable(false);
    this.setUndecorated(true);
    if (s == null) this.setLocationRelativeTo(s2);
    else this.setLocationRelativeTo(s);

    su = s;
    su2 = s2;
    w = wahl;

    ImageIcon icon = new ImageIcon("files/minigames/Sudoku/beispiel2.jpg");
    icon.setImage(icon.getImage().getScaledInstance(290, 135, Image.SCALE_DEFAULT));

    lab = new JLabel(icon);
    lab.setSize(270, 135);
    lab.setLocation(0, 0);
    this.add(lab);

    text = new JLabel();
    text.setSize(250, 20);
    text.setLocation(10, 10);
    text.setForeground(Color.white);
    text.setHorizontalAlignment(0);
    lab.add(text);

    text2 = new JLabel();
    text2.setSize(270, 20);
    text2.setLocation(10, 30);
    text2.setForeground(Color.white);
    lab.add(text2);

    ok = new JButton("OK");
    ok.setSize(90, 30);
    ok.setLocation(80, 50);
    ok.setBorderPainted(false);
    ok.setBackground(Color.lightGray);
    ok.setForeground(Color.lightGray);
    ok.setOpaque(false);
    ok.setFont(new Font("Arial Black", 4, 20));
    ok.setContentAreaFilled(false);
    ok.setFocusPainted(false);
    ok.addActionListener(this);
    ok.addMouseListener(this);
    lab.add(ok);

    textWahl(wahl);

    this.setVisible(true);
  }
 private void init() {
   setSize(800, 600);
   cp = getContentPane();
   cp.setLayout(null);
   btnResize.addActionListener(this);
   btnResize.setLocation(0, 0);
   btnResize.setSize(100, 30);
   sp.setLocation(0, 31);
   sp.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
   editorPane.setBorder(BorderFactory.createLineBorder(Color.red, 2));
   step.setLocation(0, 31);
   step.setSize(100, 100);
   cp.add(step);
   //		cp.add(sp);
   cp.add(btnResize);
 }
示例#4
0
  public GraphicsUI() {

    questionPool = new QuestionPool();

    setTitle("Question Pool");
    setSize(WIDTH, HEIGHT);

    fileL = new JLabel("Location of Question Pool File:");
    fileTF = new JTextField(10);

    checkB = new JButton("Check File");

    log = new JTextArea(6, 30);

    Container pane = getContentPane();
    pane.setLayout(null);

    // set locations and sizes for the elements
    fileL.setLocation(90, 15);
    fileL.setSize(ELEMENT_WIDTH, 30);
    fileTF.setLocation(90, 65);
    fileTF.setSize(ELEMENT_WIDTH, 30);
    checkB.setLocation(90, 105);
    checkB.setSize(300, 35);
    log.setLocation(90, 145);
    log.setSize(300, 30);

    // add listener to button
    CheckButtonHandler cbHandler = new CheckButtonHandler();
    checkB.addActionListener(cbHandler);
    fileTF.addActionListener(cbHandler);

    // add elements to pane
    pane.add(fileL);
    pane.add(fileTF);
    pane.add(checkB);
    pane.add(log);

    setLocation(100, 60);
    setVisible(true);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  }
  void setupGUI() {
    taDictionary = new TextArea();
    taDictionary.setLocation(0, 0);
    taDictionary.setSize(106, 567);
    taDictionary.setBackground(new Color(-1));
    taDictionary.setText("");
    taDictionary.setRows(5);
    taDictionary.setColumns(1);
    getContentPane().add(taDictionary);

    tfSourc = new TextField();
    tfSourc.setLocation(224, 90);
    tfSourc.setSize(266, 25);
    tfSourc.setBackground(new Color(-1));
    tfSourc.setText("");
    tfSourc.setColumns(10);
    getContentPane().add(tfSourc);

    lblSourc = new Label();
    lblSourc.setLocation(106, 90);
    lblSourc.setSize(119, 25);
    lblSourc.setText("Source Word:");
    getContentPane().add(lblSourc);
    /*
    lblDestinatio = new Label();
    lblDestinatio.setLocation(106,97);
    lblDestinatio.setSize(119,25);
    lblDestinatio.setText("Destination Wor");
    getContentPane().add(lblDestinatio);
       */

    lblDestinatio = new Label();
    lblDestinatio.setLocation(106, 120);
    lblDestinatio.setSize(119, 25);
    lblDestinatio.setText("Destination Word:");
    getContentPane().add(lblDestinatio);

    lblWordSize = new Label();
    lblWordSize.setLocation(106, 27); // 106,120
    lblWordSize.setSize(119, 25);
    lblWordSize.setText("Word Size:");
    getContentPane().add(lblWordSize);

    tfWordSize = new TextField();
    tfWordSize.setLocation(224, 27); // 224,120
    tfWordSize.setSize(263, 25);
    tfWordSize.setBackground(new Color(-1));
    tfWordSize.setText("5");
    tfWordSize.setColumns(10);
    getContentPane().add(tfWordSize);

    tfSourc_6 = new TextField();
    tfSourc_6.setLocation(226, 120);
    tfSourc_6.setSize(263, 25);
    tfSourc_6.setBackground(new Color(-1));
    tfSourc_6.setText("");
    tfSourc_6.setColumns(10);
    getContentPane().add(tfSourc_6);

    lblFileNam = new Label();
    lblFileNam.setLocation(104, 0);
    lblFileNam.setSize(119, 25);
    lblFileNam.setText("FilePath:");
    getContentPane().add(lblFileNam);

    tfFilePat = new TextField();
    tfFilePat.setLocation(224, 0);
    tfFilePat.setSize(266, 25);
    tfFilePat.setBackground(new Color(-1));

    // OS Detection
    if (System.getProperty("os.name").startsWith("Windows")) {
      // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
      tfFilePat.setText("c:\\ics340\\words.txt");
      System.out.println("Detected Windows: " + System.getProperty("os.name"));
    } else {
      tfFilePat.setText("/Users/jasonedstrom/ics340/d1.txt");
      System.out.println("Detected Mac OS X: " + System.getProperty("os.name"));
    }

    tfFilePat.setColumns(10);
    getContentPane().add(tfFilePat);

    btLoadTextFiel = new JButton();
    btLoadTextFiel.setLocation(108, 50); // 108,27
    btLoadTextFiel.setSize(198, 32);
    btLoadTextFiel.setText("Load Words from Text Field");
    getContentPane().add(btLoadTextFiel);

    btLoadFil = new JButton();
    btLoadFil.setLocation(306, 50); // 306,27
    btLoadFil.setSize(183, 32);
    btLoadFil.setText("Load Words from File");
    getContentPane().add(btLoadFil);

    btFindPat = new JButton();
    btFindPat.setLocation(106, 160);
    btFindPat.setSize(384, 38);
    btFindPat.setText("Find Path");
    getContentPane().add(btFindPat);

    lblDictCoun = new JLabel();
    lblDictCoun.setLocation(108, 513);
    lblDictCoun.setSize(300, 27);
    lblDictCoun.setForeground(new Color(-65536));
    lblDictCoun.setText("Words in Dictionary = 0 words");
    getContentPane().add(lblDictCoun);

    lblIndexing1 = new JLabel();
    lblIndexing1.setLocation(107, 454);
    lblIndexing1.setSize(130, 27);
    lblIndexing1.setForeground(new Color(-16777216));
    lblIndexing1.setText("");
    getContentPane().add(lblIndexing1);

    lblFindPat = new JLabel();
    lblFindPat.setLocation(108, 540);
    lblFindPat.setSize(250, 27);
    lblFindPat.setForeground(new Color(-14646771));
    lblFindPat.setText("Time to find Path: 0 milliseconds");
    getContentPane().add(lblFindPat);

    lblCos = new JLabel();
    lblCos.setLocation(360, 540);
    lblCos.setSize(175, 27);
    lblCos.setForeground(new Color(-16777216));
    lblCos.setText("Cost of Path: 0.0");
    getContentPane().add(lblCos);

    lblProgres = new JLabel();
    lblProgres.setLocation(108, 484);
    lblProgres.setSize(371, 26);
    lblProgres.setForeground(new Color(-14646771));
    lblProgres.setText("Time to Build Graph: 0 milliseconds");
    getContentPane().add(lblProgres);

    testpanel = new JPanel();
    testpanel.setLocation(106, 200);
    testpanel.setSize(350, 200);
    testpanel.setForeground(new Color(-14646771));
    // testpanel.setText("Test Location");
    getContentPane().add(testpanel);

    btClear = new JButton();
    btClear.setLocation(355, 513);
    btClear.setSize(125, 25);
    btClear.setText("Clear Results");
    getContentPane().add(btClear);

    // add actionlisteners to buttons
    btFindPat.addActionListener(this);
    btLoadTextFiel.addActionListener(this);
    btLoadFil.addActionListener(this);
    btClear.addActionListener(this);

    setTitle("WordLadderGUI");
    setSize(500, 600);
    setVisible(true);
    setResizable(false);
  }
  // Set the positions and sizes of the buttons and display the panel
  public void paintComponent(Graphics page) {
    super.paintComponent(page);

    // Calculate the button width and height so the buttons span the screen
    int screenWidth = getWidth();
    int screenHeight = getHeight();
    int[] buttonWidth = new int[5];
    buttonWidth[0] = (screenWidth - (BUTTON_SPACE * 13)) / 13;
    buttonWidth[1] = buttonWidth[0];
    buttonWidth[2] = (screenWidth - (BUTTON_SPACE * 11)) / 11;
    buttonWidth[3] = (screenWidth - (BUTTON_SPACE * 11)) / 10;
    buttonWidth[4] = (screenWidth - (BUTTON_SPACE * 11)) / 10;
    int buttonHeight = (screenHeight - (BUTTON_SPACE * 7)) / 6;

    int xPos;
    int yPos;
    // Subtract 1 from this int every time a sound button is placed where it belongs
    // When it equals zero all sounds have been placed
    int keysToMap = soundList.size();
    ArrayList<BoardButton> copy = (ArrayList<BoardButton>) soundList.clone();

    // For each string in the rows array, check if any of the key strings for the sound match
    for (int j = 0; j < rows.length; j++) {
      int i = 0;

      // For each string in the rows array, check each sound object to see if it is played with a
      // key in that row
      while ((copy.size() > 0) && (i < soundList.size())) {
        int index = 0;
        if (soundList.get(i).getKeyName().indexOf("N") != -1) {
          if (j == 4) index = rows[j].indexOf(soundList.get(i).getKeyName().substring(1));
          else index = -1;
        } else {
          if (j != 4)
            // Get where the key string is in the rows array
            index = rows[j].indexOf(soundList.get(i).getKeyName());
          else index = -1;
        }
        // If the key string doesn't exist, the key is not in this row and the button won't be
        // placed
        if (index != -1) {
          // Place the button based on the corresponding key's position on the keyboard
          xPos = ((buttonWidth[j] + BUTTON_SPACE) * index) + BUTTON_SPACE;
          yPos = ((buttonHeight + BUTTON_SPACE) * j) + BUTTON_SPACE;

          JButton curr = soundList.get(i).getButton();
          // Set the button's size and position to the size and position calculated
          curr.setSize(new Dimension(buttonWidth[j], buttonHeight));
          curr.setLocation(xPos, yPos);
          // Decrement the number of sounds left to map
          copy.remove(soundList.get(i));
          keysToMap -= 1;
        }

        // Increment the index of the sound to check
        i++;
      }
    }

    // Set the x-position, y-position, and size of the spacebar key
    // It will span the bottom of the screen and be the same height as the other buttons
    JButton btnSpace = space.getButton();
    xPos = 10;
    yPos = ((buttonHeight + BUTTON_SPACE) * 5) + BUTTON_SPACE;
    btnSpace.setSize(new Dimension(screenWidth - (BUTTON_SPACE * 2), buttonHeight));
    btnSpace.setLocation(xPos, yPos);
  }
示例#7
0
  /**
   * This method creates the content pane that will be a part of the frame, including the JLabels,
   * JPanels and the JButtons INPUT (parameters): none OUTOUT (return): the main JPanel object that
   * includes everything
   */
  public JPanel createContentPane() {

    JPanel totalGUI = new JPanel(); // the main panel
    totalGUI.setBackground(Color.BLACK);
    totalGUI.setLayout(null);

    printInstructions();
    startNum = In.getInt();
    if (startNum == 1) startGame = true;
    else startGame = false;
    while (!startGame) {
      System.out.println("Please enter 1 to start the game");
      startNum = In.getInt();
      if (startNum == 1) startGame = true;
      else startGame = false;
    }
    if (startGame) {
      titlePanel = new JPanel(); // a panel where the title will be displayed
      titlePanel.setLayout(null);
      titlePanel.setLocation(0, 0);
      titlePanel.setSize(1600, 150);
      Color titlePanelColor = new Color(238, 130, 238);
      titlePanel.setBackground(titlePanelColor);
      totalGUI.add(titlePanel); // this panel is added to the main panel

      gamePanel = new JPanel(); // game panel (where the cards will be displayed)
      gamePanel.setLayout(null);
      gamePanel.setLocation(0, 150);
      gamePanel.setSize(950, 650);
      gamePanel.setBackground(Color.BLACK);
      totalGUI.add(gamePanel);

      newGameButton = new JButton("Start"); // a button to start the game
      newGameButton.setLocation(800, 155);
      newGameButton.setSize(120, 30);
      newGameButton.addActionListener(this);
      gamePanel.add(newGameButton); // this button is added to the game panel

      endGameButton = new JButton("End Game"); // a button to end the game
      endGameButton.setLocation(800, 195);
      endGameButton.setSize(120, 30);
      endGameButton.addActionListener(this);
      gamePanel.add(endGameButton);

      hitButton = new JButton("Hit! (Player)"); // a hit button for the player
      hitButton.setLocation(800, 235);
      hitButton.setSize(120, 30);
      hitButton.addActionListener(this);
      gamePanel.add(hitButton);

      hitButton2 = new JButton("Hit! (Dealer)"); // a hit button for the dealer
      hitButton2.setLocation(800, 275);
      hitButton2.setSize(120, 30);
      hitButton2.addActionListener(this);
      gamePanel.add(hitButton2);

      standButton = new JButton("Stand (Player)"); // a stand button for the player
      standButton.setLocation(800, 315);
      standButton.setSize(120, 30);
      standButton.addActionListener(this);
      gamePanel.add(standButton);

      standButton2 = new JButton("Stand (Dealer)"); // a stand button for the dealer
      standButton2.setLocation(800, 355);
      standButton2.setSize(120, 30);
      standButton2.addActionListener(this);
      gamePanel.add(standButton2);

      playerTitle =
          new JLabel(
              "Player"); // label that displays the word "Player" on the screen
      playerTitle.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color playerTitleColor = new Color(0, 250, 154);
      playerTitle.setForeground(playerTitleColor);
      playerTitle.setLocation(550, 150);
      playerTitle.setSize(100, 30);
      gamePanel.add(playerTitle);

      dealerTitle = new JLabel("Dealer"); // label that displays the word "Dealer" on the screen
      dealerTitle.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color dealerTitleColor = new Color(0, 250, 154);
      dealerTitle.setForeground(dealerTitleColor);
      dealerTitle.setLocation(550, 350);
      dealerTitle.setSize(100, 30);
      gamePanel.add(dealerTitle);

      scoreLabel = new JLabel(""); // label that displays the score
      scoreLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 30));
      Color scoreLabelColor = new Color(255, 20, 147);
      scoreLabel.setForeground(scoreLabelColor);
      scoreLabel.setLocation(200, 130);
      scoreLabel.setSize(400, 300);
      gamePanel.add(scoreLabel);

      turnLabel = new JLabel(""); // label that informs the users whose turn it is
      turnLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color turnLabelColor = new Color(255, 127, 80);
      turnLabel.setForeground(turnLabelColor);
      turnLabel.setLocation(250, 200);
      turnLabel.setSize(300, 100);
      gamePanel.add(turnLabel);

      score1 = new JLabel("");
      score1.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color score1Color = new Color(255, 127, 80);
      score1.setForeground(score1Color);
      score1.setLocation(660, 135);
      score1.setSize(100, 60);
      gamePanel.add(score1);

      score2 = new JLabel("");
      score2.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
      Color score2Color = new Color(255, 127, 80);
      score2.setForeground(score2Color);
      score2.setLocation(660, 335);
      score2.setSize(100, 60);
      gamePanel.add(score2);

      ImageIcon titleIcon1 = new ImageIcon("BlackJack.jpg");
      titlePics = new JLabel(titleIcon1); // an image for decor
      titlePics.setLocation(0, 0);
      titlePics.setSize(150, 150);
      titlePanel.add(titlePics); // image added to title label

      welcomeLabel = new JLabel("Welcome To Casino Royale!");
      welcomeLabel.setFont(new Font("Monotype Corsiva", Font.BOLD, 40));
      Color titleColor = new Color(0, 255, 255); // title
      welcomeLabel.setForeground(titleColor);
      welcomeLabel.setLocation(245, 0);
      welcomeLabel.setSize(700, 100);
      titlePanel.add(welcomeLabel);

      commandLabel = new JLabel("Please press \"Start\" to start a game of Black Jack!");
      commandLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 16));
      Color commandColor = new Color(0, 0, 0);
      commandLabel.setForeground(commandColor); // instruction to user on how to start the game
      commandLabel.setLocation(250, 101);
      commandLabel.setSize(700, 44);
      titlePanel.add(commandLabel);

      ImageIcon titleIcon3 = new ImageIcon("Swirl.jpg");
      titlePics = new JLabel(titleIcon3); // an image for decor
      titlePics.setLocation(783, 0);
      titlePics.setSize(150, 150);
      titlePanel.add(titlePics);

      totalGUI.setOpaque(true);
      return totalGUI; // return the final JPanel
    }
    return totalGUI;
  }