【发布时间】:2016-01-21 02:59:48
【问题描述】:
我的代码可以编译,但是当我运行它时,会弹出一条奇怪的错误消息。
错误信息说
“java.lang.StackOverflowError:null(在 sun.awt.Win32GraphicsConfig 中)。
它应该做的是打印出一个带有 4x10 按钮数组的面板,其中包含一个按钮以列出迄今为止所有存储的信息。这些按钮现在什么都不做,但这很好,因为我现在只关心实际的图形。如果需要,我可以将另一个类用于数组列表,我可以将其放入 cmets 中。
代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.*;
import java.io.File;
import java.io.PrintWriter;
public class CulminatingProjectGUI extends JFrame implements ActionListener
{
private static JButton[][] jbtNumButtons = new JButton[10][4];
private static JButton jbtList = new JButton("List");
ArrayList<Culminating> seats = new ArrayList<Culminating>();
public CulminatingProjectGUI()
{
//Construct JFame object as a container for other objects
JFrame frame = new JFrame("Fly By Buddies");
//Set the dimensions of the window
frame.setSize(750, 720);
//Creates a pane for content
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(11, 4));
jbtList.addActionListener(new CulminatingProjectGUI());
for (int m = 1,n = 1; n < 11;)
{
jbtNumButtons[n][m].addActionListener(new CulminatingProjectGUI());
if(n == 1)
{
jbtNumButtons[n][m].setText(m + "A");
}
else if(n == 2)
{
jbtNumButtons[n][m].setText(m + "B");
}
else if(n == 3)
{
jbtNumButtons[n][m].setText(m + "C");
}
else if(n == 4)
{
jbtNumButtons[n][m].setText(m + "D");
}
pane.add(jbtNumButtons[n][m]);
m++;
if(m > 4)
{
n++;
m = 0;
}
}
//add content pane to a frame
pane.add(jbtList);
frame.setContentPane(pane);
//Display the frame - window
frame.setVisible(true);
//Bring the window to front
frame.toFront();
}
public static void main(String []args)
{
CulminatingProjectGUI frame = new CulminatingProjectGUI();
//Create seat array. Still testing.
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("List"))
{
String listedFlyers = "";
for (int h =0;h< 40;h++)
{
listedFlyers = listedFlyers + seats.get(h).toString() + "\n";
}
JTextArea text = new JTextArea(listedFlyers, 10, 40);
JScrollPane scroll = new JScrollPane(text);
}
else if (e.getActionCommand().equals(""))
{
}
}
}
【问题讨论】:
-
这是整个错误信息吗?
-
是的,这就是整个错误信息
标签: java stack-overflow