Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将用户从GUI提供的输入存储到字符串数组中,以备将来在java中使用_Java - Fatal编程技术网

如何将用户从GUI提供的输入存储到字符串数组中,以备将来在java中使用

如何将用户从GUI提供的输入存储到字符串数组中,以备将来在java中使用,java,Java,好的,我要做的第一件事是将info设置为ArrayList,而不是字符串数组 public void launchFrame(){ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(500,500); f.setVisible(true); f.setLocationRelativeTo(null); JLabel nameL=new JLabel("Title", SwingConstan


好的,我要做的第一件事是将info设置为ArrayList,而不是字符串数组

public void launchFrame(){


      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  f.setSize(500,500);
      f.setVisible(true);
 f.setLocationRelativeTo(null);
JLabel nameL=new JLabel("Title", SwingConstants.LEFT);
String[] FormOptions = {"Choose","Text Field","Password Field","Button","Radio Button","Check Box","Drop Down Menu"};

    String[] NormalOptions = {"Choose","Write Text", "Upload Picture", "Frame", "I-Frame"};
    JTextField nameTF=new JTextField(10);

    final JPanel comboPanel = new JPanel();
    JLabel comboLbl = new JLabel("Form:");
JComboBox forms=new JComboBox(FormOptions);


comboPanel.add(comboLbl);
    comboPanel.add(forms);
comboPanel.add(nameL);
comboPanel.add(nameTF);

    final JPanel comboPanel1 = new JPanel();
    comboPanel1.setVisible(false);
    JLabel comboLbl1 = new JLabel("Normal HTML:");
    JComboBox Normals = new JComboBox(NormalOptions);

    comboPanel1.add(comboLbl1);
    comboPanel1.add(Normals);

    JButton HTML = new JButton( "Form or Normal");


HTML.addActionListener(new ActionListener()
    {
        @Override
        public void actionPerformed(ActionEvent event)
        {
           comboPanel1.setVisible(!comboPanel1.isVisible());
           comboPanel.setVisible(!comboPanel.isVisible());

        }
    });

    f.add(comboPanel, BorderLayout.NORTH);
    f.add(comboPanel1, BorderLayout.CENTER);
    f.add(HTML,BorderLayout.SOUTH);

    f.setVisible(true);


static String[] info = new String[500];//Here i need help               
}

public static void main(String args[]){
      BasicGuiTest gui = new BasicGuiTest();
      gui.launchFrame();
  }
//What Should i do here? I want to get whether the user is choosing form or Normal as 

//well as its options..

private class GetInfo implements ActionListener
{
    public void actionPerformed(ActionEvent ae)
    {

        info[i]=comboPanel.getSelectedItem
}
//Then i will output the string array to a text file..
下面是将列表写入文件的代码

info.append(comboPanel.getSelectedItem());

这是否回答了您的问题?

或者,您可以避免重新发明轮子并使用内置的java首选项API

info.append(comboPanel.getSelectedItem());
FileWriter writer = new FileWriter(new File("C:/filename.txt"));
for(String line : info){
    writer.write(line + "\n");
}
writer.close();