Simple help
Tahnks to all you guys who helped me with the code. There is a small problem i wan to display the output in the following progrma in a textarea that is attcahed to lower. how to display the Output in a textarea in a panel. I am using an another window to display the output but i want to display the output in the same window in a teaxt area and when clear is pressed it should clear everything
mport java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowClass extends JFrame implements ActionListener{
private JPanel topPanel;
private JPanel bottomPanel;
private JTextField tname;
private JLabel cname;
private JComboBox processor;
private JComboBox hardDisk;
private JRadioButton mb256,mb512;
private ButtonGroup radiogroup;
private JComboBox procspeed;
private JCheckBox ijp,iwl;
private JCheckBox floppy,dvd,cd;
private Container c;
private String pnames[]={"Pentium 4","Celeron","AMD","Intel Centrino"};
private String hnames[]={"30 GB","40 GB","60 GB"};
private String snames[]={"1.8 GHZ","2.2 GHZ","2.8 GHZ"};
private JButton submit;
private JButton clear;
private JTextArea output;
public WindowClass() {
Container c=getContentPane();
topPanel=new JPanel();
topPanel.setLayout(new GridLayout(6,2,5,5));
cname=new JLabel("Name:");
topPanel.add(cname);
tname=new JTextField(10);
topPanel.add(tname);
processor=new JComboBox(pnames);
processor.setMaximumRowCount(3);
topPanel.add(processor);
hardDisk=new JComboBox(hnames);
hardDisk.setMaximumRowCount(3);
topPanel.add(hardDisk);
procspeed=new JComboBox(snames);
procspeed.setMaximumRowCount(3);
topPanel.add(procspeed);
mb256=new JRadioButton("256 MB",true);
topPanel.add(mb256);
mb512=new JRadioButton("512 MB",false);
topPanel.add(mb512);
radiogroup=new ButtonGroup();
radiogroup.add(mb256);
radiogroup.add(mb512);
ijp=new JCheckBox("Ink Jet Printer",true);
topPanel.add(ijp);
iwl=new JCheckBox("Inbuilt wireless LAN",false);
topPanel.add(iwl);
floppy=new JCheckBox("Floppy",false);
topPanel.add(floppy);
dvd=new JCheckBox("DVD Writer",false);
topPanel.add(dvd);
cd=new JCheckBox("CD Writer",false);
topPanel.add(cd);
c.add(topPanel,BorderLayout.NORTH);
bottomPanel=new JPanel();
submit=new JButton("Submit");
clear=new JButton("Clear");
bottomPanel.setLayout(new GridLayout(1,100));
bottomPanel.add(submit);
submit.addActionListener(this);
bottomPanel.add(clear);
clear.addActionListener(this);
c.add(bottomPanel,BorderLayout.SOUTH);
}
public static void main(String args[])
{
WindowClass wc = new WindowClass();
wc.setSize(400,400);
wc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
wc.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String command=ae.getActionCommand();
if(command.equals("Submit"))
{
Computer computer=new Computer();
String name=tname.getText();
computer.setName(name);
int code1=processor.getSelectedIndex();
computer.setProcessor(code1);
int code2=hardDisk.getSelectedIndex();
computer.setHarddisk(code2);
int code3=procspeed.getSelectedIndex();
computer.setprocessorspeed(code3);
if(mb256.isSelected())
computer.setRam(256);
else if(mb512.isSelected())
computer.setRam(512);
if(ijp.isSelected())
computer.setPrinter();
if(iwl.isSelected())
computer.setWireless();
if(floppy.isSelected())
computer.setFloppy();
if(dvd.isSelected())
computer.setDVD();
if(cd.isSelected())
computer.CDw();
computer.show();
}
if(command.equals("Clear"))
{
tname.setText(" ");
}
}
private class Computer {
private String name="";
private double processor_cost;
private double total_cost=0.0;
private double hard_drive_cost;
private double ram_cost;
private double processor_speed_cost;
private double printer_cost;
private double wireless_cost;
private double floppy_cost;
private double dvd_cost;
private double cdwriter_cost;
private String output;
public void setName(String obj1)
{
name=obj1;
output+=name+"\n";
}
public void setProcessor(int obj2)
{
if (obj2==0)
{
processor_cost=1200.00;
output+="Processor: Pentium4$1200.00";
}
if (obj2==1)
{
processor_cost=700.00;
output+="Processor: celeron $700.00"+"\n";
}
if (obj2==2)
{
processor_cost=650.00;
output+="Processor: AMP$650.00"+"/n";
}
if (obj2==3)
{
processor_cost=1300.00;
output+="Processor: Intel Centrino$1300.00"+"\n";
}
total_cost=total_cost+processor_cost;
}
public void setHarddisk(int obj3)
{
if (obj3==0)
{
hard_drive_cost=0.00;
output+="Hard Disk: 30 GB$0.00"+"\n";
}
if (obj3==1)
{
hard_drive_cost=100.00;
output+="Hard Disk: 40 GB$100.00"+"\n";
}
if (obj3==2)
{
hard_drive_cost=175.00;
output+="Hard Disk: 60 GB$175.00"+"\n";
}
total_cost=total_cost+hard_drive_cost;
}
public void setRam(int obj5)
{
if (obj5==256)
{
ram_cost=0.00;
output+="RAM: 256 MB $0.00"+"\n";
}
if (obj5==512)
{
ram_cost=100.00;
output+="RAM: 512 MB$75.00"+"\n";
}
total_cost=total_cost+ram_cost;
}
public void setprocessorspeed(int obj4)
{
if (obj4==0)
{
processor_speed_cost=0.00;
output+="Processor Speed:1.8 GHZ $0.00"+"/n";
}
if (obj4==1)
{
processor_speed_cost=100.00;
output+="Processor Speed: 2.2 GHZ $100.00"+"/n";
}
if (obj4==2)
{
processor_speed_cost=125.00;
output+="Processor Speed:2.8 GHZ$125.00"+"/n";
}
total_cost=total_cost+processor_speed_cost;
}
public void setPrinter()
{
printer_cost=0.00;
output+="Additional Accessories: Ink jet Printer$50.00"+"/n";
total_cost=total_cost+printer_cost;
}
public void setWireless()
{
wireless_cost=0.00;
output+="Additional Accessories: Inbuilt Wireless LAN$110.00"+"/n";
total_cost=total_cost+wireless_cost;
}
public void setFloppy()
{
floppy_cost=130.00;
output+="Drives: Floppy(External)$130.00"+"/n";
total_cost=total_cost+floppy_cost;
}
public void setDVD()
{
dvd_cost=250.00;
output+="Drives: DVD writer$250.00"+"/n";
total_cost=total_cost+dvd_cost;
}
public void CDw()
{
cdwriter_cost=0.00;
output+="Drives: Cd writer$20.00"+"/n";
total_cost=total_cost+cdwriter_cost;
output+="Total Cost:"+"/t/t/t/t/t"+total_cost;
}
public void show()
{
JOptionPane.showMessageDialog(null,output,"Computer Configuration for",JOptionPane.INFORMATION_MESSAGE );
}
}
}

