Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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..
 
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
 
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.
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!