Results 1 to 3 of 3
Thread: Cannot find symbol problem
- 04-11-2010, 03:01 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
Cannot find symbol problem
Hi there
I'm fairly confused about a compiler error I keep getting with the following code (planning to tidy up the import statments later). The problem is the last two lines of code, which give me the message: cannot find symbol, variable tomandy (or variable Tom), class Party.
I've tried putting them inside the main method which doesn't complie either, and I can't put them in another class since I need to delcare them in the class that declares ActionListener...
What I'm trying to do is get the window to run the Halsey2.stuff method refresh the window when you click the JButton. It works fine if I leave the button with no function.
Would be massively grateful for any advice? Thanks!
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import static java.lang.System.out;
import javax.swing.*;
public class Party implements ActionListener{
public static void main(String[] args){
Halsey2 Tomandy = new Halsey2();
Tomandy.stuff();
JLabel one = new JLabel ("Salutations. I would like to invite you to a very special
party.", SwingConstants.CENTER);
JLabel two = new JLabel ("We will partake in the following:",SwingConstants.CENTER);
JLabel three = new JLabel ("Listening to " + Tomandy.music, SwingConstants.CENTER);
JLabel four = new JLabel ("Drinking " + Tomandy.drink, SwingConstants.CENTER);
JLabel five = new JLabel ("Eating " + Tomandy.food, SwingConstants.CENTER);
JLabel six = new JLabel ("The dress code is " + Tomandy.clothes, SwingConstants.CENTER);
JLabel seven = new JLabel ("I do hope you will attend.", SwingConstants.CENTER);
JButton eight = new JButton("No thanks, try again.");
eight.addActionListener(Tomandy);
JPanel pane = new JPanel();
GridLayout airmax = new GridLayout (8,1);
pane.setLayout(airmax);
pane.add(one);
pane.add(two);
pane.add(three);
pane.add(four);
pane.add(five);
pane.add(six);
pane.add(seven);
pane.add(eight);
JFrame Tom = new JFrame("Party of possible doom");
Tom.add(pane);
Tom.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
Tom.pack();
Tom.setVisible(true);}
public void actionPerformed(ActionEvent event) {
Tomandy.stuff();
Tom.repaint();
}
}
-
You have a scope issue here:
The variables you are trying to access have been declared inside of main and are visible inside main only. I think that you may want to rethink everything so that your design is more OOP-natured. You'll likely want to make your main much simpler so that it perhaps initializes the app and that's it.Java Code:public class Party implements ActionListener { public static void main(String[] args) { Halsey2 Tomandy = new Halsey2(); //.... JFrame Tom = new JFrame("Party of possible doom"); //.... } public void actionPerformed(ActionEvent event) { Tomandy.stuff(); Tom.repaint(); } }
Also, please read the link in my signature regarding code tags.
Best of luck!
- 04-11-2010, 03:32 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Cannot find symbol
By SarahB in forum New To JavaReplies: 0Last Post: 03-06-2010, 03:03 PM -
Can not find symbol ???
By AliceNewbie in forum New To JavaReplies: 1Last Post: 02-17-2010, 01:44 AM -
cannot find symbol
By GabWit in forum New To JavaReplies: 3Last Post: 01-25-2009, 12:13 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks