Friday, 1 January 2016

Make a coloured button in java

To make a coloured button in java use following code

Code:

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

public class myGreenButton
{

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

   }
}

Output:


No comments:

Post a Comment