So I'm attempting to create a simple application in which I can click a button and allow the user to display an image of their choice using a jFIleChooser from the menu and display that image into a label. I wrote code that works for that, but I'm supposed to create and use a method called "BufferedImage getImage()" using a class "ImageManipulator" to actually run that code, so that I can call on that method rather than running all the code in the main class. Here is what I have: (My ImageManipulator class)
public class ImageManipulator extends MainWindow {
BufferedImage image;
public ImageManipulator() {
image = null;
}
public ImageManipulator(BufferedImage image){
this.image = image;
}
public BufferedImage getImage() {
FileChooser.showOpenDialog(null);
BufferedImage image = null;
try{
File myFile = FileChooser.getSelectedFile();
image = ImageIO.read(myFile);
labelImage.setIcon(new ImageIcon(image));
}
catch(IOException e){
}
return image;
}
and my main window for the GUI (the code that actually goes under buttonClicked):
private void buttonChooseActionPerformed(java.awt.event.ActionEvent evt) {
ImageManipulator myManipulator = new ImageManipulator(image);
myManipulator.getImage();
}
So it presents an error because the image variable within myManipulator has not been declared or initialized. I realize that I need to initialize the image variable above in my main window and "connect" it to the image variable that is being returned via getImage() in some way, I'm just not sure about how to do so or what to set image equal to so that it actually runs the code in the getImage() method. I'm new to using classes and OO programming so hopefully someone can give me some direction here.