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