[JAVA]如何将数组从另一个类打印到GUI(使用JFrame)?

时间:2017-03-14 21:04:18

标签: java arrays swing

我正在处理包含多个类的代码。我正在尝试展示一个我已经创建另一个类的数组,进入GUI或JTextArea。但是,我一直收到错误。我请注意,创建此特定数组是为了存储文件中的数据。

这是我的代码的一部分:

public class THEGUI{  
    SUB c= new SUB(); *//in which SUB is a class that contains my array*
    String[] word= c.three(*W*);*//three is a method in the class SUB

    *//the text area*
    JTextArea textAreaLeft = new JTextArea(5, 20);
       textAreaLeft.setEditable(false);
       JScrollPane scrollPane = new JScrollPane(textAreaLeft);
       frame.getContentPane().add(scrollPane);
       frame.add(c.three(W))

在SUB类(一个完全不同的类/ .java文件)中:

class SUB{
    public static String[] W;
}

为什么我在尝试将数组W传递给我的三个方法时遇到错误,当我在W类中声明它时?我似乎无法将声明的数组放入GUI中。 GUI TextArea为空。如果您需要我澄清,请询问。

另外,我为格式化道歉。不知道如何解决这个问题。新来的:/

0 个答案:

没有答案