Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Having problem.. pls help..! Ugently..  RSS feed

 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i having problem getting the selected item from a JComboBox, to save it in a text file.. i'm not sure which & what coding i have to use.. Pls help me..
Thanks..
 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the actionlistener to to get the selected item then in the actionlistener methos move it tothe textfile when u dothat it will be saved
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Freya Tan
While we all can empathise with your need for urgent replies to your questions, specifying so in the subject will most likely get your posts ignored.
We regard everyone's questions with the same sense of urgency. There are none more important than others.
Not to mention the site moderators have a tendancy to have fun with urgent questions. I thought I would give you a heads up since you are kinda new around here.
 
Freya Tan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying..
is this how i should do it..?
public void addData(String da, String mo, String ye, double ti, String am, String ap ) throws IOException {

App type = new App(da,mo,ye,ti,am,ap);
AppList.add(type);

File out = new File("Appointment.txt");

FileOutputStream output = new FileOutputStream(out);
PrintStream NewApp = new PrintStream(output);

for (int i = 0; i < AppList.size(); i++) {
type = (App)AppList.get(i);
NewApp.println(type.getDate() + ";" + type.getMonth() + ";" + type.getYear() + ";" + type.getYear() + ";" + type.getam() + ";" + type.getApp()); <------------- error
}

output.close();


dayInput.setText("");
monthInput.setText("");
yearInput.setText("");
timeInput.setText("");
am.setSelectedItem( "" ); <------------ error
appInput.setText("");

dayInput.requestFocus();
}



// actionPerformed is invoked when a Button is clicked
public void actionPerformed(ActionEvent e)
{

// when doneButton is clicked
if(e.getSource() == doneButton){
try {

String da = dayInput.getText();
String mo = monthInput.getText();
String ye = yearInput.getText();
double ti = Double.parseDouble(timeInput.getText());
String am = am.getSelectedItem(); <------- error
String ap = appInput.getText();
addData(da, mo, ye, ti, am, ap);
AppointmentPage();
}

catch (NumberFormatException nfe ) {

JOptionPane.showMessageDialog(this," You must enter an integer time " );
timeInput.setText("");
timeInput.requestFocus();
}
catch (IOException io) {

System.err.println(" Error writing to file\n" +
io.toString());
System.exit(1);
}

}

y do i have this 3 error..? can u help me..? Thanks alot..
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you take a look at the API you will notice that a JComboBox's getSelectedItem() returns an Objects, not a String.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!