使用我创建的 Java 方法 getImage() 时出现问题?

Issues with using Java Method getImage() I created?

所以我试图创建一个简单的应用程序,我可以在其中单击一个按钮并允许用户使用菜单中的 jFIleChooser 显示他们选择的图像并将该图像显示到标签中。我编写了适用于此的代码,但我应该使用 class "ImageManipulator" 创建并使用名为 "BufferedImage getImage()" 的方法来实际 运行 该代码,这样我可以调用该方法而不是 运行 主 class 中的所有代码。这是我的:(我的 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;

}

和我的 GUI 主要 window(实际位于 buttonClicked 下的代码):

private void buttonChooseActionPerformed(java.awt.event.ActionEvent evt) {                                             


        ImageManipulator myManipulator = new ImageManipulator(image);
        myManipulator.getImage();


}   

因此出现错误,因为 myManipulator 中的图像变量尚未声明或初始化。我意识到我需要在主 window 和 "connect" 中将上面的图像变量初始化为以某种方式通过 getImage() 返回的图像变量,我只是不确定如何这样做或将图像设置为等于什么,以便它实际上 运行s getImage() 方法中的代码。我刚开始使用 classes 和 OO 编程,所以希望有人能在这里给我一些指导。

为了让方法正常工作,我删除了第二个构造函数

public ImageManipulator(BufferedImage image){ this.image = image; }

并使用了第一个构造函数并做了一些小改动

public ImageManipulator() { this.image = image; }

创建时 ImageManipulator myManipulator = new ImageManipulator(); 因为在这种情况下实际上不需要向 myManipulator 传递参数。