
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Bill Kraynek
 */
public class GUISample2 {

    JButton button2;

    public GUISample2() {
        JFrame theFrame = new JFrame("GUI Sample");
        Toolkit tk = Toolkit.getDefaultToolkit();
        int width = (int) (tk.getScreenSize().getWidth()) / 2;
        int height = (int) (tk.getScreenSize().getHeight()) / 2;
        theFrame.setSize(width, height);
        theFrame.setLocation(width / 2, height / 2);
        theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        theFrame.setLayout(new FlowLayout(FlowLayout.CENTER, width, 30));
        JLabel label1 = new JLabel("Label 1");
        JButton button1 = new JButton("Button 1");
        button1.addActionListener(new ButtonAction());
        JPanel panel1 = new JPanel();
        panel1.add(label1);
        panel1.add(button1);
        theFrame.add(panel1);
        JLabel label2 = new JLabel("Label 2");
        button2 = new JButton("Button 2");
        button2.setEnabled(false);
        button2.addActionListener(new ButtonAction());
        JPanel panel2 = new JPanel();
        panel2.add(label2);
        panel2.add(button2);
        theFrame.add(panel2);
        theFrame.setVisible(true);
    }

    class ButtonAction implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            String buttonLabel = e.getActionCommand();
            JOptionPane.showMessageDialog(null, buttonLabel + " was clicked");
            if (buttonLabel.equals("Button 1")) {
                button2.setEnabled(true);
            } else {
                button2.setEnabled(false);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new GUISample2();
    }
}

