コード例 #1
0
ファイル: Spacer.java プロジェクト: grimtraveller/LightZone
 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);
  }
コード例 #3
0
 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
  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);
  }
コード例 #5
0
  // 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);
  }