Tuesday, 2 February 2016

Make an enabled and a disabled button

How to make an enabled and a disabled button

Program

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.*;

public class Enable_disable_Button
{

  public static void main(String[] args)
  {
    JFrame f1 = new JFrame("Welcome");
    JButton b1 = new JButton("OK enabled");
    b1.setBackground(Color.GREEN);
    b1.setEnabled(true);
    f1.add(b1);
    JButton b2 = new JButton("OK disabled");
    b2.setBackground(Color.GREEN);
    b2.setEnabled(false);
    f1.add(b2);
    f1.setVisible(true);
    f1.setSize(200,200);
    f1.setLayout(new FlowLayout(FlowLayout.LEFT));
    //f1.setProperty(JFrame.EXIT_ON_CLOSE);
   f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   }
}

Output




No comments:

Post a Comment