actionPerformed not returning a value.
Hello fellow java enthusiasts,
I have been stuck on this problem for this past few days.
I have tried different ways to get my program going but it failed.
Here it is.
Code :
public void doWrite(){
User u = new User();
String passconcat= new String(password.getPassword());
u.setUserName(username.getText());
u.setPassword(passconcat);
u.setName(name.getText());
doDisplayMonth().getActionListeners();
UserWriter writer = new UserWriter();
writer.writeUserInfo(u);
}
public JComboBox doDisplayMonth(){
Object comboBox [] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
final JComboBox month = new JComboBox(comboBox);
month.setBounds(86, 287, 97, 23);
contentPane.add(month);
month.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
User u = new User();
u.setMonth((String) month.getSelectedItem());
System.out.print(u.getMonth());
}
});
return month;
}
That piece of code is trying to write the selected item on a JComboBox containing an array of months.
I just want the method actionPerformed to return a string value to be declared at the method doWrite().
Any solutions?
It will be highly appreciated.
Thanks in advance.
PS. Sorry if my english is not that good.
Re: actionPerformed not returning a value.
Try using the ItemStateChanged event for the JComboBox, i've used that one before and i know it works. Let me know how that works out for you.