Reputation: 1
My code compiles but when I run it, a weird error message pops up.
The error message says
"java.lang.StackOverflowError:null(in sun.awt.Win32GraphicsConfig).
What it's supposed to do is print out a panel with a 4x10 of a button array with a button to list all stored info so far. The buttons don't do anything right now but that's fine because I only care about the actual graphic for now. There is also another class that goes with this for the array list that I can put in the comments if needed.
Here is the code:
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(""))
{
}
}
}
Upvotes: 0
Views: 53
Reputation: 3071
jbtNumButtons[n][m].addActionListener(new CulminatingProjectGUI());
Here is the problem. You create the new instance of CulminatingProjectGUI
, and in constructor you create it again and again. You should consider the following:
jbtNumButtons[n][m].addActionListener(this);
Upvotes: 1