Solved

Combo items

Posted on 2000-05-18
4
199 Views
Last Modified: 2010-08-05
How do I read in strings from a text file, one digit on each line and use the digit to choose Choices in Combo options(drop down menus) I think that say theres 6 choices in each one so 0 would indicate choose the first and so on .Any ideas ?
Thanks in advance
0
Comment
Question by:spunog
  • 2
4 Comments
 
LVL 3

Expert Comment

by:ovidiucraciun
Comment Utility
can you be more specific, please explain in more words...
0
 
LVL 2

Accepted Solution

by:
shchuka earned 50 total points
Comment Utility
Well, you can use BufferedReader to read the lines of text and then convert them into integers - something like this:

import java.io.*;

int chNum;

try {
    BufferedReader br = new BufferedReader(new FileReader(filename));
    chNum = Integer.valueOf(br.readLine()).intValue();
    // You can read the rest of the lines here beyond the first one
}
catch(IOException ex) {
    // errors with the file
}
catch(NumberFormatException ex) {
    // what you read is not a number
}


And then you simply do this:

Choice combobox = new Choice();
....
combobox.select(chNum);


Hope, this helps,
-Aleks.
0
 
LVL 2

Expert Comment

by:Veroland
Comment Utility
File fin = new File("Filename");
BufferedInputStream bIn = new BufferedInputStream(fsIn);
BufferdReader brIn = new BufferedReader(new InputStreamReader(bIn));

String str = new String();
str = brIn.readln();
int s = dd.intValue(str);

combo1.getItemAt(s.intValue);

This is just a rough example, if you need more detail let me know


0
 
LVL 2

Expert Comment

by:Veroland
Comment Utility
opps, supposed to look like this:

String str = new String();
str = brIn.readln();
Long dd = new Long(str);
int s = dd.intValue();

combo1.getItemAt(s.intValue);
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now