[英]I'm getting an error with calling a method from another class
我知道這被問了很多,但我找不到解決我的問題的方法。 我認為我的論點在某種程度上是錯誤的。
public class ImageFileHandler extends FileHandler {
public void displayImage() {
//Displaying an image
JLabel picLabel = new JLabel(new ImageIcon(img));
JPanel jPanel = new JPanel();
jPanel.add(picLabel);
JFrame frame = new JFrame();
frame.setSize(new Dimension(img.getWidth(),
img.getHeight()));
frame.add(jPanel);
frame.setVisible(true);
}
}
我想在下面的類中調用這個 displayImage() 方法。
public class FileApplicationTester {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedImage img;
try {
img = ImageIO.read(new File("D:\\Documents\\University\\Year_3\\Advanced Programming\\Week3\\supplementary materials-20190206\\images.jpeg"));
} catch (IOException e) {
e.printStackTrace();
}
ImageFileHandler Display = new ImageFileHandler();
ImageFileHandler.displayImage();
}
}
我在ImageFileHandler.displayImage();
遇到錯誤ImageFileHandler.displayImage();
告訴我 displayImage 方法需要是靜態的,但我不希望它對該類是靜態的,對嗎?
你創建的 ImageFileHandler 實例被稱為 Display 所以像這樣使用它: Display.displayImage();
你好,你有沒有嘗試過
Display.displayImage();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.