Results 1 to 3 of 3
  1. #1
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default How to perform some event to button click

    I have the following code. I have a button on the frame.

    Java Code:
        Button b = new Button("Hello"); 
        Frame f = new Frame("Java Frame"); 
        f.add(b, BorderLayout.NORTH ); 
        f.pack(); 
        f.show();
    I want some action to be preformed on the button click. Please guide me how to do so.

    _ PEACE

  2. #2
    Jman is offline Member
    Join Date
    Dec 2007
    Posts
    17
    Rep Power
    0

    Default

    Hi Eva,

    Have a read about ActionListeners. This should explain what needs to be done to produce a button action.

  3. #3
    undertow's Avatar
    undertow is offline Member
    Join Date
    Jan 2008
    Location
    Colorado USA
    Posts
    12
    Rep Power
    0

    Default

    Java Code:
        Button b = new Button("Hello"); 
    
        b.addActionListener(new ActionListener()
        {
             public void actionPerformed(ActionEvent e)
             {
                 //something in response to click
             }
        });
    
        Frame f = new Frame("Java Frame"); 
        f.add(b, BorderLayout.NORTH ); 
        f.pack(); 
        f.show();
    I would also suggest looking into SUN's documentation on actionListener interface and the Action Object.

Similar Threads

  1. Replies: 3
    Last Post: 03-26-2009, 11:31 PM
  2. Swing - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:03 AM
  3. AWT - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:02 AM
  4. how to click a jbutton and open an url
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:44 PM
  5. Click Framework 1.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-09-2007, 09:27 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
  •