Reputation: 11
I'm using ACM library and working out the exercises present in "The Art and Science of Java" on my own. I have a simple program which should have added a Button to the screen but I'm getting a couple of error messages that I've not been able to resolve on my own.
//The first import results in the error message about javax.swing.JComponent
import acm.program.*;
import java.awt.event.*;
import javax.swing.*;
public class NewFirstButton extends ConsoleProgram {
public void init(){
setFont("Courier-24");
hiButton = new JButton("Hi");
// The line below produces the second error about function args
add(hiButton, SOUTH);
addActionListeners();
}
public void actionPerformed(ActionEvent e){
if (hiButton == e.getSource()){
println("Hello there!");
}
}
private JButton hiButton;
}
The first problem is the error message "The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files".
The second being, "The method add(String, Component) in the type Container is not applicable for the arguments (JButton, String)".
Can anyone please help me out with these? I'm very new to JAVA and a little help would be really appreciated. Thanks
Upvotes: 1
Views: 2014
Reputation: 11
I had the same problem. My code worked fine until (I think) I allowed Java update from 7u25 to 8u51. That could be your problem also.
Try uninstalling the newer version of Java and reinstalling an older version. Such as 7u25.
I'm unsure if swing compenents have been depricated (and dropped) but this would be my guess as to why things stopped working.
Upvotes: 1