I am trying to get my program to display an image after it is dragged over, but I dont really have a good idea of how to do this.
Example: There is an image on your desktop, photo.jpg . You would take that, drag it over into a java JFrame, and the contents of that image (the photo iteself) would display.
From开发者_运维百科 there I would like to be able to play with the size ability of the photo, but first step first, I dont know how to approach getting it to display in the JFrame. Any help would be greatly appreciated.
Once you have the image (I didn't think you were asking about the drag-and-drop feature, if that was the part you were asking about, sorry.), you can either push the image into an ImageIcon and display it in a JLabel as described here
Or you can mess around with using Graphics#drawImage
methods in paintComponent
to draw Images
.
Something along the lines of (as a very basic example):
public void paintComponent(Graphics page)
{
super.paintComponent(page);
page.drawImage(img, 0, 0, null);
}
I give a more detailed example here.
精彩评论