public void openCaptureWindow() {
    if (framenr - lastcapture_framenr < number_of_frames_before_cwopen) {
      return;
    }

    // Capture Window
    cw.setVisible(true);
    cw.toFront();

    // Timer for closing the capturewindow
    TimerTask task =
        new TimerTask() {

          @Override
          public void run() {
            EventQueue.invokeLater(
                new Runnable() {
                  public void run() {
                    System.out.println("Closing cw...");
                    cw.setVisible(false);
                    cwText.setText(""); // Empty text in case there is a text
                  }
                });
          }
        };
    cwTimer = new Timer();
    cwTimer.schedule(task, number_of_second_capturewindow * 1000);
  }
Esempio n. 2
0
  private void _displayRespStrInFrame() {

    final JFrame frame = new JFrame("Google Static Map - Error");
    GUIUtils.setAppIcon(frame, "69.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JTextArea response = new JTextArea(_respStr, 25, 80);
    response.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {
            /*frame.dispose();*/
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });

    frame.setContentPane(new JScrollPane(response));
    frame.pack();

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
  }
Esempio n. 3
0
  private MainPanel(final JFrame frame) {
    super();
    add(check);
    setPreferredSize(new Dimension(320, 240));

    if (!SystemTray.isSupported()) {
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      return;
    }
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowIconified(WindowEvent e) {
            if (check.isSelected()) {
              e.getWindow().dispose();
            }
          }
        });
    // or
    // frame.addWindowStateListener(new WindowStateListener() {
    //    @Override public void windowStateChanged(WindowEvent e) {
    //        if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) {
    //            e.getWindow().dispose();
    //        }
    //    }
    // });

    final SystemTray tray = SystemTray.getSystemTray();
    Dimension d = tray.getTrayIconSize();
    BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height);
    final PopupMenu popup = new PopupMenu();
    final TrayIcon icon = new TrayIcon(image, "TRAY", popup);

    MenuItem item1 = new MenuItem("OPEN");
    item1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.setVisible(true);
          }
        });
    MenuItem item2 = new MenuItem("EXIT");
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            tray.remove(icon);
            frame.dispose();
            // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });
    popup.add(item1);
    popup.add(item2);

    try {
      tray.add(icon);
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
  private void initGUI() {

    JPanel pCommand = new JPanel();

    pResult = new JPanel();
    nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand, pResult);

    pCommand.setLayout(new BorderLayout());
    pResult.setLayout(new BorderLayout());

    Font fFont = new Font("Dialog", Font.PLAIN, 12);

    txtCommand = new JTextArea(5, 40);

    txtCommand.setMargin(new Insets(5, 5, 5, 5));
    txtCommand.addKeyListener(this);

    txtCommandScroll = new JScrollPane(txtCommand);
    txtResult = new JTextArea(20, 40);

    txtResult.setMargin(new Insets(5, 5, 5, 5));

    txtResultScroll = new JScrollPane(txtResult);

    txtCommand.setFont(fFont);
    txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
    /*
    // button replaced by toolbar
            butExecute = new JButton("Execute");

            butExecute.addActionListener(this);
            pCommand.add(butExecute, BorderLayout.EAST);
    */
    pCommand.add(txtCommandScroll, BorderLayout.CENTER);

    gResult = new GridSwing();
    gResultTable = new JTable(gResult);
    gScrollPane = new JScrollPane(gResultTable);

    // getContentPane().setLayout(new BorderLayout());
    pResult.add(gScrollPane, BorderLayout.CENTER);

    // Set up the tree
    rootNode = new DefaultMutableTreeNode("Connection");
    treeModel = new DefaultTreeModel(rootNode);
    tTree = new JTree(treeModel);
    tScrollPane = new JScrollPane(tTree);

    tScrollPane.setPreferredSize(new Dimension(120, 400));
    tScrollPane.setMinimumSize(new Dimension(70, 100));
    txtCommandScroll.setPreferredSize(new Dimension(360, 100));
    txtCommandScroll.setMinimumSize(new Dimension(180, 100));
    gScrollPane.setPreferredSize(new Dimension(460, 300));

    ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tScrollPane, nsSplitPane);

    fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER);
    doLayout();
    fMain.pack();
  }
 /** 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);
 }
  /** Method to create the menu bar, menus, and menu items */
  private void setUpMenuBar() {
    // create menu
    menuBar = new JMenuBar();
    zoomMenu = new JMenu("Zoom");
    twentyFive = new JMenuItem("25%");
    fifty = new JMenuItem("50%");
    seventyFive = new JMenuItem("75%");
    hundred = new JMenuItem("100%");
    hundred.setEnabled(false);
    hundredFifty = new JMenuItem("150%");
    twoHundred = new JMenuItem("200%");
    fiveHundred = new JMenuItem("500%");

    // add the action listeners
    twentyFive.addActionListener(this);
    fifty.addActionListener(this);
    seventyFive.addActionListener(this);
    hundred.addActionListener(this);
    hundredFifty.addActionListener(this);
    twoHundred.addActionListener(this);
    fiveHundred.addActionListener(this);

    // add the menu items to the menus
    zoomMenu.add(twentyFive);
    zoomMenu.add(fifty);
    zoomMenu.add(seventyFive);
    zoomMenu.add(hundred);
    zoomMenu.add(hundredFifty);
    zoomMenu.add(twoHundred);
    zoomMenu.add(fiveHundred);
    menuBar.add(zoomMenu);

    // set the menu bar to this menu
    pictureFrame.setJMenuBar(menuBar);
  }
  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);
  }
Esempio n. 8
0
  public static void main(String[] args) {

    Global.debugging = true;

    // make frame

    final JFrame frame = new JFrame("Test Client Game");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // make game
    ClientGame game = null;
    String[] names = {
      "Alpha", "Beta", "Charlie", "Delta", "Epsilon", "Foxtrot", "Gamma", "Hurricane"
    };
    int ptr = 0;

    while (true) {
      try {
        game = new ClientGame(names[ptr++], (args.length > 1 ? args[1] : "localhost"));
        break;
      } catch (ClientNameException ex) {
        System.err.println(ex);
      } catch (IOException ex) {
        System.err.println("Could not connect to server");
      }
    }

    // add controls to frame

    game.getPlayerShip().getControls().setContainer(frame);

    // add full screen toggle

    FullScreenToggle.addToggleToGame(frame, game, KeyEvent.VK_F11);

    // add game to frame

    frame.add(game);

    // show frame

    frame.pack();
    frame.setVisible(true);

    game.startTheGame();
  }
  /** Creates the JFrame and sets everything up */
  private void createWindow() {
    // create the picture frame and initialize it
    createAndInitPictureFrame();

    // set up the menu bar
    setUpMenuBar();

    // create the information panel
    createInfoPanel();

    // creates the scrollpane for the picture
    createAndInitScrollingImage();

    // show the picture in the frame at the size it needs to be
    pictureFrame.pack();
    pictureFrame.setVisible(true);
  }
  /** Create and initialize the scrolling image */
  private void createAndInitScrollingImage() {
    scrollPane = new JScrollPane();

    BufferedImage bimg = picture.getBufferedImage();
    imageDisplay = new ImageDisplay(bimg);
    imageDisplay.addMouseMotionListener(this);
    imageDisplay.addMouseListener(this);
    imageDisplay.setToolTipText("Click a mouse button on a pixel to see the pixel information");
    scrollPane.setViewportView(imageDisplay);
    pictureFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
  }
Esempio n. 11
0
  // 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);
  }
Esempio n. 12
0
  /** Returns a DebugGraphics for use in buffering window. */
  private Graphics debugGraphics() {
    DebugGraphics debugGraphics;
    DebugGraphicsInfo info = info();
    JFrame debugFrame;

    if (info.debugFrame == null) {
      info.debugFrame = new JFrame();
      info.debugFrame.setSize(500, 500);
    }
    debugFrame = info.debugFrame;
    debugFrame.show();
    debugGraphics = new DebugGraphics(debugFrame.getGraphics());
    debugGraphics.setFont(getFont());
    debugGraphics.setColor(getColor());
    debugGraphics.translate(xOffset, yOffset);
    debugGraphics.setClip(getClipBounds());
    if (debugFlash()) {
      debugGraphics.setDebugOptions(FLASH_OPTION);
    }
    return debugGraphics;
  }
Esempio n. 13
0
  /**
   * @param filenames
   * @exception Exception if internal error
   */
  public ChestImageViewer(String filenames[]) throws Exception {
    DisplayDeviceArea[] displayDeviceAreas = getPresentationAndImageDeviceAreas();
    if (displayDeviceAreas == null) {
      System.err.println("Cannot determine device display areas");
    } else {
      System.err.println("Found " + displayDeviceAreas.length + " device display areas");
      for (int i = 0; i < displayDeviceAreas.length; ++i) {
        System.err.println("[" + i + "] = " + displayDeviceAreas[i]);
        displayDeviceAreas[i].getFrame().setBackground(Color.black);
        displayDeviceAreas[i].getFrame().setVisible(true);
      }

      {
        // Need to actually add something to the unused left display frame, else background will not
        // be set to black on Windows
        JPanel backgroundPanel = new JPanel();
        backgroundPanel.setBackground(Color.black);
        displayDeviceAreas[0].getFrame().getContentPane().add(backgroundPanel);
        displayDeviceAreas[0].getFrame().validate();
      }

      frame = displayDeviceAreas[1].getFrame();

      Container content = frame.getContentPane();
      content.setLayout(new GridLayout(1, 1));
      multiPanel = new JPanel();
      // multiPanel.setBackground(Color.black);
      frameWidth = (int) frame.getWidth();
      frameHeight = (int) frame.getHeight();
      Dimension d = new Dimension(frameWidth, frameHeight);
      // multiPanel.setSize(d);
      multiPanel.setPreferredSize(d);
      multiPanel.setBackground(Color.black);
      content.add(multiPanel);
      // frame.pack();
      content.validate();

      loadMultiPanelFromSpecifiedFiles(filenames);
    }
  }
Esempio n. 14
0
  public static void main(String args[]) throws Exception {

    JFrame ventana = new JFrame("Image");
    // int k=5;
    String n;
    int c[] = new int[9];

    n = "C:\\BORLANDC\\BIN\\CIMG1098.jpg";

    // n[1]="C:\\BORLANDC\\BIN\\sd";

    ventana.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            System.exit(0);
          }
        });
    ventana.getContentPane().add(new erosion(n), BorderLayout.CENTER);

    ventana.setSize(1000, 1000);

    ventana.setVisible(true);

    /*  ventana.addWindowListener( new WindowAdapter() {
         public void windowClosing( WindowEvent evt ){
    System.exit( 0 );
         }
       } );
       ventana.getContentPane().add( new GetImage(),BorderLayout.CENTER );
       ventana.setSize( 500,500 );

       ventana.setVisible( true );

    /*
    GetImage image = new GetImage();
       image.setSize(400, 340);
       image.setVisible(true);
       image.setLocation(200, 100);*/
  }
  public void windowClosing(WindowEvent ev) {

    try {
      cConn.close();
    } catch (Exception e) {
    }

    fMain.dispose();

    if (bMustExit) {
      System.exit(0);
    }
  }
Esempio n. 16
0
 public static void main(String[] args) {
   MojamComponent mc = new MojamComponent();
   JFrame frame = new JFrame();
   JPanel panel = new JPanel(new BorderLayout());
   panel.add(mc);
   frame.setContentPane(panel);
   frame.pack();
   frame.setResizable(false);
   frame.setLocationRelativeTo(null);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
   mc.start();
 }
Esempio n. 17
0
  public void setVisible(boolean bl) {
    if (false) {
      // <Begin_setVisible_boolean>
      if (bl) {
        init();
        start();
      } else {
        stop();
      }
      super.setVisible(bl);

      // <End_setVisible_boolean>

    }
  }
Esempio n. 18
0
 public static void createAndShowGUI() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | UnsupportedLookAndFeelException ex) {
     ex.printStackTrace();
   }
   JFrame frame = new JFrame("@title@");
   frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   frame.getContentPane().add(new MainPanel());
   frame.pack();
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
  /** Creates the North JPanel with all the pixel location and color information */
  private void createInfoPanel() {
    // create the info panel and set the layout
    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new BorderLayout());

    // create the font
    Font largerFont = new Font(infoPanel.getFont().getName(), infoPanel.getFont().getStyle(), 14);

    // create the pixel location panel
    JPanel locationPanel = createLocationPanel(largerFont);

    // create the color information panel
    JPanel colorInfoPanel = createColorInfoPanel(largerFont);

    // add the panels to the info panel
    infoPanel.add(BorderLayout.NORTH, locationPanel);
    infoPanel.add(BorderLayout.SOUTH, colorInfoPanel);

    // add the info panel
    pictureFrame.getContentPane().add(BorderLayout.NORTH, infoPanel);
  }
Esempio n. 20
0
 public static void createAndShowGUI() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | UnsupportedLookAndFeelException ex) {
     ex.printStackTrace();
   }
   JFrame frame = new JFrame("@title@");
   frame.setIconImages(
       Arrays.asList(
           makeBufferedImage(new StarIcon(), 16, 16),
           makeBufferedImage(new StarIcon(16, 8, 5), 40, 40)));
   // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   // frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
   frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   frame.getContentPane().add(new MainPanel(frame));
   frame.setResizable(false);
   frame.pack();
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
Esempio n. 21
0
  public void run() {
    String objRouter = applet.getParameter("name");
    // No Internationalisation
    try {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream outp = new DataOutputStream(byteStream);
      outp.writeInt(GenericConstants.ROUTER_PROPERTIES);
      outp.writeUTF(objRouter);
      outp.flush();

      byte[] bytes = byteStream.toByteArray();
      outp.close();
      byteStream.reset();
      byteStream.close();
      byte[] data = GenericSession.getInstance().syncSend(bytes);
      if (data != null) {
        DataInputStream inp = new DataInputStream(new ByteArrayInputStream(data));
        int reqId = inp.readInt();
        if (reqId == GenericConstants.ROUTER_PROPERTIES) {
          int length = inp.readInt();
          byte serverData[] = new byte[length];
          inp.readFully(serverData);
          routerobject = NmsClientUtil.deSerializeVector(serverData);
        }

        init();
        refresh();
        super.setVisible(true);
      }
      /*init();
      refresh();
      super.setVisible(true);*/

      else close();

    } catch (Exception e) {
      // NmsClientUtil.err(NmsClientUtil.getFrame(app),"IO Error sending request to server.
      // "+e);//No Internationalisation
    }
  }
 public static void main(String s[]) {
   if (s.length > 0) j2kfilename = s[0];
   else j2kfilename = "girl";
   System.out.println(j2kfilename);
   isApplet = false;
   JFrame f = new JFrame("ImageViewer");
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   JApplet applet = new ImageViewer();
   f.getContentPane().add("Center", applet);
   applet.init();
   f.pack();
   f.setSize(new Dimension(550, 550));
   f.show();
 }
Esempio n. 23
0
  public static void main(String args[]) throws Exception {
    final JFrame frame = new JFrame();
    final JTextArea textArea = new JTextArea(30, 60);
    final JScrollPane scrollPane = new JScrollPane(textArea);
    frame.getContentPane().add(scrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    ScreenCapture.createImage(menu, "menu.jpg");
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Frame Image");
    menu.add(menuItem);
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            //  Let the menu close and repaint itself before taking the image

            new Thread() {
              public void run() {
                try {
                  Thread.sleep(50);
                  System.out.println("Creating frame.jpg");
                  frame.repaint();
                  ScreenCapture.createImage(frame, "frame.jpg");
                } catch (Exception exc) {
                  System.out.println(exc);
                }
              }
            }.start();
          };
        });

    final JButton button = new JButton("Create Images");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              System.out.println("Creating desktop.jpg");
              ScreenCapture.createDesktopImage("desktop.jpg");
              System.out.println("Creating frame.jpg");
              ScreenCapture.createImage(frame, "frame.jpg");
              System.out.println("Creating scrollpane.jpg");
              ScreenCapture.createImage(scrollPane, "scrollpane.jpg");
              System.out.println("Creating textarea.jpg");
              ScreenCapture.createImage(textArea, "textarea.jpg");
              System.out.println("Creating button.jpg");
              ScreenCapture.createImage(button, "button.jpg");
              button.setText("button refreshed");
              button.paintImmediately(button.getBounds());
              System.out.println("Creating refresh.jpg");
              ScreenCapture.createImage(button, "refresh.jpg");
              System.out.println("Creating region.jpg");
              Rectangle r = new Rectangle(0, 0, 100, 16);
              ScreenCapture.createImage(textArea, r, "region.png");
            } catch (Exception exc) {
              System.out.println(exc);
            }
          }
        });
    frame.getContentPane().add(button, BorderLayout.SOUTH);

    try {
      FileReader fr = new FileReader("ScreenCapture.java");
      BufferedReader br = new BufferedReader(fr);
      textArea.read(br, null);
      br.close();
    } catch (Exception e) {
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
Esempio n. 24
0
  /** @param args */
  public static void main(String[] args) {
    JPanel boxPane = new JPanel(new BorderLayout());
    // boxPane.setLayout(new BoxLayout(boxPane, BoxLayout.LINE_AXIS));
    // boxPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    // boxPane.add(Box.createVerticalGlue());
    Example1 ex = new Example1();
    // boxPane.add(ex);

    boxPane.add(Box.createRigidArea(new Dimension(10, 0)));
    Button btnStartStop = new Button("Start / Stop");
    btnStartStop.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            log.info("Suspending / Resuming the simulation thread, current state = " + helper.stop);
            if (helper.stop == true) helper.unpause();
            else helper.pause();
          }
        });
    // btnStartStop.setMaximumSize(new Dimension(100, 100));
    boxPane.add(btnStartStop, BorderLayout.PAGE_START);

    JScrollPane worldScrollPane = new JScrollPane(ex);

    final JSplitPane splitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, worldScrollPane, boxPane);
    splitPane.setResizeWeight(0.5);
    splitPane.setOneTouchExpandable(true);
    splitPane.setContinuousLayout(true);

    worldScrollPane.addAncestorListener(
        new AncestorListener() {
          @Override
          public void ancestorRemoved(AncestorEvent arg0) {
            splitPane.repaint();
          }

          @Override
          public void ancestorMoved(AncestorEvent arg0) {
            splitPane.repaint();
          }

          @Override
          public void ancestorAdded(AncestorEvent arg0) {
            splitPane.repaint();
          }
        });

    JFrame f = new JFrame();
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    f.add(splitPane, BorderLayout.CENTER);
    // f.add(boxPane);
    f.pack();
    f.setVisible(true);

    helper = new SimulationHelper(ex.getGraphics());

    helper.start();

    // layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));

  }
 /**
  * Set the title of the frame
  *
  * @param title the title to use in the JFrame
  */
 public void setTitle(String title) {
   pictureFrame.setTitle(title);
 }
 /** Repaints the image on the scrollpane. */
 public void repaint() {
   pictureFrame.repaint();
 }
Esempio n. 27
0
 // draw onscreen if defer is false
 private static void draw() {
   if (defer) return;
   onscreen.drawImage(offscreenImage, 0, 0, null);
   frame.repaint();
 }
Esempio n. 28
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);
          }
        });
  }
Esempio n. 29
0
 public static void display() {
   // Store reference to frame for use in dialogs.
   frame = new JFrame();
   buildGUI();
   frame.setVisible(true);
 }
  public static void main(String[] args) {
    // read filename and N 2 parameters
    String fileName = args[0];
    N = Integer.parseInt(args[1]);

    // output two images, one original image at left, the other result image at right
    BufferedImage imgOriginal =
        new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    BufferedImage img = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);

    try {
      File file = new File(fileName);
      InputStream is = new FileInputStream(file);

      long len = file.length();
      byte[] bytes = new byte[(int) len];

      int offset = 0;
      int numRead = 0;
      while (offset < bytes.length
          && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
        offset += numRead;
      }

      int ind = 0;
      for (int y = 0; y < IMAGE_HEIGHT; y++) {
        for (int x = 0; x < IMAGE_WIDTH; x++) {
          // for reading .raw image to show as a rgb image
          byte r = bytes[ind];
          byte g = bytes[ind];
          byte b = bytes[ind];

          // set pixel for display original image
          int pixOriginal = 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
          imgOriginal.setRGB(x, y, pixOriginal);
          ind++;
        }
      }
      is.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    int[] vectorSpace = calculateVectorSpace(imgOriginal);

    // quantization
    for (int y = 0; y < IMAGE_HEIGHT; y++) {
      for (int x = 0; x < IMAGE_WIDTH; x++) {
        int clusterId = vectorSpace[IMAGE_WIDTH * y + x];
        img.setRGB(x, y, clusters[clusterId].getPixel());
      }
    }

    // Use a panel and label to display the image
    JPanel panel = new JPanel();
    panel.add(new JLabel(new ImageIcon(imgOriginal)));
    panel.add(new JLabel(new ImageIcon(img)));

    JFrame frame = new JFrame("Display images");

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }