Example #1
1
 public void paint(Graphics g) {
   imageLabel.setLocation(textField.getX() - 8, 2);
   super.paint(g);
   //    System.out.println( "panel paint" ) ;
 }
Example #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);
  }
Example #3
0
 public void run() {
   try {
     while (läuft) {
       Thread.sleep(1);
       if (verloren) {
         verloren();
       } else {
         if (intro) {
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_n.png"));
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_n.png"));
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_n.png"));
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_n.png"));
           lblVerloren.setText("");
           start.setText("3");
           Thread.sleep(1000);
           start.setText("2");
           Thread.sleep(1000);
           start.setText("1");
           Thread.sleep(1000);
           start.setLocation(start.getX() - 20, start.getY());
           start.setText("Los!");
           Thread.sleep(250);
           start.setText("");
           start.setLocation(start.getX() + 20, start.getY());
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_0.png"));
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_0.png"));
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_0.png"));
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
           intro = false;
           neu = true;
         }
         if (wiedergeben && !verloren) {
           Thread.sleep(500);
           alteFarbe();
         } else if (neu && !verloren) neueFarbe();
         if (!wiedergeben && !neu) {
           String s = "Noch ";
           vKlicks = runde - klick;
           if (vKlicks >= 1) s = s + String.valueOf(vKlicks);
           else s = "";
           klicks.setText(s);
         } else klicks.setText("");
       }
     }
   } catch (Exception e) {
   }
 }
Example #4
0
 public void run() {
   int pos_x = 0;
   while (true) {
     pos_x += 2;
     lblPic.setLocation(pos_x, pos_y);
     Pause(time);
     if (pos_x >= wide) pos_x = 0;
   }
 }
  private void processDrag(final MouseEvent e) {
    if (myDragCancelled) return;
    if (!isDraggingNow()) {
      if (myPressedPoint == null) return;
      if (isWithinDeadZone(e)) return;

      myDragPane = findLayeredPane(e);
      if (myDragPane == null) return;
      final BufferedImage image =
          new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      paint(image.getGraphics());
      myDragButtonImage =
          new JLabel(new ImageIcon(image)) {

            public String toString() {
              return "Image for: " + StripeButton.this.toString();
            }
          };
      myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER);
      myDragButtonImage.setSize(myDragButtonImage.getPreferredSize());
      setVisible(false);
      myPane.startDrag();
      myDragKeyEventDispatcher = new DragKeyEventDispatcher();
      KeyboardFocusManager.getCurrentKeyboardFocusManager()
          .addKeyEventDispatcher(myDragKeyEventDispatcher);
    }
    if (!isDraggingNow()) return;

    Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane);
    if (myPressedPoint != null) {
      xy.x -= myPressedPoint.x;
      xy.y -= myPressedPoint.y;
    }
    myDragButtonImage.setLocation(xy);

    SwingUtilities.convertPointToScreen(xy, myDragPane);

    final Stripe stripe =
        myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent());
    if (stripe == null) {
      if (myLastStripe != null) {
        myLastStripe.resetDrop();
      }
    } else {
      if (myLastStripe != null && myLastStripe != stripe) {
        myLastStripe.resetDrop();
      }
      stripe.processDropButton(this, myDragButtonImage, xy);
    }

    myLastStripe = stripe;
  }
Example #6
0
  public void keyPressed(KeyEvent ke) {
    int code = ke.getKeyCode();
    if (code == KeyEvent.VK_UP) {
      this.zil.setIcon(new ImageIcon(getImage(getCodeBase(), "zil_walk_back.gif")));
      repaint();
      // y -= speed;
      for (int z = speed; z > 0; z--) {
        y -= z;
        zil.setLocation(x, y);
      }
    } else if (code == KeyEvent.VK_DOWN) {
      this.zil.setIcon(new ImageIcon(getImage(getCodeBase(), "zil_walk_front.gif")));
      repaint();
      //  y += speed;
      for (int z = speed; z > 0; z--) {
        y += z;
        zil.setLocation(x, y);
      }
    } else if (code == KeyEvent.VK_LEFT) {
      this.zil.setIcon(new ImageIcon(getImage(getCodeBase(), "zil_walk_left.gif")));
      repaint();
      // x -= speed;
      for (int z = speed; z > 0; z--) {
        x -= z;

        zil.setLocation(x, y);
      }
    } else if (code == KeyEvent.VK_RIGHT) {

      this.zil.setIcon(new ImageIcon(getImage(getCodeBase(), "zil_walk_right.gif")));
      repaint();
      // x += speed;
      for (int z = speed; z > 0; z--) {
        x += z;
        zil.setLocation(x, y);
      }
    }
  }
Example #7
0
  public Senso() {
    super("Senso");
    this.setSize(640, 480);
    this.setLocation(100, 100);
    this.getContentPane().setBackground(Color.black);
    this.setUndecorated(true);
    this.setBackground(Color.white);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setLayout(null);
    this.setAlwaysOnTop(true);

    klicks = new JLabel();
    klicks.setSize(150, 25);
    klicks.setLocation(20, 300);
    klicks.setFont(new Font("Impact", 5, 25));
    klicks.setForeground(Color.lightGray);
    this.add(klicks);

    start = new JLabel();
    start.setSize(350, 50);
    start.setLocation(350, 200);
    start.setFont(new Font("Impact", 5, 50));
    start.setForeground(Color.lightGray);
    this.add(start);

    lblVerloren = new JLabel();
    lblVerloren.setSize(350, 30);
    lblVerloren.setLocation(200, 215);
    lblVerloren.setFont(new Font("Impact", 5, 30));
    lblVerloren.setForeground(Color.lightGray);
    this.add(lblVerloren);

    neustart = new JLabel("Neustart");
    neustart.setSize(100, 30);
    neustart.setLocation(20, 200);
    neustart.setFont(new Font("Impact", 5, 25));
    neustart.setForeground(Color.darkGray);
    neustart.addMouseListener(this);
    this.add(neustart);

    beenden = new JLabel("Beenden");
    beenden.setSize(100, 30);
    beenden.setLocation(20, 390);
    beenden.setFont(new Font("Impact", 5, 25));
    beenden.setForeground(Color.gray);
    beenden.addMouseListener(this);
    this.add(beenden);

    us = new JLabel("Senso");
    us.setSize(150, 35);
    us.setLocation(10, 30);
    us.setFont(new Font("Impact", 1, 35));
    us.setForeground(Color.white);
    this.add(us);

    punkte = new JLabel("Score: " + String.valueOf(points));
    punkte.setSize(200, 20);
    punkte.setLocation(400, 400);
    punkte.setFont(new Font("Impact", 0, 20));
    punkte.setForeground(Color.white);
    this.add(punkte);

    rot = new JLabel(new ImageIcon("files/Minigames/Senso/red_0.png"));
    rot.setSize(216, 207);
    rot.setLocation(150, 25);
    rot.setBackground(Color.darkGray);
    rot.addMouseListener(this);
    this.add(rot);

    gruen = new JLabel(new ImageIcon("files/Minigames/Senso/green_0.png"));
    gruen.setSize(216, 207);
    gruen.setLocation(366, 25);
    gruen.setBackground(Color.darkGray);
    gruen.addMouseListener(this);
    this.add(gruen);

    gelb = new JLabel(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
    gelb.setSize(216, 207);
    gelb.setLocation(366, 232);
    gelb.setBackground(Color.darkGray);
    gelb.addMouseListener(this);
    this.add(gelb);

    blau = new JLabel(new ImageIcon("files/Minigames/Senso/blue_0.png"));
    blau.setSize(216, 207);
    blau.setLocation(150, 232);
    blau.setBackground(Color.darkGray);
    blau.addMouseListener(this);
    this.add(blau);

    this.addMouseListener(this);

    // spiel = new Thread(this);
    zufall = new Random();

    läuft = false;

    zahl = zufall.nextInt(4);
    // this.setVisible(true);
    soundR = new File("files/Minigames/Senso/rot.wav");
    soundG = new File("files/Minigames/Senso/gruen.wav");
    soundB = new File("files/Minigames/Senso/blau.wav");
    soundY = new File("files/Minigames/Senso/gelb.wav");
    soundF = new File("files/Minigames/Senso/falsch.wav");
  }
  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);
  }
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    Object obj = actionEvent.getSource();

    if (obj == btFindPat) {

      testpanel.removeAll();
      validate();
      repaint();
      if (taDictionary.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            frame, "Please load words so they appear in Text Area before Finding Path. ");

      } else if ((tfSourc.getText().isEmpty()) || (tfSourc_6.getText().isEmpty())) {
        JOptionPane.showMessageDialog(
            frame, "Please enter Source and Destination words before Finding Path. ");
      } else if (testpanel.getComponents().length != 0) {
        JOptionPane.showMessageDialog(frame, "Please clear results before continuing.");
      } else {
        wordLadder.findPath(
            tfSourc.getText(), tfSourc_6.getText(), Integer.parseInt(tfWordSize.getText()));
        lblFindPat.setText(
            "Time to find Path: " + String.valueOf(wordLadder.getTimeForPath()) + " milliseconds");
        lblCos.setText("Cost of Path: " + String.valueOf(wordLadder.g.getCost()));
        results = wordLadder.getResults();
        Collections.reverse(results);
        int x = 10;
        int y = 20;

        for (String s : results) {
          x += 20;
          y += 20;
          JLabel _lbl = new JLabel(s);
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);

          if (results.indexOf(s) == 0) {
            _lbl.setForeground(new Color(-14646771));
          } else if (results.indexOf(s) == (results.size() - 1)) {
            _lbl.setForeground(new Color(-8254711));
          } else {
            _lbl.setForeground(new Color(-16777216));
          }
          testpanel.add(_lbl);
          testpanel.repaint();
        }
        if (wordLadder.g.getCost() == 0) {
          // if (wordLadder.g.getGraphError() != null){
          JLabel _lbl = new JLabel(wordLadder.g.getGraphError());
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);
          testpanel.add(_lbl);
          testpanel.repaint();
          // }

        }
      }
      /*if (taDictionary.getText().isEmpty()){
      wordLadder = new WordLadder(tfFilePat.getText(), tfSourc.getText(), tfSourc_6.getText());
       }else if (!taDictionary.getText().isEmpty()){
          ArrayList<String> taList = new ArrayList<String>();
          StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
          while (stringTokenizer.hasMoreTokens()) {
              String token = stringTokenizer.nextToken();
              taList.add(token);
          }
        */
      // }
    }

    if (obj == btLoadFil) {
      clearData();
      // wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      // String size = tfWordSize.getText();
      // int intSize = Integer.parseInt(size);
      // WordLadderGUI.showMessage("Loading words of" + tfWordSize.getText() + " characters from
      // file: " + tfFilePat.getText(), Color.GREEN, Color.GREEN);
      lblIndexing1.setText("Indexing...");
      System.out.println(
          "Loading words of "
              + tfWordSize.getText()
              + " characters from file: "
              + tfFilePat.getText());
      wordLadder = new WordLadder(tfFilePat.getText(), Integer.parseInt(tfWordSize.getText()));
      // wordLadder.
      guiDictionary = new WordCollection(wordLadder.getWordList());
      WordLadderGUI.showMessage(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText(),
          Color.GREEN,
          Color.GREEN);
      System.out.println(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText());
      taDictionary.setText(guiDictionary.toString());
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }

    if (obj == btLoadTextFiel) {
      wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      String taDump = taDictionary.getText();
      System.out.println("Loading Words from Text Area");
      lblIndexing1.setText("Indexing...");
      ArrayList<String> taList = new ArrayList<String>();
      StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
      while (stringTokenizer.hasMoreTokens()) {
        String token = stringTokenizer.nextToken();
        taList.add(token);
      }
      guiDictionary = new WordCollection();
      guiDictionary.setWords(taList);
      wordLadder = new WordLadder(taList);
      WordLadderGUI.showMessage(
          "Loading " + wordLadder.getWordList().size() + " words from Text Field",
          Color.GREEN,
          Color.GREEN);
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }
    if (obj == btClear) {
      testpanel.removeAll();
      testpanel.validate();
      testpanel.repaint();
      wordLadder = null;
      lblCos.setText("Cost of Path: 0.0");
      lblCos.repaint();
      lblDictCoun.setText("Words in Dictionary = 0 words");
      lblFindPat.setText("Time to find Path: 0 milliseconds");
      tfSourc.setText("");
      tfSourc_6.setText("");
      taDictionary.setText("");
      results = null;
      lblProgres.setText("Time to Build Graph: 0 milliseconds");
    }
  }