I need to be able to assign an array to a .txt file so I need to reference the variable "s" outside the while loop. Even after I define and initialize the variable I still get an error when I initialize in the while loop. What am I doing wrong?
package vp.sga_form_generator;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class GUI extends JFrame{
public GUI() throws FileNotFoundException {
super("SGA Form Creator - Viper Productions");
setSize(1000,800);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(30, 2));
//Opens File
Scanner names = new Scanner(new File("names.txt"));
// String name1 = names.next();
String[] s;
while(names.hasNext()){
s = {names.next()};
}
JComboBox names1 = new JComboBox(s);
JComboBox names2 = new JComboBox(s);
add(names1);
add(names2);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.