문제

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Spel
{
private JFrame frame;


public Spel()
{
    makeFrame();
}
}

Here's my code. Im new to Java programming, and im trying to make a simple game. But i get this error when compiling, why is that?

EDIT: Solved this, thanks. Added new code:

private void makeFrame()
{
    frame = new JFrame("Spel");
    Container contentPane = frame.getContentPane();
    JLabel label = new JLabel("titel");
    contentPane.add(label);
    frame.pack();
    frame.setVisible(true);
}
도움이 되었습니까?

해결책

you don't have any makeFrame() method either in this class, nor in any imported static classes

try to add

public void makeFrame() {
 System.out.println("foo");
}

to your Spel class and see what happens

다른 팁

makeFrame();

Here you are calling a function named makeFrame From your code from above comment. Do it like

public class Spel
{
private JFrame frame;


public Spel()
{
    makeFrame();
}

public void makeFrame() 
{ 
 frame = new JFrame("Spel");
Container contentPane = frame.getContentPane();
JLabel label = new JLabel("titel");
contentPane.add(label);
frame.pack();
frame.setVisible(true);
}

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top