2
votes

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

    }

}
1
Perhaps this will help. - pushkin
I'll post this as an answer, so people know it's resolved. - pushkin
Yes that did resolve the problem although I still have more to fix - JudasMoses

1 Answers

2
votes

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.