在开始之前,我将整个窗格作为动作打开。我想知道为什么如果我运行这个程序,它不输出10行方程,文本区域在它们的右边。它输出一个窗口,里面什么都没有。 (程序正在代码的不同部分运行 - 这是一个片段。)
`
pane2.setLayout(new GridBagLayout());
GridBagConstraints d = new GridBagConstraints(); //Creates New GBC
if (shouldFill)
{
//natural height, maximum width
d.fill = GridBagConstraints.HORIZONTAL;
}
if(multiTable >= 1 && multiTable <= 12)
{
for(int r = 1; r <= 10; r++)
{
int[] answer = {1};
JPanel[] prob = new JPanel[10];
JLabel[] probOutput = new JLabel[10];
JTextArea[] uAnswer = new JTextArea[10];
prob[r] = new JPanel();
rand1 = random1.nextInt(12)+1;
rand2 = random1.nextInt(2)+1;
answer[r] = multiTable * rand1;
if(rand2 == 1)
probType =( r+") "+multiTable+" x "+rand2);
if(rand2 == 2)
probType =( r+") "+rand2+" x "+multiTable);
probOutput[r] = new JLabel(probType);
d.gridx = 0;
d.gridy = r;
pane2.add(probOutput[r], d);
uAnswer[r] = new JTextArea();
d.gridx = 1;
d.gridy = r;
pane2.add(uAnswer[r], d);
}
frame2.add(pane2);
frame2.pack();
}
}`
Here是完整程序的pastebin链接的链接(这是我不太关心的学校计划,只需要等级。)