• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to load an Image from a different Jframe  RSS feed

 
Aggelos wat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.");

}
.......
}
 
Randall Twede
Ranch Hand
Posts: 4683
8
Java Scala
  • Mark post as helpful
  • send pies
  • 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
 
Sam Gooding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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")));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!