Reputation: 1
I have a problem with Intellij Idea. When I do run my code GUI doesn't give me any interface even there are no errors.
Can you please help me?
The code is below:
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 );
}
}
Upvotes: 0
Views: 71
Reputation: 813
You should replace public void main(String[] args)
by public static void main(String[] args)
.
The main
method in java is always public static void main(String[] args)
, other headers cannot be your main method.
Upvotes: 1