PDA

View Full Version : Adding Buttons To Gui [Java]



SonniE
11-05-2009, 04:56 AM
Originally Submitted: http://fluidcoding.com/javaButtonEx.php
looks like this
http://www.fluidcoding.com/img/buttonExample.jpg (http://www.fluidcoding.com/javaButtonEx.php)


/**
* Application: Gui Button Example
* Author: Brian SonniE
* 5/11/09
* www.fluidcoding.com - Coding Simplified.
*/

import javax.swing.*;

public class ButtonExample extends JFrame{
private JButton myButton;
private JPanel pane;

public ButtonExample()
{
// Make application close when exit is clicked
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Set the title on the top of the window
setTitle("Button Example");
// make it visible
setVisible(true);
// set the size (Width, Height) of window
setSize(400,100);
// Build the JPanel
buildPane();
// Add the JPanel Containter to the JFrame
add(pane);
}

public void buildPane()
{
pane = new JPanel();
// Create an Instance of the JButton Object
myButton = new JButton("Click Me");

// Add the button to the JPanel
pane.add(myButton);
}
public static void main(String[] args) {
ButtonExample window = new ButtonExample();
}
}