import javax.swing.*;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Container;
public class lille extends JFrame implements ActionListener, ItemListener {
JTextArea addressArea;
JScrollPane addressPane;
JLabel addressLabel;
JLabel freqLabel;
JComboBox freqButton;
JCheckBox tradeButton;
JLabel tradeLabel;
JRadioButton age1;
JRadioButton age2;
JRadioButton age3;
JRadioButton age4;
ButtonGroup ageButton;
JPanel agePanel;
JPanel freqPanel;
JPanel procPanel;
JPanel blankPanel;
Container cp;
String[] comboString={"First Time","Occasionally","Frequently"};
JButton procButton;
public lille() {
cp = this.getContentPane();
cp.setLayout(new GridLayout(5,1));
agePanel = new JPanel();
agePanel.setLayout(new GridLayout(4,1));
freqPanel = new JPanel();
freqPanel.setLayout(new GridLayout(1,2));
procPanel = new JPanel();
procPanel.setLayout(new GridLayout(1,1));
blankPanel = new JPanel();
blankPanel.setLayout(new GridLayout(2,2));
addressLabel = new JLabel("Enter Name and Address:");
cp.add(addressLabel);
addressArea = new JTextArea(3,12);
addressPane = new JScrollPane(addressArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
cp.add(addressPane);
tradeLabel = new JLabel("Check if you are a trade Customer");
tradeButton = new JCheckBox("Trade Customer", false);
tradeButton.addItemListener(this);
cp.add(tradeLabel);
cp.add(tradeButton);
freqLabel = new JLabel("How often do you shop with us:");
freqPanel.add(freqLabel);
freqButton = new JComboBox(comboString);
freqButton.addActionListener(this);
freqPanel.add(freqButton);
cp.add(freqPanel);
ageButton = new ButtonGroup();
age1= new JRadioButton("age under 20");
age2= new JRadioButton("20-39");
age3= new JRadioButton("40-59");
age4= new JRadioButton("over 60");
ageButton.add(age1);
ageButton.add(age2);
ageButton.add(age3);
ageButton.add(age4);
age1.addActionListener(this);
age2.addActionListener(this);
age3.addActionListener(this);
age4.addActionListener(this);
agePanel.add(age1);
agePanel.add(age2);
agePanel.add(age3);
agePanel.add(age4);
cp.add(agePanel);
cp.add(blankPanel);
procButton = new JButton("Process Info");
procButton.addActionListener(this);
procPanel.add(procButton);
cp.add(procPanel);
this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
} //End of lille constructor
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JComboBox) {
System.out.println("Customer Shops: " + freqButton.getSelectedItem() );
} else if (e.getSource() instanceof JRadioButton) {
if ( age1.isSelected() ) {
System.out.println("Customer is under 20");
} else if (age2.isSelected() ) {
System.out.println("Customer is 20 - 39");
} else if (age3.isSelected() ) {
System.out.println("Customer is 40 - 59");
} else if (age4.isSelected() ) {
System.out.println("Customer is over 60");
}
} else if (e.getSource() instanceof JButton) {
System.out.println("Process Order");
System.out.println("Text Box Contains:" + addressArea.getText());
}
} //End of actionPerformed
public void itemStateChanged (ItemEvent e) {
if (e.getSource() instanceof JCheckBox) {
JCheckBox buttonLabel = (JCheckBox)e.getItemSelectable();
if (buttonLabel == tradeButton) {
if(e.getStateChange() == e.SELECTED) {
System.out.println("Customer is trade");
} else {
System.out.println("Customer is not trade");
}
}
}
} //End of itemStateChanged
public static void main(String args[]) {
lille ll = new lille();
ll.setTitle("EXAMPLE");
ll.setSize(400,600);
ll.setVisible(true);
}
} // End of lille