Results 1 to 6 of 6

Thread: What is the use of JButton class?

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    What is the use of JButton class?

    Hello friend,

    I need your help to sort out my java query. I am very weak in class concept of java. I am not getting what is the use of JButton class of java. I don't know anything about it's constructors. I have referred various website but nothing was helpful. If you posses sound knowledge about the JButton class of java, then please let me aware about the same. I would really appreciate you any help over JButton class.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is the use of JButton class?

    A JButton class of java is basically used for the implementations of the 'oush' button. The JButton class of java is extended from the 'javax.swing.AbstractButton' package of java programming language. This package is also taken from 'javax.swing.JComponent' package. A JButton class of java implements Accessible, ImageObserver, MenuContainer, Serializable, ItemSelectable interfaces. There are two subclasses of JButton class, which are BasicArrowButton and MetalComboBoxButton.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What is the use of JButton class?

    Hi,

    Please refer following example of java to know about the use of JButton class:
    Code:
    import javax.swing.JButton;
    import javax.swing.UIManager;
    
    public class JButtonDM
     {
      public static void main(String argds[]) throws Exception {
        JFrame frame02 = new JFrame("UIDefaults Example");
        frame02.setDefaultCloseOperation(3);
        Container c1 = frame02.getContentPane();
        UIManager.put("Button.background", Color.red);
        UIManager.put("Button.foreground", Color.white);
        Font f1 = new Font("Serif", Font.ITALIC, 24);
        UIManager.put("Button.font", f1);
    
        JButton north = new JButton("North");
        JButton west = new JButton("West");
        JButton center = new JButton("Center");
        c1.add(north, BorderLayout.NORTH);
        c1.add(west, BorderLayout.WEST);
        c1.add(center, BorderLayout.CENTER);
        frame02.pack();
        frame02.show();
    
      }
    
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is the use of JButton class?

    Please review following nested classes of JButton class, and which are very useful to access the properties of JButton class:
    • Component.BltBufferStrategy
    • JButton.AccessibleJButton
    • Container.AccessibleAWTContainer
    • AbstractButton.ButtonChangeListener
    • Component.FlipBufferStrategy

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the use of JButton class?

    In following example of java, I have used the JButton(String text, Icon icon) constructor of JButton class to create push button, please review it carefully:
    Code:
    import javax.swing.JButton;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    
    public class JButtonSample
     {
    
      public static void main(String argys[])
     {
        JFrame vQ = new JFrame("DefaultButton");
        vQ.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Icon warnIcon1 = new ImageIcon("Warn.gif");
        JButton button03 = new JButton("Warning", warnIcon1);
        vQ.add(button03);
        vQ.setSize(400, 200);
        vQ.setVisible(true);
      }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is the use of JButton class?

    Ordinary buttons — JButton objects have just a bit more functionality than the AbstractButton class provides: You can make a JButton be the default button. At most one button in a top-level container can be the default button. The default button typically has a highlighted appearance and acts clicked whenever the top-level container has the keyboard focus and the user presses the Return or Enter key. The exact implementation of the default button feature depends on the look and feel.

Similar Threads

  1. How to handle JButton Click Event in Java Swing
    By Kungfu Pandey in forum Software Development
    Replies: 3
    Last Post: 20-01-2012, 12:13 PM
  2. Add actionlistener to JButton
    By KAMANA in forum Software Development
    Replies: 6
    Last Post: 03-08-2010, 10:54 AM
  3. JButton to send command to Java console
    By Fox28 in forum Software Development
    Replies: 6
    Last Post: 21-07-2010, 10:03 AM
  4. JButton must retain its position when resizing
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 12:47 PM
  5. JButton does not work in java swing
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 15-04-2009, 12:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,045,148.39851 seconds with 17 queries