0

I am trying code a JPanel in a class (classA) and trying to instantiate it from a class (classB) (where the main method is).

But when I try to code the classA the content assist does not supports. It does not resolves panel related codes, shows syntax error.

What could the problem be?

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

public class gui1 {
    JFrame j = new JFrame("MY Menu");
    j.setSize(900, 700);
    j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    j.setResizable(false);
}
4

1 に答える 1

1

メソッド/静的初期化ブロックの外でメソッドを呼び出すことはできません。コンストラクターで初期化してみてください。

public class Gui1 {
    JFrame my_frame;
    public Gui1()
    {
        my_frame = new JFrame("MY Menu");
        my_frame.setSize(900, 700);
        my_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        my_frame.setResizable(false);
    }
}
于 2013-02-25T09:27:39.397 に答える