안녕하세요 저는 텍스트 파일에서 항목을 나열하도록 콤보 상자를 가져 오는 데 어려움을 겪고 있습니다. 그리고 그 동안 나는 combobx를 바꿀 때 radioButton이 동적으로 변경되는지 또는 너무 많은 문제가 될 것인지 묻고 싶습니다.콤보 상자에서 텍스트 파일 사용
import java.awt.GridLayout;
import java.util.Arrays;
import java.util.Scanner;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.io.*;
public class MovieSelection extends JFrame {
private JRadioButton selection1;
private JRadioButton selection2;
private JRadioButton selection3;
private JPanel moviePanel;
private JLabel priceLabel;
private JComboBox movieBox;
private ButtonGroup bg;
private String[] movieName = { "RED", "Taken", "Star Trek", "Star Wars",
"Avatar" };
public MovieSelection() {
super("Please select your movie");
setSize(800, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(15, 4));
setLocationRelativeTo(null);
// PrintWriter outputFile = new PrintWriter(TheMovies.txt);
buildMoviePanel();
add(moviePanel);
setVisible(true);
}
private class MovieLists implements ActionListener {
public void actionPerformed(ActionEvent e) {
Scanner inputFile = new Scanner(TheMovies.txt);
while (inputFile.hasNext()) {
String nextMovieName = inputFile.nextLine();
}
JComboBox cb = (JComboBox) e.getSource();
String Themovie = (String) cb.getSelectedItem();
}
}
}
콤보 상자에서 전체 텍스트 파일을 원하십니까? – Apurv
'actionPerformed' 메쏘드의'스캐너 입력 파일 = 새 검사기 (TheMovies.txt);' –
'JComboBox movieLists = new JComboBox (TheMovies.txt); – Apurv