Results 1 to 3 of 3
Thread: getting the value of variable
- 03-04-2008, 06:33 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 6
- Rep Power
- 0
getting the value of variable
public void actionPerformed(ActionEvent e)
{
if (!txtBox.getText().equals("")){
int a = 0;
for(int i = 0; i < combo.getItemCount(); i++){
if(combo.getItemAt(i).equals(txtBox.getText())){
a = 1;
break;
}
}
if (a == 1)
JOptionPane.showMessageDialog(null,"Combo has already this item.");
else
combo.addItem(txtBox.getText());
// I want to store the value of txtBox.text(), to an array and then to a file,
if some could show me how to do this it would be appreciated as i have tried for about an hour and a half myself.
thank you in advance!!
- 03-04-2008, 08:26 PM #2
Well, what do you about arrays, and FileWriting?
If you don't know how to use arrays, you should learn how. And, you will need to learn about the FileWriter class. (Or BufferedWriter, or PrintWriter).
Just let us know what you know so we can assist you.
- 03-05-2008, 01:42 AM #3
Member
- Join Date
- Dec 2007
- Posts
- 30
- Rep Power
- 0
You'll probably want an array list since you don't know how many items you'll be getting.
and then each time you find a new item and add it to the combo just add this line with it:import java.util.ArrayList; // import
ArrayList<String> items = new ArrayList<String>(); // how to declare one
As for writing it to a file, that's kind of complicated...items.add(txtBox.getText());
Similar Threads
-
Increment a Variable
By rhm54 in forum New To JavaReplies: 2Last Post: 06-14-2008, 02:57 AM -
Getting variable value from a variable name
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:26 PM -
Variable No. of Arguments
By Gajesh Tripathi in forum New To JavaReplies: 2Last Post: 10-31-2007, 02:50 PM -
Create a new variable
By mathias in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:48 AM -
String Variable
By Eric in forum Advanced JavaReplies: 1Last Post: 06-06-2007, 04:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks