import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Cars extends JApplet implements ActionListener, ItemListener
{
FlowLayout flow = new FlowLayout();
JButton buttonOne = new JButton("Male");
JButton buttonTwo = new JButton("Female");
JCheckBox clickMe = new JCheckBox("Married");
JCheckBox orMe = new JCheckBox("with children");
JLabel iSawThat = new JLabel("Press a button.");
Font bigFont = new Font("helvetica", Font.BOLD, 24);
public void init()
{
Container con = getContentPane();
con.setLayout(flow);
con.add(buttonOne);
con.add(buttonTwo);
con.add(clickMe);
con.add(orMe);
con.add(iSawThat);
iSawThat.setFont(bigFont);
buttonOne.addActionListener(this);
buttonTwo.addActionListener(this);
clickMe.addItemListener(this);
orMe.addItemListener(this);
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if(source == buttonOne)
{
if(clickMe.isSelected())
if(orMe.isSelected())
{
iSawThat.setText("YOU need a generic minivan.");
}
else
{
iSawThat.setText("You need a Toyota Echo.");
}
else if(orMe.isSelected())
{
iSawThat.setText("You need a Pontiac GTO.");
}
else
{
iSawThat.setText("You need a Chevrolet Corvette.");
}
}
else
{
if(clickMe.isSelected())
if(orMe.isSelected())
{
iSawThat.setText("You NEED a GMC Yukon Denali.");
}
else
{
iSawThat.setText("You need a Toyota Prius.");
}
else if(orMe.isSelected())
{
iSawThat.setText("You need a generic minivan.");
}
else
{
iSawThat.setText("You need a Toyota Echo.");
}
}
repaint();
}
public void itemStateChanged(ItemEvent event)
{
{
iSawThat.setText("Select Male or Female.");
}
repaint();
}
}