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();
 }
Exemplo n.º 2
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);*/
  }
Exemplo n.º 3
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);
          }
        });
  }
  public WebcamCaptureAndFadePanel(String saveDir, String layout) {

    System.out.println("Using " + saveDir + " as directory for the images.");
    saveDirectory = saveDir;

    getImages();
    images_used = new ArrayList<Integer>();
    images_lastadded = new ArrayList<Integer>();
    images_nevershown = new ArrayList<Integer>();

    Vector devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone();
    Enumeration enumeration = devices.elements();
    System.out.println("- Available cameras -");
    ArrayList<String> names = new ArrayList<String>();
    while (enumeration.hasMoreElements()) {
      CaptureDeviceInfo cdi = (CaptureDeviceInfo) enumeration.nextElement();
      String name = cdi.getName();
      if (name.startsWith("vfw:")) {
        names.add(name);
        System.out.println(name);
      }
    }

    // String str1 = "vfw:Logitech USB Video Camera:0";
    // String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
    if (names.size() == 0) {
      JOptionPane.showMessageDialog(
          null,
          "Ingen kamera funnet. " + "Du må koble til et kamera for å kjøre programmet.",
          "Feil",
          JOptionPane.ERROR_MESSAGE);
      System.exit(0);
    } else if (names.size() > 1) {

      JOptionPane.showMessageDialog(
          null,
          "Fant mer enn 1 kamera. " + "Velger da:\n" + names.get(0),
          "Advarsel",
          JOptionPane.WARNING_MESSAGE);
    }

    String str2 = names.get(0);
    di = CaptureDeviceManager.getDevice(str2);
    ml = di.getLocator();

    try {
      player = Manager.createRealizedPlayer(ml);
      formatControl = (FormatControl) player.getControl("javax.media.control.FormatControl");

      /*
      Format[] formats = formatControl.getSupportedFormats();
      for (int i=0; i<formats.length; i++)
      	System.out.println(formats[i].toString());
      */

      player.start();
    } catch (javax.media.NoPlayerException e) {
      JOptionPane.showMessageDialog(
          null,
          "Klarer ikke å starte" + " programmet pga. feil med kamera. Sjekk at det er koblet til.",
          "IOException",
          JOptionPane.ERROR_MESSAGE);
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }

    /*
     * Layout
     *
     * Add
     * - comp
     * - imagepanels
     */

    if (layout.equals("1024v2")) {
      layout1024v2();
    } else if (layout.equals("1280")) {
      layout1280();
    } else {
      layout1024();
    }

    // Capture Window
    if (captureWindow) {
      cw = new JFrame("Capture from webcam");
      cw.setAlwaysOnTop(true);
      cw.setSize(sizeCaptureWindow_x, sizeCaptureWindow_y);
      cw.addKeyListener(new captureWindowKeyListner());
      cw.setUndecorated(true);

      // Add webcam
      if ((comp = player.getVisualComponent()) != null) {
        cw.add(comp);
      }

      // Add panel to window and set location of window
      cw.setLocation(cwLocation_x, cwLocation_y);
    }

    // Text window
    cwText = new rotatedText("");

    /*
     * Timer for update
     */
    Timer thread = new Timer();
    thread.schedule(new frameUpdateTask(), 0, (1000 / fps));
  }
Exemplo n.º 5
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();
  }
Exemplo n.º 6
0
  public LJ3MDApp() {
    tNum.setHorizontalAlignment(JTextField.CENTER);
    tTemp.setHorizontalAlignment(JTextField.CENTER);
    tRho.setHorizontalAlignment(JTextField.CENTER);
    tSpeed.setHorizontalAlignment(JTextField.CENTER);

    tAvK.setHorizontalAlignment(JTextField.RIGHT);
    tAvU.setHorizontalAlignment(JTextField.RIGHT);
    tAvp.setHorizontalAlignment(JTextField.RIGHT);

    float[] aveKing = new float[501];
    float[] avePot = new float[501];
    float[] aveEn = new float[501];

    JFrame box = new JFrame();
    box.setLayout(new BorderLayout());
    box.setSize(1000, 1000);
    box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    cpnl = new JPanel(); // create a panel for controls
    cpnl.setLayout(new GridLayout(18, 2));
    box.add(cpnl, BorderLayout.EAST);

    // add controls
    cpnl.add(bStart);
    bStart.addActionListener(this);

    cpnl.add(bReset);
    bReset.addActionListener(this);

    cpnl.add(new JLabel(" N:"));
    tNum.addActionListener(this);
    cpnl.add(tNum);

    cpnl.add(new JLabel(" Density (\u03c1):"));
    tRho.addActionListener(this);
    cpnl.add(tRho);

    cpnl.add(new JLabel(" Steps/frame:"));
    tSpeed.addActionListener(this);
    cpnl.add(tSpeed);

    cpnl.add(bTstat);
    bTstat.addActionListener(this);

    cpnl.add(bPot);
    bPot.addActionListener(this);

    cpnl.add(new JLabel(" < K/N > :"));
    tAvK.setEditable(false);
    cpnl.add(tAvK);

    cpnl.add(new JLabel(" Temperature:"));
    tTemp.setEditable(false);
    cpnl.add(tTemp);

    cpnl.add(new JLabel(" < U/N > :"));
    tAvU.setEditable(false);
    cpnl.add(tAvU);

    cpnl.add(new JLabel(" < pressure > :"));
    tAvp.setEditable(false);
    cpnl.add(tAvp);

    cpnl.add(bRetime);
    bRetime.addActionListener(this);

    spnl = new JPanel(); // create a panel for status
    box.add(spnl, BorderLayout.SOUTH);
    lStatus.setFont(new Font("Courier", 0, 12));
    spnl.add(lStatus);

    canvas = new XYZCanvas();
    box.add(canvas, BorderLayout.CENTER);

    timer = new Timer(delay, this);
    timer.start();
    //        timer.stop();
    box.setVisible(true);
  }
  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();
  }