Hello
Can somebody help me and tell me why I can’t change the background color of the second PN2 panel.
I get this error about unknown source
Exception in thread "AWT-EventQueue-1" java.lang.NullP ointerException
at test$myFreaking Listener.action Performed(test. java:34)
at java.awt.Button .processActionE vent(Unknown Source)
at java.awt.Button .processEvent(U nknown Source)
at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.r un(Unknown Source)
and this is the source
I am doing something wrong here but I can’t find it.
Any one?
Can somebody help me and tell me why I can’t change the background color of the second PN2 panel.
I get this error about unknown source
Exception in thread "AWT-EventQueue-1" java.lang.NullP ointerException
at test$myFreaking Listener.action Performed(test. java:34)
at java.awt.Button .processActionE vent(Unknown Source)
at java.awt.Button .processEvent(U nknown Source)
at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
at java.awt.Compon ent.dispatchEve nt(Unknown Source)
at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
at java.awt.EventD ispatchThread.r un(Unknown Source)
and this is the source
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class test extends Applet {
public void init () {
this.setSize(600,440);
this.setBackground(Color.white);
this.setLayout(new GridLayout(2,1));
Panel PN1 = new Panel();
this.add(PN1);
Panel PN2 = new Panel();
this.add(PN2);
PN2.setBackground(Color.red);
Button but = new Button();
PN1.add(but);
but.setLabel("Change Panel's Color ");
but.addActionListener(new myFreakingListener());
}
class myFreakingListener implements ActionListener{
public void actionPerformed(ActionEvent ae){
PN2.setBackground(Color.orange);
}
}
Panel PN1, PN2;
}
Any one?
Comment