Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code does not work and shows: Panel02.java:62: error: cannot find symbol if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() ==

My code does not work and shows: Panel02.java:62: error: cannot find symbol

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

^

symbol:variable northButton

location: class MyActionListener

Panel02.java:62: error: cannot find symbol

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

^

symbol:variable southButton

location: class MyActionListener

Panel02.java:62: error: cannot find symbol

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

^

symbol:variable westButton

location: class MyActionListener

Panel02.java:62: error: cannot find symbol

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

^

symbol:variable eastButton

location: class MyActionListener

Panel02.java:62: error: cannot find symbol

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

^

symbol:variable centerButton

location: class MyActionListener

Panel02.java:64: error: cannot find symbol

northButton.setText("A year later");

^

symbol:variable northButton

location: class MyActionListener

Panel02.java:65: error: cannot find symbol

southButton.setText("Thanks for teacher's help");

^

symbol:variable southButton

location: class MyActionListener

Panel02.java:66: error: cannot find symbol

eastButton.setText("As well as your hardwork");

^

symbol:variable eastButton

location: class MyActionListener

Panel02.java:67: error: cannot find symbol

southButton.setText("Now, you can make prefect program!");

^

symbol:variable southButton

location: class MyActionListener

Can you help me modify my code to make it work? Please disregard a.jpg and b.jpg. I appreciate it!

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Panel02 extends JPanel

{

public JButton northButton, southButton, westButton, eastButton, centerButton;

public ImageIcon picture1, picture2;

public Panel02()

{

setLayout(new BorderLayout());

northButton = new JButton(" First day of learning Java (maybe other languages) ");

add(northButton, BorderLayout.NORTH);

northButton.setForeground(Color.white);

northButton.setBackground(Color.red);

northButton.setFont(new Font("Helvetica", Font.ITALIC, 24));

ActionListener listener1 = new MyActionListener();

northButton.addActionListener(listener1);

southButton = new JButton("Luckily, it finally works correctly, but you do not understand what bugs did you make. (to be continue)");

add(southButton, BorderLayout.SOUTH);

southButton.setForeground(Color.gray);

southButton.setBackground(Color.orange.brighter());

southButton.setFont(new Font("Serif", Font.BOLD, 24));

ActionListener listener2 = new MyActionListener();

southButton.addActionListener(listener2);

westButton = new JButton("Your program does not work as expected.");

add(westButton, BorderLayout.WEST);

westButton.setForeground(Color.yellow);

westButton.setBackground(Color.blue);

westButton.setFont(new Font("TimesRoman", Font.PLAIN, 36));

ActionListener listener3 = new MyActionListener();

westButton.addActionListener(listener3);

eastButton = new JButton("You check your code mutiple times...");

add(eastButton, BorderLayout.EAST);

eastButton.setForeground(Color.pink);

eastButton.setBackground(Color.magenta.darker());

eastButton.setFont(new Font("TimesRoman", Font.BOLD, 36));

ActionListener listener4 = new MyActionListener();

eastButton.addActionListener(listener4);

picture1 = new ImageIcon("a.jpg");

centerButton = new JButton(picture1);

add(centerButton, BorderLayout.CENTER);

ActionListener listener5 = new MyActionListener();

centerButton.addActionListener(listener5);

}

}

class MyActionListener implements ActionListener

{

public MyActionListener()

{

}

public void actionPerformed(ActionEvent event)

{

if(event.getSource() == northButton ||event.getSource() == southButton || event.getSource() == westButton || event.getSource() == eastButton ||event.getSource() == centerButton)

{

northButton.setText("A year later");

southButton.setText("Thanks for teacher's help");

eastButton.setText("As well as your hardwork");

southButton.setText("Now, you can make prefect program!");

centerButton.setText("b.jpg");

}

}

}

class Driver02

{

public static void main(String[] args)

{

JFrame frame = new JFrame("GUI mini-program #2");

frame.setSize(400, 350);

frame.setLocation(200, 200);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setContentPane(new Panel02());

frame.setVisible(true);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

Explain how business markets differ from consumer markets.

Answered: 1 week ago