Exemple #1
0
  void jbInit() throws Exception {
    panel1.setLayout(borderLayout1);
    panel2.setBackground(Color.yellow);
    panel2.setLayout(borderLayout2);
    ButtonOK.setLabel("OK");
    ButtonOK.addMouseListener(
        new java.awt.event.MouseAdapter() {

          public void mouseClicked(MouseEvent e) {
            ButtonOK_mouseClicked(e);
          }
        });

    String s1 = CallingApp.MotherApplet.GetName();

    textArea1.setBackground(SystemColor.control);
    textArea1.setEditable(false);

    panel1.add(panel2, BorderLayout.CENTER);
    panel2.add(textArea1, BorderLayout.CENTER);
    panel1.add(panel3, BorderLayout.SOUTH);
    panel3.add(ButtonOK, null);
    String s =
        s1
            + " v:"
            + CallingApp.MotherApplet.GetVersionNum()
            + "\n"
            + CallingApp.MotherApplet.GetInfos();
    textArea1.setText(s);
  }
 public void adjustmentValueChanged(AdjustmentEvent e) {
   Object ob = e.getSource();
   int p, q, r;
   p = s1.getValue();
   q = s2.getValue();
   r = s3.getValue();
   Color c = new Color(p, q, r);
   p1.setBackground(c);
 }
  /** Constructor. */
  private HeaderPanel() {
    setBackground(BACKGROUND_COLOR);
    setLayout(cardLayout);

    add(functionCard, FUNCTION);
    add(messageCard, MESSAGE);

    functionCard.setBackground(BACKGROUND_COLOR);
    functionCard.setLayout(new BorderLayout());

    messageCard.setBackground(BACKGROUND_COLOR);
    messageCard.setLayout(new BorderLayout());

    label.setFont(new Font("Dialog", Font.BOLD, 12));
    label.setAlignment(Label.CENTER);
    label.setForeground(Color.black);

    messageCard.add(label, BorderLayout.CENTER);
  }
  public void updateColor(Color c, Object source) {
    // record colour for the object
    rgb = c.getRGB();

    if (source != red && source != green && source != blue) {
      red.setIntValue((rgb & 0xff0000) >> 16);
      green.setIntValue((rgb & 0xff00) >> 8);
      blue.setIntValue((rgb & 0xff));

      hexText.setText("0x" + String.format("%06x", rgb & 0xffffff));
    }

    colorSample.setBackground(c);
    colorSample.repaint();
  }
  public TheWorld() {
    super("This is the world, and God says...");

    p = new Panel();
    p.setBackground(Color.black);

    add(p);
    btnLight = new LetThereBeLightCommand("Let there be light", p);
    btnLand = new LetThereBeLandCommand("Let there be land", p);
    btnReset = new ResetCommand("Reset", p);
    btnExit = new GodRestsCommand("God rests");

    p.add(btnLight);
    p.add(btnLand);
    p.add(btnReset);
    p.add(btnExit);

    btnLight.addActionListener(this);
    btnLand.addActionListener(this);
    btnReset.addActionListener(this);
    btnExit.addActionListener(this);
    setBounds(100, 100, 400, 200);
    setVisible(true);
  }
  public void init() {
    try {
      robot = new Robot();
    } catch (AWTException ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
    this.setLayout(new BorderLayout());

    target.setBackground(Color.green);
    target.setName("GreenBox"); // for the ease of debug
    target.setPreferredSize(new Dimension(100, 100));
    String toolkit = Toolkit.getDefaultToolkit().getClass().getName();

    // on X systems two buttons are reserved for wheel though they are countable by MouseInfo.
    int buttonsNumber =
        toolkit.equals("sun.awt.windows.WToolkit")
            ? MouseInfo.getNumberOfButtons()
            : MouseInfo.getNumberOfButtons() - 2;

    for (int i = 0; i < 8; i++) {
      buttonNumber.add("BUTTON" + (i + 1) + "_MASK");
    }

    pressOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now pressing : " + (buttonNumber.getSelectedIndex() + 1));

            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    releaseOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now releasing : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    clickOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now clicking : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });
    target.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseReleased(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseClicked(MouseEvent e) {
            Sysout.println("" + e);
          }
        });

    String[] instructions = {
      "Do provide an instruction to the robot by",
      "choosing the button number to act and ",
      "pressing appropriate java.awt.Button on the left.",
      "Inspect an output in the TextArea below.",
      "Please don't generate non-natural sequences like Release-Release, etc.",
      "If you use keyboard be sure that you released the keyboard shortly.",
      "If events are generated well press Pass, otherwise Fail."
    };
    Sysout.createDialogWithInstructions(instructions);
  } // End  init()
Exemple #7
0
  /**
   * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is
   * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ.
   */
  public ImageJ(java.applet.Applet applet, int mode) {
    super("ImageJ");
    if ((mode & DEBUG) != 0) IJ.setDebugMode(true);
    mode = mode & 255;
    if (IJ.debugMode) IJ.log("ImageJ starting in debug mode: " + mode);
    embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW);
    this.applet = applet;
    String err1 = Prefs.load(this, applet);
    setBackground(backgroundColor);
    Menus m = new Menus(this, applet);
    String err2 = m.addMenuBar();
    m.installPopupMenu(this);
    setLayout(new BorderLayout());

    // Tool bar
    toolbar = new Toolbar();
    toolbar.addKeyListener(this);
    add("Center", toolbar);

    // Status bar
    statusBar = new Panel();
    statusBar.setLayout(new BorderLayout());
    statusBar.setForeground(Color.black);
    statusBar.setBackground(backgroundColor);
    statusLine = new JLabel();
    statusLine.setFont(new Font("SansSerif", Font.PLAIN, 13));
    statusLine.addKeyListener(this);
    statusLine.addMouseListener(this);
    statusBar.add("Center", statusLine);
    progressBar = new ProgressBar(120, 20);
    progressBar.addKeyListener(this);
    progressBar.addMouseListener(this);
    statusBar.add("East", progressBar);
    add("South", statusBar);

    IJ.init(this, applet);
    addKeyListener(this);
    addWindowListener(this);
    setFocusTraversalKeysEnabled(false);
    m.installStartupMacroSet(); // add custom tools
    runStartupMacro();

    Point loc = getPreferredLocation();
    Dimension tbSize = toolbar.getPreferredSize();
    setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug
    if (mode != NO_SHOW) {
      if (IJ.isWindows())
        try {
          setIcon();
        } catch (Exception e) {
        }
      setLocation(loc.x, loc.y);
      setResizable(!IJ.isMacOSX());
      pack();
      setVisible(true);
    }
    if (err1 != null) IJ.error(err1);
    if (err2 != null) {
      IJ.error(err2);
      IJ.runPlugIn("ij.plugin.ClassChecker", "");
    }
    if (IJ.isMacintosh() && applet == null) {
      Object qh = null;
      qh = IJ.runPlugIn("MacAdapter", "");
      if (qh == null) IJ.runPlugIn("QuitHandler", "");
    }
    if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", "");
    String str = m.getMacroCount() == 1 ? " macro" : " macros";
    IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str);
    configureProxy();
    if (applet == null) loadCursors();
  }
Exemple #8
0
  /**
   * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is
   * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ.
   */
  public ImageJ(java.applet.Applet applet, int mode) {
    super("ImageJ");
    embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW);
    this.applet = applet;
    String err1 = Prefs.load(this, applet);
    if (IJ.isLinux()) {
      backgroundColor = new Color(240, 240, 240);
      setBackground(backgroundColor);
    }
    Menus m = new Menus(this, applet);
    String err2 = m.addMenuBar();
    m.installPopupMenu(this);
    setLayout(new GridLayout(2, 1));

    // Tool bar
    toolbar = new Toolbar();
    toolbar.addKeyListener(this);
    add(toolbar);

    // Status bar
    statusBar = new Panel();
    statusBar.setLayout(new BorderLayout());
    statusBar.setForeground(Color.black);
    statusBar.setBackground(backgroundColor);
    statusLine = new Label();
    statusLine.setFont(SansSerif12);
    statusLine.addKeyListener(this);
    statusLine.addMouseListener(this);
    statusBar.add("Center", statusLine);
    progressBar = new ProgressBar(120, 20);
    progressBar.addKeyListener(this);
    progressBar.addMouseListener(this);
    statusBar.add("East", progressBar);
    statusBar.setSize(toolbar.getPreferredSize());
    add(statusBar);

    IJ.init(this, applet);
    addKeyListener(this);
    addWindowListener(this);
    setFocusTraversalKeysEnabled(false);

    Point loc = getPreferredLocation();
    Dimension tbSize = toolbar.getPreferredSize();
    int ijWidth = tbSize.width + 10;
    int ijHeight = 100;
    setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug
    if (mode != NO_SHOW) {
      if (IJ.isWindows())
        try {
          setIcon();
        } catch (Exception e) {
        }
      setBounds(loc.x, loc.y, ijWidth, ijHeight); // needed for pack to work
      setLocation(loc.x, loc.y);
      pack();
      setResizable(!(IJ.isMacintosh() || IJ.isWindows())); // make resizable on Linux
      show();
    }
    if (err1 != null) IJ.error(err1);
    if (err2 != null) {
      IJ.error(err2);
      IJ.runPlugIn("ij.plugin.ClassChecker", "");
    }
    m.installStartupMacroSet();
    if (IJ.isMacintosh() && applet == null) {
      Object qh = null;
      qh = IJ.runPlugIn("MacAdapter", "");
      if (qh == null) IJ.runPlugIn("QuitHandler", "");
    }
    if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", "");
    String str = m.getMacroCount() == 1 ? " macro" : " macros";
    IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str);
    // if (applet==null && !embedded && Prefs.runSocketListener)
    //	new SocketListener();
    configureProxy();
    if (applet == null) loadCursors();
  }
Exemple #9
0
  public void init() {
    sounds = new TetrisSound();
    installNewPiece();

    pause_resume_butt.setEnabled(false);
    start_newgame_butt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            if (start_newgame_butt.getLabel().equals("Start")) startGame();
            else newGame();
          }
        });
    pause_resume_butt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            if (pause_resume_butt.getLabel().equals("Pause")) pauseGame();
            else resumeGame();
          }
        });

    KeyListener key_listener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (timer.isPaused()) return;
            if (e.getKeyCode() == 37 || e.getKeyCode() == 39) {
              int dir = e.getKeyCode() == 37 ? -1 : 1;
              synchronized (timer) {
                cur_piece.cut();
                cur_piece.setX(cur_piece.getX() + dir);
                if (!cur_piece.canPaste()) cur_piece.setX(cur_piece.getX() - dir);
                cur_piece.paste();
              }
              game_grid.repaint();
            } else if (e.getKeyCode() == 38) {
              synchronized (timer) {
                cur_piece.cut();
                cur_piece.rotate();
                if (!cur_piece.canPaste()) cur_piece.rotateBack();
                cur_piece.paste();
              }
              game_grid.repaint();
            }
            if (e.getKeyCode() == 40) {
              timer.setFast(true);
            }
          }
        };

    start_newgame_butt.addKeyListener(key_listener);
    pause_resume_butt.addKeyListener(key_listener);

    Panel right_panel = new Panel(new GridLayout(3, 1));
    right_panel.setBackground(BACKGROUND_COLOR);

    Panel control_panel = new Panel();
    control_panel.add(start_newgame_butt);
    control_panel.add(pause_resume_butt);
    control_panel.setBackground(BACKGROUND_COLOR);
    right_panel.add(control_panel);

    Panel tmp = new Panel(new BorderLayout());
    tmp.add("North", new TetrisLabel("    Next Piece:"));
    tmp.add("Center", next_piece_canvas);
    tmp.setBackground(BACKGROUND_COLOR);
    right_panel.add(tmp);

    Panel stats_panel = new Panel(new GridLayout(4, 2));
    stats_panel.add(new TetrisLabel("    Rows Deleted: "));
    stats_panel.add(rows_deleted_label);
    stats_panel.add(new TetrisLabel("    Level: "));
    stats_panel.add(level_label);
    stats_panel.add(new TetrisLabel("    Score: "));
    stats_panel.add(score_label);
    stats_panel.add(new TetrisLabel("    High Score: "));
    stats_panel.add(high_score_label);
    tmp = new Panel(new BorderLayout());
    tmp.setBackground(BACKGROUND_COLOR);
    tmp.add("Center", stats_panel);
    right_panel.add(tmp);

    this.setLayout(new GridLayout(1, 2));
    this.add(game_grid);
    this.add(right_panel);
    this.setBackground(BACKGROUND_COLOR);
    this.validate();
  }
 public void Execute() {
   p.setBackground(Color.black);
 }