我的 JFrame 不会在 Eclipse 中导入

My JFrame wont import in Eclipse

当我将鼠标悬停在 JFrame 上进行导入时,它出现了消息:

"Access restriction: The constructor JFrame(String) is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre1.8.0_31\lib\rt.jar"

此外,我的 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();

    }

}

检查 this

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library.