Java 我的框架打不开
当我尝试在JGrasp或Eclipse上运行代码时,不会弹出JFrame。虽然我对编码很陌生,但我认为我做的每件事都是对的Java 我的框架打不开,java,jframe,Java,Jframe,当我尝试在JGrasp或Eclipse上运行代码时,不会弹出JFrame。虽然我对编码很陌生,但我认为我做的每件事都是对的 import javax.swing.*; import java.awt.*; public class test { private JFrame f; private JPanel p; private JButton b1; private JLabel lab; public void test() {
import javax.swing.*;
import java.awt.*;
public class test {
private JFrame f;
private JPanel p;
private JButton b1;
private JLabel lab;
public void test()
{
gui();
}
public void gui()
{
f = new JFrame("This is the title of the JFrame");
f.setVisible(true);
f.setSize(600,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new JPanel();
p.setBackground(Color.CYAN);
b1 = new JButton("This is the JButton");
lab = new JLabel("This is the JLabel");
p.add(b1);
p.add(lab);
f.add(p);
}
public static void main (String args []){
new test();
}
}
调用setVisible(true)
last。看
调用setVisible(true)
last。看
我同意Whiskyspider,但是你的构造函数不应该有返回类型
public void test()
应更改为public test()
我同意Whiskyspider,但您的构造函数不应具有返回类型public void test()
应更改为public test()
同意。我认为这是什么都没有出现的主要原因。同意。我认为这是什么都没有出现的主要原因。你还应该在事件调度线程上完成所有GUI工作。你还应该在事件调度线程上完成所有GUI工作。
f.pack();
f.setVisible(true);