Results 1 to 3 of 3
  1. #1
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Detecting buttons

    I am making a program and i need to check if by buttons get pressed here is my code
    Java Code:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    
    public class ExitScreen {
      public static void main(String[] args) 
      
      {
        JFrame f = new JFrame("Exit Screen");
        f.setSize(400, 150);
        Container content = f.getContentPane();
        content.setBackground(Color.white);
        content.setLayout(new FlowLayout()); 
    	content.add(new JButton("EXIT"));
        content.add(new JButton("PLAY AGAIN"));
        f.setVisible(true);  
      }
    }
    Last edited by jsobel; 04-06-2012 at 04:21 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Detecting buttons

    Read the API for JButton and follow the link to the tutorial on How to Use Buttons, Check Boxes, and Radio Buttons where you will find a detailed explanation and sample code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

Similar Threads

  1. Detecting second application action's
    By ContoNick in forum New To Java
    Replies: 5
    Last Post: 12-30-2011, 06:33 PM
  2. Detecting if the player presses q or e
    By meesterpickles in forum AWT / Swing
    Replies: 3
    Last Post: 12-18-2011, 04:38 PM
  3. Detecting Capitalization
    By danthegreat in forum New To Java
    Replies: 10
    Last Post: 09-09-2011, 09:46 PM
  4. Detecting if string or int
    By Alk in forum New To Java
    Replies: 6
    Last Post: 05-14-2011, 11:26 PM
  5. Detecting a lost X connection
    By jeffpaulwilson in forum AWT / Swing
    Replies: 2
    Last Post: 03-09-2011, 07:54 PM

Posting Permissions

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