Friday 26 January 2018

JFrame Examples

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

public class JFrameExample2 {
  public static void main(String[] args) {

    JFrame f = new JFrame("This is a test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setDefaultLookAndFeelDecorated(true);
  
    f.setSize(400, 150);
    Container content = f.getContentPane();

    content.setBackground(Color.blue);
    content.setLayout(new FlowLayout());
  
    JPanel p = new JPanel();
    p.setOpaque(true);
  
    JLabel la = new JLabel("Name");
    p.add(la);
     JButton b1 = new JButton("Ok");
     p.add(b1);
    p.add(new JButton("Button 1"));
    p.add(new JButton("Button 2"));
    p.add(new JButton("Button 3"));
  
    p.setBorder(BorderFactory.createLineBorder(Color.RED));
    content.add(p);
  

    f.setVisible(true);
  }
 

}

0 comments: