button actionlistener error

it says it cant find SevenContinentsFrame
please helppp
/**
* Write a description of class SevenContinents here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JButton;
public class SevenContinents extends JFrame implements ActionListener
{
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton button7 = new JButton("7");

public SevenContinents()
{

//BUTTONS!!!

setSize(1500,1000);

button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
button7.addActionListener(this);

SevenContinentsFrame.add(button1);
SevenContinentsFrame.add(button2);
SevenContinentsFrame.add(button3);
SevenContinentsFrame.add(button4);
SevenContinentsFrame.add(button5);
SevenContinentsFrame.add(button6);
SevenContinentsFrame.add(button7);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource == btn1)
{
System.out.println("You chose...");
}
if(e.getSource == btn2)
{
System.out.println("You chose...");
}
if(e.getSource == btn3)
{
System.out.println("You chose...");
}
if(e.getSource == btn4)
{
System.out.println("You chose...");
}
if(e.getSource == btn5)
{
System.out.println("You chose...");
}
if(e.getSource == btn6)
{
System.out.println("You chose...");
}
if(e.getSource == btn7)
{
System.out.println("You chose...");
}

}

public static void main(String[] args)
{
JFrame SevenContinentsFrame = new JFrame();
SevenContinentsFrame.setVisible(true);
SevenContinentsFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
}

}
Why are you posting this on a C++ forum? You do realize the code you have written is in Java?

If you want *any* chance to get help, click 'edit topic' at the top of this page and move this topic into the lounge. There is still no guarantee that I or rapidcoder will help, however.
This is a C++ forum, there are many Java forums out there.

Secondly, please use code tags (the <> sign under format when you are posting a thread).

And lastly, because I am a nice person, the solution to your problem is that SevenContinentsFrame goes out of scope in your other functions other than main(). Read this article, start to finish: http://www.java-made-easy.com/variable-scope.html
Last edited on
Topic archived. No new replies allowed.