2

When I hover over JFrame to import, it comes up with the message:

"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"

Also, my frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); line isn't working, either. It comes up with the same thing. Anyone have any idea how to fix this?

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();

    }

}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
JudasMoses
  • 378
  • 4
  • 22

1 Answers1

2

Check this out.

  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.
Community
  • 1
  • 1
pushkin
  • 9,575
  • 15
  • 51
  • 95