1

我是 java 新手,我们被要求制作一个程序,该程序将根据我的数组的大小创建多个 Jtextfields,我尝试了这段代码,但 JOption 窗口中没有显示

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class try3 {
public static void main(String[] args) throws IOException{

    String maindish = "Main.txt";
    String mainprice = "mainprice.txt";
    FileReader menu1 = new FileReader(maindish);BufferedReader Menu1 = new BufferedReader(menu1);
    FileReader price1 = new FileReader(mainprice);BufferedReader Price1 = new BufferedReader(price1);

    String menu = null;
    ArrayList MENU = new ArrayList();
    for (int a = 0; (menu = Menu1.readLine()) != null; a++ )
        MENU.add(menu);
    Object[] arr = new Object[MENU.size()];
    MENU.toArray(arr);





    int control = arr.length;
    JLabel[] label = new JLabel[arr.length];
    JTextField[] text = new JTextField[arr.length];
    JPanel panel = new JPanel(new BorderLayout());
    for (int a = 0; a >= control; a++){
        label[a] = new JLabel(arr[a].toString());
        text[a] = new JTextField("Quantity");   
        panel.add(label[a],BorderLayout.WEST);
        panel.add(text[a],BorderLayout.CENTER);}


    JOptionPane.showConfirmDialog(null, panel, "Login", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);

    }
}
4

0 回答 0