/** 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);
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
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);
  }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
  private void _displayImgInFrame() {

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

    JLabel imgLbl = new JLabel(new ImageIcon(_img));
    imgLbl.setToolTipText(
        MessageFormat.format(
            "<html>Image downloaded from URI<br>size: w={0}, h={1}</html>",
            _img.getWidth(), _img.getHeight()));

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
    frame.setContentPane(imgLbl);
    frame.pack();
    frame.setResizable(false);

    imgLbl.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {

            System.out.println("Mouse Listener:  Mouse Clicked!");
            mapIsUp = 1;
            sentX = 0.00;
            clickX = e.getX(); // Latitude
            clickY = e.getY(); // Longitude
            if ((clickX < (_img.getWidth() / 2))
                && (clickY < (_img.getHeight() / 2))) { // 1st quadrant positive values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); // Add to latitude
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY); // Add to Longitude
              System.out.println("Top left");
            } else if ((clickX > (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 2nd quadrant negative values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Right");
            } else if ((clickX < (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Left");
            } else { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Top Right");
            }

            BigDecimal toCoordsX = new BigDecimal(sentX);
            BigDecimal toCoordsY = new BigDecimal(sentY);

            sentX =
                (toCoordsX.setScale(6, BigDecimal.ROUND_HALF_UP))
                    .doubleValue(); // allows values of up to 6 decimal places
            sentY = (toCoordsY.setScale(6, BigDecimal.ROUND_HALF_UP)).doubleValue();
            getCoords = sentX + " " + sentY;
            ttfLati.setText(Double.toString(sentX));
            ttfLongi.setText(Double.toString(sentY));

            System.out.println("... saving Coordinates");
            saveLocation(
                getCoords); // pass getCoords through saveLocation. this string is appended to the
                            // savedLocations file.
            System.out.println("... savedCoordinates");

            // Update the Locations ComboBox with new additions
            ttfSave.removeAllItems(); // re-populate the ComboBox
            System.out.println("removed items");

            getSavedLocations(); // run through file to get all locations
            for (int i = 0; i < loc.size(); i++) ttfSave.addItem(loc.get(i));
            System.out.println("update combobox");
            mapIsUp = 0;
            frame.dispose(); // closes window
            startTaskAction(); // pops up a new window
          }

          public void saveLocation(String xy) {
            BufferedWriter f = null; // created a bufferedWriter object

            try {
              f =
                  new BufferedWriter(
                      new FileWriter(
                          "savedLocations.txt",
                          true)); // evaluated true if file has not been created yet
              f.write(xy); // append passed coordinates and append to file if exists
              f.newLine();
              f.flush();
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } finally { // close the file
              if (f != null) {

                try {
                  f.close();
                } catch (IOException e) { // any error, catch exception
                  System.err.println("Error: " + e.getMessage());
                }
              }
            }
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

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