コード例 #1
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();
    }
  }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: erosion.java プロジェクト: jpgr24/getimage
  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);*/
  }
コード例 #4
0
ファイル: Example1.java プロジェクト: dzlab/CATkit
  /** @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"));

  }
コード例 #5
0
ファイル: DrawTool.java プロジェクト: tstamler/linAlg
  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);
          }
        });
  }
コード例 #6
0
  BallDetector(boolean _display) {

    ctx = Freenect.createContext();
    if (ctx.numDevices() > 0) {
      kinect = ctx.openDevice(0);
    } else {
      System.err.println("WARNING: No kinects detected");
      return;
    }
    display = _display;

    controlFrame = new JFrame("Controls");
    controlFrame.setLayout(new GridLayout(5, 1));
    controlFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pg = new ParameterGUI();
    pg.addIntSlider("maxDepth", "max depth", 800, 2047, 1050);
    pg.addIntSlider("blobThresh", "blob thresh", 1, 500, 125);
    pg.addIntSlider("thresh", "thresh", 1, 100, 10);
    pg.addIntSlider("frames", "frames", 1, 1000, 1);
    pg.addListener(
        new ParameterListener() {
          public void parameterChanged(ParameterGUI _pg, String name) {
            if (name.equals("thresh")) {
              KinectDepthVideo.THRESH = _pg.gi(name);
            } else if (name.equals("frames")) {
              KinectDepthVideo.MAX_FRAMES = _pg.gi(name);
            } else if (name.equals("maxDepth")) {
              KinectDepthVideo.MAX_DEPTH = _pg.gi(name);
            }
          }
        });
    controlFrame.add(pg, 0, 0);

    startTracking = new JButton("Start Tracking Balls");
    startTracking.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            if (!tracking) {
              tracking = true;
              colorStream.pause();
              depthStream.pause();
              startTracking.setText("Stop Tracking");
            } else {
              tracking = false;
              colorStream.resume();
              depthStream.resume();
              startTracking.setText("Start Tracking Balls");
            }
          }
        });
    controlFrame.add(startTracking, 1, 0);

    resetProjectile = new JButton("Reset Projectile");
    resetProjectile.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_RESET", "reset");
            } catch (IOException ex) {
              System.out.println("can't publish reset");
            }
          }
        });
    controlFrame.add(resetProjectile, 2, 0);
    resetDepth = new JButton("Reset Depth Avgs");
    resetDepth.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DepthClearer ic = new DepthClearer(pg);
            ic.start();
          }
        });
    controlFrame.add(resetDepth, 3, 0);
    JPanel scoreButtons = new JPanel(new GridLayout(1, 3));
    JButton addHuman = new JButton("human++");
    addHuman.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_HUMAN", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    JButton addRobot = new JButton("robot++");
    addRobot.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_ROBOT", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    JButton resetScores = new JButton("reset scores");
    resetScores.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_RESET", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    scoreButtons.add(addHuman, 0, 0);
    scoreButtons.add(addRobot, 0, 1);
    scoreButtons.add(resetScores, 0, 2);
    controlFrame.add(scoreButtons, 4, 0);
    controlFrame.setSize(800, 600);
    controlFrame.setVisible(true);

    colorFrame = new JFrame("color feed");
    colorMonitor = new Object();
    colorStream = new KinectRGBVideo(kinect, colorMonitor, display);
    colorFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    colorFrame.addWindowListener(new RGBClose());
    colorFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT);
    colorFrame.setContentPane(colorStream);
    colorFrame.setVisible(true);

    depthFrame = new JFrame("depth feed");
    depthMonitor = new Object();
    depthStream = new KinectDepthVideo(kinect, depthMonitor, display);
    depthFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    depthFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT);
    depthFrame.setContentPane(depthStream);
    depthFrame.setVisible(true);

    rgbImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);
    depthImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);

    validImageValue = new boolean[KinectVideo.WIDTH * KinectVideo.HEIGHT];
    try {
      lcm = new LCM("udpm://239.255.76.67:7667?ttl=1");
    } catch (IOException e) {
      lcm = LCM.getSingleton();
    }
    BALL = new Statistics();

    finder = new BallTracker(KinectVideo.WIDTH, KinectVideo.HEIGHT, false);

    if (display) {
      depthImg = depthStream.getFrame();
      rgbImg = colorStream.getFrame();
    }
    // get robot position from click
    depthStream.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            Point botPix = e.getPoint();
            botStart = depthStream.getWorldCoords(botPix);
            botStart.z += 0.08;
            System.out.println("botStart: " + botStart.toString());
            depthStream.showSubtraction();
            depthStream.botLoc = botPix;
          }
        });
    DepthClearer ic = new DepthClearer(pg);
    ic.start();
  }
コード例 #7
0
  void main() {

    CommonSwing.setDefaultColor();

    fMain = new JFrame("HSQL Database Manager");

    // (ulrivo): An actual icon.
    fMain.getContentPane().add(createToolBar(), "North");
    fMain.setIconImage(CommonSwing.getIcon());
    fMain.addWindowListener(this);

    JMenuBar bar = new JMenuBar();

    // used shortcuts: CERGTSIUDOLM
    String fitems[] = {
      "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit"
    };

    addMenu(bar, "File", fitems);

    String vitems[] = {"RRefresh Tree", "--", "GResults in Grid", "TResults in Text"};

    addMenu(bar, "View", vitems);

    String sitems[] = {
      "SSELECT",
      "IINSERT",
      "UUPDATE",
      "DDELETE",
      "---",
      "-CREATE TABLE",
      "-DROP TABLE",
      "-CREATE INDEX",
      "-DROP INDEX",
      "--",
      "-CHECKPOINT",
      "-SCRIPT",
      "-SET",
      "-SHUTDOWN",
      "--",
      "-Test Script"
    };

    addMenu(bar, "Command", sitems);

    mRecent = new JMenu("Recent");

    bar.add(mRecent);

    String soptions[] = {
      "-AutoCommit on",
      "-AutoCommit off",
      "OCommit",
      "LRollback",
      "--",
      "-Disable MaxRows",
      "-Set MaxRows to 100",
      "--",
      "-Logging on",
      "-Logging off",
      "--",
      "-Insert test data"
    };

    addMenu(bar, "Options", soptions);

    String stools[] = {"-Dump", "-Restore", "-Transfer"};

    addMenu(bar, "Tools", stools);
    fMain.setJMenuBar(bar);
    initGUI();

    sRecent = new String[iMaxRecent];

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();

    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
      fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
      fMain.setLocation(0, 0);
      fMain.setSize(d);
    }

    fMain.show();

    // (ulrivo): load query from command line
    if (defScript != null) {
      if (defDirectory != null) {
        defScript = defDirectory + File.separator + defScript;
      }

      // if insert stmet is thousands of records...skip showing it
      // as text.  Too huge.
      StringBuffer buf = new StringBuffer();

      ifHuge = DatabaseManagerCommon.readFile(defScript);

      if (4096 <= ifHuge.length()) {
        buf.append("This huge file cannot be edited. Please execute\n");
        txtCommand.setText(buf.toString());
      } else {
        txtCommand.setText(ifHuge);
      }
    }

    txtCommand.requestFocus();
  }