Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with JPanel.setBackground program  RSS feed

 
Jae Lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am currently taking an online intro to java class. The professor has not been able to get back to me and I need to understand this in order to complete the hw which is due at the end of the week.
I have copied my entire code from top to bottom

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class third extends JFrame
{
JButton b1, b2, b3;
JPanel p1;

third()
{
setTitle("getting smarter with swing");
setSize(300,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1 = new JButton("b1");
b2 = new JButton("b2");
b3 = new JButton("b3");

p1 = new JPanel();

b1.addActionListener(new b1Listener());
b2.addActionListener(new b1Listener());
b3.addActionListener(new b1Listener());


setLayout(new FlowLayout());
p1.add(b1);
p1.add(b2);
p1.add(b3);

add(p1);

setVisible(true);
}



class b1Listener implements ActionListener
{
public void actionPerformed(ActionEvent b)
{
if (b.getActionCommand().equals("b1")) //will return b1, b2, b3 as a string
p1.setBackgroud(Color.RED);
else if (b.getActionCommand().equals("b2"))
p1.setBackground(Color.BLUE);
else if (b.getActionCommand().equals("b3"))
p1.setBackground(Color.YELLOW);

}
}


public static void main (String [] args)
{
third a1 = new third(); //create object for second class
}
}


The bold is where I am receiving the error. Here is what it looks like verbatim.

second.java:44: cannot find symbol
symbol: method setBackground(java.awt.Color)
location: class javax.swing.JPanel
p1.setBackground(Color.RED);

Please HELP. THANK YOU
 
Jae Lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel really stupid and i found my own mistake.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You meant "p1.setBackgroud" instead of "p1.setBackground"? Or was it something else?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!