您好,我是 Java 图形的新手,只是在尝试一些东西,但我对如何在创建的窗口上显示数组中的数字感到困惑?我不确定它是否与文本相同?
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class area extends JFrame{
int[] myArray;
myArray = new int[3];
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;
JTextArea area = new JTextArea();
for (int i=0; i<myArray.length; i++)
{
area.append(myArray[i]+"\n");
}
add(area);
public static void main(String args[]) {
area gui = new area();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(400,200);
gui.setVisible(true);
}
}