/** Method to create and initialize the picture frame */
 private void createAndInitPictureFrame() {
   pictureFrame = new JFrame(); // create the JFrame
   pictureFrame.setResizable(true); // allow the user to resize it
   pictureFrame.getContentPane().setLayout(new BorderLayout()); // use border layout
   pictureFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // when close stop
   pictureFrame.setTitle(picture.getTitle());
   PictureExplorerFocusTraversalPolicy newPolicy = new PictureExplorerFocusTraversalPolicy();
   pictureFrame.setFocusTraversalPolicy(newPolicy);
 }
  public static void main(String s[]) {

    // Getting save directory
    String saveDir;
    if (s.length > 0) {
      saveDir = s[0];
    } else {
      saveDir =
          JOptionPane.showInputDialog(
              null,
              "Please enter directory where "
                  + "the images is/will be saved\n\n"
                  + "Also possible to specifiy as argument 1 when "
                  + "running this program.",
              "l:\\webcamtest");
    }

    String layout = "";
    if (s.length > 1) {
      layout = s[1];
    }

    // Move mouse to the point 5000,5000 px (out of the screen)
    Robot rob;
    try {
      rob = new Robot();
      rob.setAutoDelay(500); // 0,5 s
      rob.mouseMove(5000, 5000);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    // Make the main window
    JFrame frame = new JFrame();
    frame.setAlwaysOnTop(true);
    frame.setTitle(
        "Webcam capture and imagefading - "
            + "Vitenfabrikken Jærmuseet - "
            + "made by Hallvard Nygård - "
            + "Vitenfabrikken.no / Jaermuseet.no");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setUndecorated(true);

    WebcamCaptureAndFadePanel panel = new WebcamCaptureAndFadePanel(saveDir, layout);
    frame.getContentPane().add(panel);
    frame.addKeyListener(panel);
    frame.pack();

    frame.setVisible(true);
  }
  // init
  private static void init() {
    if (frame != null) frame.setVisible(false);

    frame = new JFrame();
    offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    offscreen = offscreenImage.createGraphics();
    onscreen = onscreenImage.createGraphics();
    setXscale();
    setYscale();
    offscreen.setColor(DEFAULT_CLEAR_COLOR);
    offscreen.fillRect(0, 0, width, height);
    setPenColor();
    setPenRadius();
    setFont();
    clear();

    // add anti-aliasing
    RenderingHints hints =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    offscreen.addRenderingHints(hints);

    // frame stuff
    ImageIcon icon = new ImageIcon(onscreenImage);
    JLabel draw = new JLabel(icon);

    draw.addMouseListener(std);
    draw.addMouseMotionListener(std);

    frame.setContentPane(draw);
    frame.addKeyListener(std); // JLabel cannot get keyboard focus
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows
    // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // closes only current window
    frame.setTitle("Standard Draw");
    frame.setJMenuBar(createMenuBar());
    frame.pack();
    frame.requestFocusInWindow();
    frame.setVisible(true);
  }
Example #4
0
  static void buildGUI() {
    // Need this size to balance axes.
    frame.setSize(520, 690);
    frame.setTitle("DrawTool");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    Container cPane = frame.getContentPane();

    // Status label on top. Unused for now.
    statusLabel.setOpaque(true);
    statusLabel.setBackground(Color.white);
    cPane.add(statusLabel, BorderLayout.NORTH);

    // Build the input/output elements at the bottom.
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    panel.setBackground(inputPanelColor);
    panel.setLayout(new GridLayout(2, 1));
    panel.add(outputLabel);
    JPanel bottomPanel = new JPanel();
    bottomPanel.setBackground(inputPanelColor);
    bottomPanel.add(inputField);
    bottomPanel.add(new JLabel("   "));
    JButton enterButton = new JButton("Enter");
    enterButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent a) {
            hasEntered = true;
          }
        });
    bottomPanel.add(enterButton);
    panel.add(bottomPanel);
    if (!sequencingOn) {
      cPane.add(panel, BorderLayout.SOUTH);
    }

    // Drawing in the center.
    drawArea = new DrawTool();
    if (sequencingOn) {
      frame.addKeyListener(
          new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
              handleKeyTyped(e);
            }
          });
    }
    cPane.add(drawArea, BorderLayout.CENTER);

    drawArea.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            handleMouseClick(e);
          }

          public void mouseReleased(MouseEvent e) {
            handleMouseReleased(e);
          }
        });

    drawArea.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            handleMouseDragged(e);
          }
        });
  }
 /**
  * Set the title of the frame
  *
  * @param title the title to use in the JFrame
  */
 public void setTitle(String title) {
   pictureFrame.setTitle(title);
 }
Example #6
0
 public static void setTitle(String title) {
   frame.setTitle(title);
 }