Exemplo n.º 1
1
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
Exemplo n.º 2
1
  // --------------------------------actionHost---------------------------------
  private void actionHost() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.CANCEL_OPTION) {
      return;
    }

    int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame)));

    JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame));
    dlgBox.pack();
    try {
      oConn.host(nPort);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    dlgBox.setVisible(false);
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();

    try {
      oMap.loadMap(oFC.getSelectedFile());
      oConn.send("loadmap", oFC.getName(oFC.getSelectedFile()));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
 private void setLayout() {
   GroupLayout layout = new GroupLayout(dialog.getContentPane());
   dialog.getContentPane().setLayout(layout);
   dialog.setResizable(true);
   layout.setAutoCreateContainerGaps(true);
   layout.setHorizontalGroup(layout.createParallelGroup().addComponent(tabbedPane));
   layout.setVerticalGroup(layout.createParallelGroup().addComponent(tabbedPane));
   layout.setHonorsVisibility(tabbedPane, true);
   // TODO set color here
   dialog.getContentPane().setBackground(new Color(0x132638));
   dialog.validate();
   dialog.repaint();
 }
  public static void main(String[] args) {

    JFrame frame = new JFrame("Network Tables");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    Display display = new Display();
    frame.getContentPane().add(display);

    frame.setLocation(0, 0);
    frame.setSize(new Dimension(2000, 700));

    frame.revalidate();
    frame.repaint();
    frame.setVisible(true);
  }
Exemplo n.º 5
0
 public void actionPerformed(ActionEvent ae) {
   JButton button = (JButton) ae.getSource();
   if (button == high) {
     frame.remove(main);
     frame.setContentPane(scores);
   }
   if (button == cred) {
     frame.remove(main);
     frame.setContentPane(credits);
   }
   if (button == start) {
     frame.remove(main);
     frame.setContentPane(story);
   }
   if (button == stor) {
     frame.remove(story);
     frame.setContentPane(tutorial);
   }
   if (button == tutor) {
     frame.remove(main);
     DesktopLauncher a = new DesktopLauncher();
     a.run();
   }
   if (button == returns1) {
     frame.remove(scores);
     frame.setContentPane(main);
   }
   if (button == returns2) {
     frame.remove(credits);
     frame.setContentPane(main);
   }
   if (button == returns3) {
     frame.remove(story);
     frame.setContentPane(main);
   }
   if (button == returns4) {
     frame.remove(tutorial);
     frame.setContentPane(story);
   }
   frame.validate();
   frame.repaint();
 }
Exemplo n.º 6
0
  @Override
  public void mouseClicked(MouseEvent e) {

    // System.out.println("hit: button"+e.getButton()+" pos:"+e.getPoint());
    if (e.getButton() > 1) return;
    int x = pixelToPosition(e.getX(), 0);
    int y = pixelToPosition(e.getY(), 1);

    if (x >= width || y >= height || x < 0 || y < 0) return;

    synchronized (field.lock) {
      if (e.isShiftDown()) {
        field.aliveCells[x][y] = false;
      } else {
        field.aliveCells[x][y] = true;
      }
    }
    e.consume();

    f.invalidate();
    f.repaint();
  }
Exemplo n.º 7
0
  static void GoEnd(JFrame frame, int i) {
    Image background = new ImageIcon("image/final_" + i + ".png").getImage();
    background =
        background.getScaledInstance(frame.getWidth(), frame.getHeight(), Image.SCALE_DEFAULT);
    JLabel back = new JLabel();
    back.setBounds(0, 0, frame.getWidth(), frame.getHeight());
    back.setIcon(new ImageIcon(background));
    frame.add(back, 1);
    frame.validate();
    frame.repaint();
    if (i == 1) { // 烤好
      Talk.say("你成功的通過了這學期", 1);
      Talk.say("這次經驗也讓你對學習產生濃烈的興趣", 1);
      Talk.say("讓你大四成為了神,進而順利畢業", 1);

    } else if (i == 2) { // 系館
      Talk.say("經由你的捐贈", 1);
      Talk.say("資訊系逐漸自成一個校區", 1);
      Talk.say("而在原系館中庭擺放了一個十倍放大的銅像", 1);
      Talk.say("用來紀念資訊系傑出校友─大恩碩像", 1);

    } else if (i == 3) { // 出國
      Talk.say("你放棄了學業,踏上了桌球國手之路", 1);
      Talk.say("過五關斬六將", 1);
      Talk.say("終於成為了世界桌球王", 1);

    } else if (i == 4) { // 0分 game over
      Talk.say("輕輕的我走了", 1);
      Talk.say("正如我輕輕地來", 1);
      Talk.say("我揮一揮衣袖", 1);
      Talk.say("不帶走任何學分", 1);
    } else if (i == 5) { // final
      Talk.say("你完成了final project", 1);
      Talk.say("跟其他同學一起過了OOP", 1);
      Talk.say("不過大四還有更嚴苛的挑戰在等著你", 1);
      Talk.say("同學!加油吧!", 1);
    }
  }
 /** Repaints the image on the scrollpane. */
 public void repaint() {
   pictureFrame.repaint();
 }
Exemplo n.º 9
0
 public void windowDeiconified(WindowEvent e) {
   frame.repaint();
 }
Exemplo n.º 10
0
 // =======WindowListener Interface:===========================================
 public void windowActivated(WindowEvent e) {
   frame.repaint();
 }
Exemplo n.º 11
0
 @Override
 public void actionPerformed(ActionEvent e) {
   Object source = e.getSource();
   if (source instanceof JButton) {
     if (e.getActionCommand().equals("talleta")) {
       File rivitiedosto = new File(otsikko.getText().concat(".txt"));
       tk.talletaTiedosto(rivitiedosto, textArea.getText());
       tk.talletaBingoOtsikko(otstiedosto, otsikko.getText());
     }
     if (e.getActionCommand().equals("seuraava")) {
       otsikko.setText(tk.haeSeuraava(otstiedosto, otsikko.getText()));
       File rivitiedosto = new File(otsikko.getText().concat(".txt"));
       textArea.setText(tk.haeKaikkiStringiin(rivitiedosto));
     }
     if (e.getActionCommand().equals("edellinen")) {
       otsikko.setText(tk.haeEdellinen(otstiedosto, otsikko.getText()));
       File rivitiedosto = new File(otsikko.getText().concat(".txt"));
       textArea.setText(tk.haeKaikkiStringiin(rivitiedosto));
     }
     if (e.getActionCommand().equals("poista")) {
       File rivitiedosto = new File(otsikko.getText().concat(".txt"));
       tk.poistaTiedosto(rivitiedosto);
       tk.poistaBingoOtsikko(otstiedosto, otsikko.getText());
       textArea.setText("");
       otsikko.setText("Poistettu: " + otsikko.getText());
     }
     if (e.getActionCommand().equals("uusi")) {
       textArea.setText("Kirjoita bingolabelit.\nLabel per rivi.");
       otsikko.setText("Kirjoita uusi bingo");
     }
   } else if (source instanceof JComboBox) {
     JComboBox cb = (JComboBox) e.getSource();
     String valinta = (String) cb.getSelectedItem();
     switch (valinta) {
       case "Pelaa Bingo 3X3":
         koko = 3;
         lkm = 9;
         break;
       case "Pelaa Bingo 5X5":
         koko = 5;
         lkm = 25;
         break;
       case "Pelaa Bingo 7X7":
         koko = 7;
         lkm = 49;
         break;
       case "Pelaa Bingo 8X8":
         koko = 9;
         lkm = 81;
         break;
       case "Pelaa Bingo 10X10":
         koko = 10;
         lkm = 100;
         break;
     }
     if (!valinta.equalsIgnoreCase("")) {
       File rivitiedosto = new File(otsikko.getText().concat(".txt"));
       TiedostoKasittelija pelitk = new TiedostoKasittelija(lkm);
       BingoIkkuna pingoBongo = new BingoIkkuna(pelitk.haeLabelit(rivitiedosto), koko);
       pingoBongo.gui();
     }
   }
   jf.repaint();
   //        textArea.repaint();
 }
Exemplo n.º 12
0
 // draw onscreen if defer is false
 private static void draw() {
   if (defer) return;
   onscreen.drawImage(offscreenImage, 0, 0, null);
   frame.repaint();
 }
Exemplo n.º 13
0
  public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setTitle("Game Of Life");
    JMenuBar toolBar = new JMenuBar();
    JButton start = new JButton(getImageIcon("/icons/play_icon.png"));
    start.setToolTipText("Run");
    start.setBorderPainted(false);
    JButton reset = new JButton(getImageIcon("/icons/reset_icon.png"));
    reset.setToolTipText("Clear field");
    reset.setBorderPainted(false);
    JButton next = new JButton(getImageIcon("/icons/next_icon.png"));
    next.setToolTipText("Next step");
    next.setBorderPainted(false);
    JButton pause = new JButton(getImageIcon("/icons/pause_icon.png"));
    pause.setToolTipText("Pause");
    pause.setBorderPainted(false);
    JButton size = new JButton(getImageIcon("/icons/size_icon.png"));
    size.setToolTipText("Set grid size");
    size.setBorderPainted(false);
    JButton showGrid = new JButton(getImageIcon("/icons/grid_icon.png"));
    showGrid.setToolTipText("Enable/disable grid lines");
    showGrid.setBorderPainted(false);
    JButton btRandom = new JButton(getImageIcon("/icons/dice_icon.png"));
    btRandom.setToolTipText("Fill randomly");
    btRandom.setBorderPainted(false);

    JButton btAbout = new JButton(getImageIcon("/icons/about_icon.png"));
    btAbout.setToolTipText("About");
    btAbout.setBorderPainted(false);

    toolBar.add(start);
    toolBar.add(next);
    toolBar.add(pause);
    toolBar.add(reset);
    toolBar.add(btRandom);
    toolBar.add(size);
    toolBar.add(showGrid);
    toolBar.add(new JSeparator(SwingConstants.VERTICAL));
    toolBar.add(btAbout);

    frame.setJMenuBar(toolBar);
    Toolkit.getDefaultToolkit().getScreenSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setSize(screenSize);
    Grid grid = new Grid(80, 80);
    Envolver envolver = new Envolver(grid, new SimpleTransition());

    /*grid.setValueAt(150, 150, State.Full);

    grid.setValueAt(152, 150, State.Full);
    grid.setValueAt(152, 151, State.Full);

    grid.setValueAt(154, 152, State.Full);
    grid.setValueAt(154, 153, State.Full);
    grid.setValueAt(154, 154, State.Full);

    grid.setValueAt(156, 153, State.Full);
    grid.setValueAt(156, 154, State.Full);
    grid.setValueAt(156, 155, State.Full);

    grid.setValueAt(157, 154, State.Full);*/

    Random random = new Random();

    for (int x = 0; x < grid.getWidth(); x++) {
      for (int y = 0; y < grid.getHeight(); y++) {
        if (random.nextDouble() <= 0.3125) {
          grid.setValueAt(x, y, State.Full);
        }
      }
    }

    GridPanel panel = new GridPanel(grid);
    JScrollPane scrollPane = new JScrollPane(panel);
    scrollPane.setPreferredSize(screenSize);
    // panel.setPreferredSize(screenSize);
    frame.setLayout(new FormLayout("2dlu, default:grow, 2dlu", "2dlu, default:grow, 2dlu"));
    frame.getContentPane().add(scrollPane, CC.xy(2, 2));

    frame.setVisible(true);
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    Runner runner = new Runner(envolver, frame);

    start.addActionListener(e -> runner.start());
    pause.addActionListener(e -> runner.pause());
    size.addActionListener(e -> new SizeDialog(grid, frame));
    reset.addActionListener(
        e -> {
          runner.pause();
          grid.init(grid.getWidth(), grid.getHeight());
          frame.repaint();
        });

    btRandom.addActionListener(
        e -> {
          String result =
              JOptionPane.showInputDialog(
                  null,
                  "Choose the probability for an filled cell:",
                  "Input",
                  JOptionPane.PLAIN_MESSAGE);
          try {
            if (Double.parseDouble(result) <= 1.0 && Double.parseDouble(result) >= 0) {
              runner.pause();
              grid.init(grid.getWidth(), grid.getHeight(), Double.parseDouble(result));
              frame.repaint();
            }
          } catch (NumberFormatException ex) {
            // ignore
          }
        });

    showGrid.addActionListener(
        e -> {
          panel.setShowGrid(!panel.isShowGrid());
          frame.repaint();
        });

    next.addActionListener(
        e -> {
          envolver.evolve();
          frame.repaint();
        });

    btAbout.addActionListener(
        e -> {
          JOptionPane.showMessageDialog(
              null,
              "For more information about the rules\nlook to the corresponding wikipedia article.\nNote that we do not look at an infinite grid!\nA cell at the border of the grid has less neighbours than cells in the center.",
              "About",
              JOptionPane.INFORMATION_MESSAGE);
        });
  }
Exemplo n.º 14
0
  private void initialise() {

    JFrame frame = new JFrame();
    JLayeredPane jLayeredPane = new JLayeredPane();

    frame.setLayout(new BorderLayout());
    frame.setSize(500, 500);
    frame.setLocationRelativeTo(null);

    final DrawingClass drawingClass = new DrawingClass();

    JPanel testPanel =
        new JPanel() {

          @Override
          protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D graphics2D = (Graphics2D) g;
            graphics2D.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            drawingClass.draw(graphics2D, getWidth(), getHeight());

            ActionListener updateTask =
                new ActionListener() {
                  @Override
                  public void actionPerformed(java.awt.event.ActionEvent e) {
                    repaint();
                  }
                };

            new Timer(2, updateTask).start();

            Thread updateThread =
                new Thread() {
                  public void run() {
                    while (true) {
                      repaint();

                      try {
                        // Delay and give other thread a chance to run
                        Thread.sleep(1);
                      } catch (InterruptedException ignore) {
                      }
                    }
                  }
                };

            updateThread.start();
          }

          @Override
          public Dimension getPreferredSize() {
            return new Dimension(500, 500);
          }
        };

    JPanel backgroundImage =
        new JPanel() {

          @Override
          protected void paintComponent(Graphics g) {

            super.paintComponent(g);

            try {

              String urlName =
                  "file:///Users/james/UOW/CSCI213 (Java)/Assignments/Assignment 3/Solutions/src/SydneyOperaHouse.jpg";
              URL url = new URL(urlName);
              Image image = ImageIO.read(url);

              Graphics2D graphics2D = (Graphics2D) g;
              graphics2D.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), null);

            } catch (Exception e) {
              System.out.println("Error Reading Img");
            }
          }

          @Override
          public Dimension getPreferredSize() {
            return new Dimension(500, 500);
          }
        };

    /*
    frame.add(testPanel);
    frame.add(backgroundImage);
    */

    frame.add(testPanel);
    // frame.add(backgroundImage);

    // frame.add(new JLabel(new ImageIcon(URL)));
    // frame.add(testPanel);
    // frame.add(backgroundImage);

    frame.pack();
    frame.setVisible(true);
    frame.repaint();
  }
Exemplo n.º 15
0
 @Override
 public void drawField(GameField field) {
   this.field = field;
   f.invalidate();
   f.repaint();
 }
Exemplo n.º 16
0
 public static void showFrame(boolean show) {
   f.setVisible(show);
   f.repaint();
   return;
 }
Exemplo n.º 17
0
  // Checks the current state and sets the enables/disables
  // accordingly
  public void run() {
    switch (connectionStatus) {
      case DISCONNECTED:
        connectButton.setEnabled(true);
        disconnectButton.setEnabled(false);
        ipField.setEnabled(true);
        portField.setEnabled(true);
        hostOption.setEnabled(true);
        guestOption.setEnabled(true);
        chatLine.setText("");
        chatLine.setEnabled(false);
        statusColor.setBackground(Color.red);
        break;

      case DISCONNECTING:
        connectButton.setEnabled(false);
        disconnectButton.setEnabled(false);
        ipField.setEnabled(false);
        portField.setEnabled(false);
        hostOption.setEnabled(false);
        guestOption.setEnabled(false);
        chatLine.setEnabled(false);
        statusColor.setBackground(Color.orange);
        break;

      case CONNECTED:
        connectButton.setEnabled(false);
        disconnectButton.setEnabled(true);
        ipField.setEnabled(false);
        portField.setEnabled(false);
        hostOption.setEnabled(false);
        guestOption.setEnabled(false);
        chatLine.setEnabled(true);
        statusColor.setBackground(Color.green);
        break;

      case BEGIN_CONNECT:
        connectButton.setEnabled(false);
        disconnectButton.setEnabled(false);
        ipField.setEnabled(false);
        portField.setEnabled(false);
        hostOption.setEnabled(false);
        guestOption.setEnabled(false);
        chatLine.setEnabled(false);
        chatLine.grabFocus();
        statusColor.setBackground(Color.orange);
        break;
    }

    // Make sure that the button/text field states are consistent
    // with the internal states
    ipField.setText(hostIP);
    portField.setText((new Integer(port)).toString());
    hostOption.setSelected(isHost);
    guestOption.setSelected(!isHost);
    statusField.setText(statusString);
    chatText.append(toAppend.toString());
    toAppend.setLength(0);

    mainFrame.repaint();
  }
Exemplo n.º 18
0
 public void setTable(Properties w, MapTableModel t) {
   wordList = w;
   tableModel = t;
   f.repaint();
 }