Results 1 to 3 of 3
  1. #1
    ravi.joshi53 is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Thumbs up ActionListener for JButton after changing Button to JButton

    Hi,
    i am newbie in Java Swing Framework. I have an applet code, which I want to convert it into swing. I know that to convert any applet program into swing, I have to completely redesign the whole code into swing but my applet code is already having too many classes, some for buttons, some for action and some for Graphics in applet.


    Currently I can't redesign the whole code into swing but I am thinking of just use applet with some swing controls. I want only JButton instead of Button in my applet. For the same reason, I changed Button into JButton in my applet code everywhere. My applet is still working fine except these JButtons. Now buttons action are not performing by applet but JButtons are beautifully rendered in the applet.


    I want to ask you that, where I have to make changes in my code so that JButton’s actionListener will work properly same as Button action worked, as in current stage I just want to use JButton instead of Button in my applet.

    Curretly Buttons are managed in the following manner.

    Java Code:
    Panel buttonPanel = new Panel();
    buttonPanel.add(new Button("Yes"));
    buttonPanel.add(new Button("No"));
    buttonPanel.add(new Button("Help"));
    And following is the action method of applet


    Java Code:
    public boolean action(Event evt, Object arg) {
      if ("Yes".equals(arg)) {
    //here a lot of code for yes button  
      return true;
      }
      else if("No".equals(arg)){
    //here a lot of code for no button  
      return true;
      }
      else if("Help".equals(arg)){
    //here a lot of code for help button  
      return true;
      }
    return false;
    }
    Please help. Thank you.
    Last edited by ravi.joshi53; 10-06-2011 at 06:47 PM. Reason: Code was not formatted correctly

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: ActionListener for JButton after changing Button to JButton

    For what its worth, I highly recommend reading the API in detail - the method action has been deprecated since java version 1.1

    Read the following:
    How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

  3. #3
    ravi.joshi53 is offline Member
    Join Date
    Oct 2011
    Posts
    24
    Rep Power
    0

    Default Re: ActionListener for JButton after changing Button to JButton

    okk... i will read.. thank you.

Similar Threads

  1. Replies: 2
    Last Post: 09-05-2011, 12:38 AM
  2. Multiple JButton/ActionListener problem
    By graympa in forum New To Java
    Replies: 3
    Last Post: 04-04-2011, 12:48 AM
  3. JButton ActionListener problems
    By Fortu in forum New To Java
    Replies: 6
    Last Post: 02-05-2011, 04:20 PM
  4. JButton actionlistener not working, very strange
    By alacn in forum New To Java
    Replies: 4
    Last Post: 08-05-2010, 02:25 AM
  5. Replies: 2
    Last Post: 04-19-2009, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •