Re-set Combobox, radiobutton and checkboxes
How do I re-set the combobox, radiobutton, checkboxes at the click ofclear button?
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class WClass extends JFrame implements ActionListener
{
Computer computer = new Computer();
private JPanel P1;
private JPanel P2;
private JButton submit;
private JButton clear;
private JTextArea Out;
private JLabel name;
private JTextField Custname;
private JComboBox processor;
private JComboBox harddrive;
private JRadioButton ram1;
private JRadioButton ram2;
private JRadioButton ram3;
private JPanel radiopanel;
private ButtonGroup radiogroup;
private JComboBox processorsd;
private JLabel L1;
private JCheckBox printer;
private JCheckBox lan;
private JLabel L2;
private JCheckBox fpy;
private JCheckBox dvd;
private JCheckBox cdrw;
private JLabel L3;
private JLabel L4;
private JLabel L5;
private JLabel L6;
private JLabel L7;
private JLabel L8;
private JLabel L9;
private Container c;
int row;
float prncost = 50f;
float wlan = 110f;
float fppy = 110f;
float dvdw = 220f;
float cdw = 20f;
float Ram1 = 0f;
float Ram2 = 60f;
public WClass()
{
super("Laptop Configuration");
P1 = new JPanel();
P1.setLayout(new GridLayout(10,2,5,10));
P2 = new JPanel(new BorderLayout());
name = new JLabel("Customer Name");
P1.add(name);
Custname = new JTextField(10);
Custname.addActionListener(this);
P1.add(Custname);
L3 = new JLabel("Processor");
P1.add(L3);
String p[] = {"Pentium 4", "Celeron", "AMD", "Intel Centrino"};
processor = new JComboBox(p);
processor.setMaximumRowCount(3);
P1.add(processor);
L4 = new JLabel("Hard Disk");
P1.add(L4);
String h[] = {"30 GB", "40 GB", "60 GB"};
harddrive = new JComboBox(h);
harddrive.setMaximumRowCount(2);
P1.add(harddrive);
L5 = new JLabel("RAM");
P1.add(L5);
radiopanel = new JPanel();
radiopanel.setLayout(new GridLayout(1,2));
ram1 = new JRadioButton("256 MB", true);
ram2 = new JRadioButton("512 MB", false);
radiopanel.add(ram1);
radiopanel.add(ram2);
radiogroup = new ButtonGroup();
radiogroup.add(ram1);
radiogroup.add(ram2);
P1.add(radiopanel);
L6 = new JLabel("Processor Speed");
P1.add(L6);
String ps[] = {"1.8 GHz", "2.2 GHz", "2.8 GHz"};
processorsd = new JComboBox(ps);
processorsd.setMaximumRowCount(2);
P1.add(processorsd);
L1 = new JLabel("Additional Accessories");
P1.add(L1);
printer = new JCheckBox("Ink Jet Printer");
lan = new JCheckBox("Inbuilt Wireless LAN");
P1.add(printer);
L7 = new JLabel("");
P1.add(L7);
P1.add(lan);
L2 = new JLabel("Drives");
P1.add(L2);
fpy = new JCheckBox("Floppy(External)");
dvd = new JCheckBox("DVD Writer");
cdrw = new JCheckBox("CD Writer");
P1.add(fpy);
L8 = new JLabel("");
P1.add(L8);
P1.add(dvd);
L9 = new JLabel("");
P1.add(L9);
P1.add(cdrw);
c = getContentPane();
add(P1, BorderLayout.NORTH);
submit = new JButton("Submit");
submit.addActionListener(this);
clear = new JButton("Clear");
clear.addActionListener(this);
Out = new JTextArea(10,5);
P2.add(submit, BorderLayout.WEST);
P2.add(clear, BorderLayout.EAST);
P2.add(Out,BorderLayout.CENTER);
add(P2, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == submit)
{
computer.setName(Custname.getText());
computer.setProcessor(processor.getSelectedIndex());
computer.setHarddisk(harddrive.getSelectedIndex());
if(ram1.isSelected())
computer.setRam(Ram1);
if(ram2.isSelected())
computer.setRam(Ram2);
computer.setProcessorSpeed(processorsd.getSelectedIndex());
if(printer.isSelected())
computer.setPrinter(prncost);
if(lan.isSelected())
computer.setWireless(wlan);
if(fpy.isSelected())
computer.setFloppy(fppy);
if(dvd.isSelected())
computer.setDVD(dvdw);
if(cdrw.isSelected())
computer.setCdw(cdw);
Out.append("Computer Configuration for " + computer.getName() + "\n\n");
Out.append("Processor:\t\t\t " +computer.getProcessor()+ "\n");
Out.append("HardDisk: \t\t\t" + computer.getHarddisk() + "\n");
Out.append("RAM:\t\t\t" + computer.getRam() + "\n");
Out.append("ProcessorSpeed:\t\t" +computer.getProcessorSpeed() + "\n");
Out.append("Additional Accessories \t\t" + computer.getaa() + "\n");
Out.append("Drives :\t\t\t" + computer.getdrives() + "\n");
Out.append("\n");
Out.append("Total\t\t\t " + computer.getTotal() + "\n");
}
if(event.getSource() == clear)
{
Custname.setText("");
Out.setText("");
}
}
}

