swing - Java GUI programmming -


code gives error of nullpointer exception.....wat do?

import java.awt.event.*; import javax.swing.*;  public class gui implements actionlistener{ jbutton button;  public gui(){     jframe frame=new jframe();     jbutton button =new jbutton("click me!");     button.addactionlistener(this);     frame.setdefaultcloseoperation(jframe.exit_on_close);     frame.getcontentpane().add(button);     frame.setsize(270,300);     frame.setvisible(true); } public static void main(string[] args){     new gui(); }  public void actionperformed(actionevent e){     button.settext("i've been clicked"); }  } 

jbutton button =new jbutton 

this creates local variable.
button field still null.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -