Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 启动GUI程序时没有界面_Java_Swing_Intellij Idea - Fatal编程技术网

Java 启动GUI程序时没有界面

Java 启动GUI程序时没有界面,java,swing,intellij-idea,Java,Swing,Intellij Idea,我对Intellij的想法有意见。当我运行代码时,即使没有错误,GUI也不会给我任何接口 你能帮帮我吗 代码如下: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class GUI implements ActionListener { int count =0; JFrame fr

我对Intellij的想法有意见。当我运行代码时,即使没有错误,GUI也不会给我任何接口

你能帮帮我吗

代码如下:

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

public class GUI implements ActionListener {
    int count =0;
    JFrame frame;
    JPanel panel;
    JButton button;
    JLabel label;

    public GUI(){
        frame=new JFrame();
        button =new JButton("Click me");
        button.addActionListener(this);
        label =new JLabel("Number of Clicks : 0");
        panel =new JPanel();
        panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 10, 30));
        panel.setLayout(new GridLayout(0, 1));
        panel.add(button);
        panel.add(label);

        frame.add(panel,BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("OUR GUI");
        frame.pack();
        frame.setVisible(true);

    }
    public void main(String[] args){
        new GUI();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        count++;
        label.setText("Number of Clicks : "+count );
    }
}

您应该将
公共void main(String[]args)
替换为
公共静态void main(String[]args)

java中的
main
方法始终是
publicstaticvoidmain(String[]args)
,其他标题不能是您的主方法。

为什么在主方法中使用新GUI()?一旦您在main声明中包含static,您的代码就可以为我工作了。new GUI()是打开windowJems的构造函数谢谢您…它终于工作了!!您忘记将
static
添加到
main
方法