View Single Post
  #1 (permalink)  
Old 12-05-2007, 02:24 PM
Soda Soda is offline
Member
 
Join Date: Dec 2007
Posts: 15
Soda is on a distinguished road
Whats wrong with my code???
Quote:
public void actionPerformed(ActionEvent ae)
{
String name, age;
String location;
String gender, conduct, gift;

//rbMale
if(ae.getSource() == rbMale)
{
gender = "Male";
}

//rbFemale
if(ae.getSource() == rbFemale)
{
gender = "Female";
}

//rbNice
if(ae.getSource()== rbNice)
{
cbGiftNice.setVisible(true);
cbGiftNaughty.setVisible(false);
conduct = "Nice";

if(ae.getSource() == cbGiftNice)
{
JComboBox cbNice = (JComboBox)ae.getSource();
gift = (String)cbGiftNice.getSelectedItem();
}
}

//rbNaughty
if(ae.getSource() == rbNaughty)
{
cbGiftNaughty.setVisible(true);
cbGiftNice.setVisible(false);
conduct = "Naughty";

if(ae.getSource() == cbGiftNaughty)
{
JComboBox cbNaughty = (JComboBox)ae.getSource();
gift = (String)cbGiftNaughty.getSelectedItem();
}
}

//cbLocation
if(ae.getSource() == cbLocation)
{
JComboBox cbLocation = (JComboBox)ae.getSource();
location = (String)cbLocation.getSelectedItem();
}

//bView
if(ae.getSource() == bView)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame vFrame = new JFrame("List");
vFrame.setSize(300,800);
vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
vFrame.setVisible(true);

JPanel vPanel = new JPanel();
JTextArea taView = new JTextArea();

vFrame.add(vPanel);
vPanel.add(taView);

name = tfName.getText();
age = tfAge.getText();

taView.append("Name:"+(" ")+name);
taView.append("Age:"+(" ")+age);
taView.append("Sex:"+(" ")+gender);
taView.append("Conduct:"+(" ")+conduct);
taView.append("Location:"+(" ")+location);
taView.append("Gift:"+(" ")+gift);
}
Here the problem:

The last variables gender, conduct, location and gift, in taView.append, gets an error during compilation. The error was "variable gender might not have been initialized" etc, but name and age does not get any error. If add the declaration in the bView, the error becomes something like this, "error has been declared at ActionEvent" Why is that? Whats the error in my code?

Thnx much for the help!!!

Last edited by Soda : 12-05-2007 at 02:27 PM.
Reply With Quote
Sponsored Links