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