根据数组大小创建Jtextfield

时间:2013-10-09 13:57:20

标签: jtextfield

我是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);

    }
}

0 个答案:

没有答案