Like I said I am new to code, and I now am starting to learn how to make gui's in java here is my code
import java.awt.*;
import java.awt.event.*;
public class gui implements ActionListener{
private int count = 0;
private JLabel fat;
private JButton button;
private JLabel label;
public gui(){
JFrame frame = new JFrame();
button = new JButton("yes");
button.addActionListener(this);
fat = new JLabel("number of fatties: 0");
label = new JLabel("are you fat?");
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
panel.setLayout(new GridLayout(0, 1));
panel.add(label);
panel.add(button);
panel.add(fat);
frame.add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("mmmm gui");
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new gui();
}
@Override
public void actionPerformed(ActionEvent a) {
count++;
fat.setText("number of fatties: " + count);
if (count == 100){
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100));
panel.setLayout(new GridLayout(0, 1));
JLabel bigfat = new JLabel("wow to be so fat to take up 100 people, you must be really fat");
panel.add(bigfat);
frame.add(panel, BorderLayout.CENTER);
frame.setTitle("wow");
frame.pack();
frame.setVisible(true);
}
}
}
It runs perfectly fine in visual studio code, but when I use cmd and do
java gui
in the folder of the .java file, it returns Error: Could not find or load main class gui
so I could really use some help. I've looked it up everywhere, but I just dont understand any of it, so if yall could dumb it down for me that would be greatly appreciated