import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

/**
* @author joanna
*
* Window demo, taken from Johnston04 (java prog today)
*
*/
public class BangPopAp extends JFrame implements ActionListener {

// these are all the widgets our inane ap will use
JButton bangButton = new JButton ("Bang");
JButton popButton = new JButton ("Pop");

// now we set everything up in the constructor...
public BangPopAp() {
// set the title bar for the window
this.setTitle("Bangs and Pops!");

// Frames come with their main container. This just adds a reference
// so we can refer to it more easily.
Container canvas = getContentPane();
// the layout determines where things will go when we add them.
canvas.setLayout (new GridLayout(2,1));

// here we add the buttons
canvas.add(bangButton);
canvas.add(popButton);

// we have to tell the buttons what's going to listen to them.
// Doing this is sometimes called "registering". We can use the instance
// `this' because we are implementing an ActionListener (see below).
// Once we've registered, when an event happens to one of the buttons,
// it will call its listener's .actionPerformed.
bangButton.addActionListener(this); // Leave lots of space around these for inner classes!!
popButton.addActionListener(this);

// The below two methods are both inherited from JFrame.
// The first sets the size the window will be when it appears.
// Generally want a value so all your widgets look reasonable from start.
this.setSize(250,150);
// Everything would pretty much work now, but if we didn't do show()
// no one could see it!
this.show();

}

// this is the one thing we have to do to implement ActionListener.
// We have to define method "actionPerformed". This just looks to see which
// widget called it (buttons only have one action!)
public void actionPerformed(ActionEvent e) {
if (e.getSource()==bangButton) {
JOptionPane.showMessageDialog(this, "Bang!");
} else if (e.getSource()== popButton) {
JOptionPane.showMessageDialog(this, "Pop!");
}
}

// now all we do to start the ball rolling is make an instance...
public static void main(String[] args) {
BangPopAp theApp = new BangPopAp();
// except we also need to say what to do when the frame is closed!
// if we didn't have this line, the program would keep running even
// after the window was gone (that would be bad...)
theApp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


} // class