//a very simpistic swing example showing frames and an action listener
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ButtonEx implements ActionListener{
//keep frame as instance variable
private JFrame mainWin;
//constructor initializes instance variable
public ButtonEx(){

mainWin = new JFrame("This is the main Window");

//put together the graphical windows
public void setupWindow(){
Container cPane = mainWin.getContentPane();
//create two new buttons
JButton b1 = new JButton("Button 1");
JButton b2 = new JButton("Sample Second Button");
//use the current ButtonEx object as the action listener for both buttons
//now add both buttons to be visible on the screen
//the second parameter to the line just below tels java to put the
//first button at the top.
cPane.add(b1, BorderLayout.NORTH);
mainWin.pack();//set the size of the main window to just the size
//needed for all of its contents (the two buttons in this case)

public void actionPerformed(ActionEvent e){
System.out.println("Hey a button got pushed!!");
System.out.println("The text was "+e.getActionCommand());


public static void main(String[] args){
ButtonEx app = new ButtonEx();