当我将鼠标悬停在JFrame上进行导入时,会显示以下消息:
&#34;访问限制:由于对所需库C:\ Program Files(x86)\ Java \ jre1.8.0_31 \ lib \ rt.jar&#34; <的限制,无法访问构造函数JFrame(String) / p>
此外,我的frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
行也没有工作。它提出了同样的事情。任何人都知道如何解决这个问题?
package com.tutorial.main;
import java.awt.Canvas;
import java.awt.Frame;
import javax.swing.*;
import java.awt.Dimension;
public class Window extends Canvas{
private static final long serialVersionUID = -240840600533728354L;
public Window(int width, int height, String title){
JFrame frame = new JFrame(title);
frame.setPreferredSize(new Dimension(width,height));
frame.setMinimumSize(new Dimension(width,height));
frame.setMaximumSize(new Dimension(width,height));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(game);
frame.setVisible(true);
Game.start();
}
}