我知道这被问了很多,但我找不到我的问题的解决方案。我认为我的论点在某种程度上是错误的。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();告诉我 displayImage 方法需要是静态的,但我不希望它对该类是静态的,对吗?
添加回答
举报
0/150
提交
取消