Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: GUI based program

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile GUI based program

    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    class GUI2 extends JFrame implements ActionListener
    {
    public static void main(String s[])
    {

    JFrame jf=new JFrame("my tool");
    JButton jb=new JButton("submit");
    jb.addActionListener(this);
    jf.add(jb);
    }

    public void ActionPerformed(ActionEvent ae)
    {
    System.out.println("button clicked");
    }
    }

    this is showing error :
    GUI2 is not abstract and doesnot override abstract method ActionPerformed(Action Event)in ActionListener


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,256
    My Mood
    Hungover
    Thanks
    142
    Thanked 618 Times in 529 Posts

    Default Re: GUI based program

    ActionPerformed != actionPerformed. Case matters.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    vivek rajput (March 18th, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: GUI based program

    thanks. but its now showing one error :
    non-static variable this cannot be referenced from a static context
    jb.addActionListener(this);

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,256
    My Mood
    Hungover
    Thanks
    142
    Thanked 618 Times in 529 Posts

    Default Re: GUI based program

    You're in the main() method, which is static. That means you aren't "inside" a particular instance of GUI2, so you can't use the this keyword. You need to instantiate an instance of GUI2 before you can use it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    vivek rajput (March 18th, 2014)

  7. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: GUI based program

    Thanks a lot Kevin it worked finally

Similar Threads

  1. Replies: 1
    Last Post: May 15th, 2013, 08:47 AM
  2. Generate GUI for web based application
    By Dev777 in forum Member Introductions
    Replies: 0
    Last Post: July 8th, 2011, 05:52 AM
  3. Help with String based program!!!
    By astroann in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 27th, 2010, 09:07 PM
  4. Help with String based program!!!
    By astroann in forum Member Introductions
    Replies: 3
    Last Post: December 27th, 2010, 09:07 PM
  5. Replies: 3
    Last Post: January 31st, 2010, 11:24 PM