0

I tried some swing today for a GUI in java. When I want to launch the application, this error appears. Here is my source code:

package de.hoffmann;

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainApplication extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

    public MainApplication() {

        JFrame mainFrame = new JFrame("Buchstaben-Häufigkeit");
        mainFrame.setSize(600,400);

        JPanel panel = new JPanel();
        panel.setBackground(Color.red);

        mainFrame.add(panel);

        pack();
    }

    public static void main(String[] args) {

        new MainApplication().setVisible(true);
    }

}

Where's the problem

user2971688
  • 123
  • 1
  • 3
  • 9

1 Answers1

0

The code works fine. I suggest you to set the dimension of panel object: panel.setSize(600,400); and set the mainFrame to visible: mainFrame.setVisible(true);. If you have a Java heap space problem, which I find strange however, have a look in here

Community
  • 1
  • 1
Anto
  • 4,265
  • 14
  • 63
  • 113