• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to load an Image from a different Jframe

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,I made a project (at Netbeans) with three Jframes.When it runs,it crops two images and make a screenshot for each of them,from two different Jframes. I want to have these two screenshots in the third jframe. How can I load these two screenshots in the third Jframe?
Can anyone help me?
Thank you !

Below,I put a part of my code which is in two Jframes and do screenshots.I think it is helpful for you to understand !


public class Frame1 extends javax.swing.JFrame implements MouseListener, MouseMotionListener {

..........

public void draggedScreen()throws Exception
{
int w = c1 - c3;
int h = c2 - c4;
w = w * -1;
h = h * -1;
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(c1, c2,w,h));
File save_path=new File("right_eye.jpg");
ImageIO.write(img, "JPG", save_path);
System.out.println("Cropped image saved successfully.");

}
.......
}
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where is your JPanel?
you need to draw on a JPanel not a JFrame
you can then easily pass a reference to the JPanel(or it's image) from frame to frame
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going to save the created image(s) to a file (myScreenShots.jpg) then load it into a component which is contained by JFrame you want to display that image in.

for instance:

JFrame displayFrame= new JFrame();

JPanel imagePanel = new JPanel();

displayFrame.add(imagePanel);

imagePanel.add(new JLabel(new ImageIcon("myScreenShots.jpg")));
reply
    Bookmark Topic Watch Topic
  • New Topic