I am new with programming, so sorry if I use the wrong terms or so. I am programming on a macbook air and use Eclipse, but when I tried to import the javax.swing and java.awt, it doesn´t work and I receive an error message (see below). I have done a lot of research and found that some people have similar problems, but since I am a beginner I honestly don't understand the answers (like "removing swt.jar from the project dependencies"). If you know what I can do I would be so grateful for a solution. Here is the program I tried and the error messages that occurred.
import java.awt.*;
import javax.swing.*;
class WindowTest extends JFrame
{
public WindowTest (){
super ("Hi");
setSize (300,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible (true);
Container contentArea = getContentPane();
contentArea.setBackground(Color.white);
FlowLayout flowManager = new FlowLayout();
contentArea.setLayout(flowManager);
JLabel TextLabel = new JLabel ("I am here");
contentArea.add(textLabel);
JLabel TextLabel2 = new Jlabel ("OK");
contentArea.add(TextLabel2);
JTextField textBox = new JTextField ("Write here",20);
contentArea.add(textBox);
JTextArea comments = new JTextArea ("Comments please",3,20);
contentArea.add(comments);
JButton pointlessButton = new JButton ("Exit");
contentArea.add(pintlessButton);
}
}
public class TestWindow {
public static void main(String[] args) {
WindowTest Win = new WindowTest();
}
}
And the error messages:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Access restriction: The type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JFrame(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The method setDefaultCloseOperation(int) from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The field EXIT_ON_CLOSE from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The method getContentPane() from the type JFrame is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JLabel(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
textLabel cannot be resolved
Access restriction: The type JLabel is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Jlabel cannot be resolved to a type
Access restriction: The type JTextField is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JTextField(String, int) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextField is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextArea is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JTextArea(String, int, int) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JTextArea is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JButton is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The constructor JButton(String) is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
Access restriction: The type JButton is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
pintlessButton cannot be resolved
at WindowTest.<init>(TestWindow.java:6)
at TestWindow.main(TestWindow.java:43)
Thanks!