Adding Two Buttons to a JFrame - Java Swing

Java examples for Swing:JFrame

Description

Adding Two Buttons to a JFrame

Demo Code

import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Adding Component to JFrame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton closeButton = new JButton("Close");
    JButton helpButton = new JButton("Help");
    Container contentPane = frame.getContentPane();
    contentPane.add(closeButton);// w w w .ja v a2s . co  m
    contentPane.add(helpButton);
    frame.pack();
    frame.setVisible(true);
  }
}

Related Tutorials