BumbleBee
BumbleBee

Reputation: 11

Type javax.swing.JComponent cannot be resolved

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;
}

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

Answers (1)

Centrella
Centrella

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

Related Questions