When I run my program the Jbuttons sometimes show up but other times they don't. For example, if I change something unrelated to the JButtons it will not show them. It will just show an empty jframe. PS sorry if I made formatting error's with the code i'm new to this site. Any tips on asking questions would be appreciated.Also it wont let me show the top of the code either.
package ca.seanmckee.digcraft;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Game extends JPanel {
public static String versionnumber = "0.0.1"; //For updating game version number
public static String gamename = "Digcraft ";
public static boolean dig = true;
public static int rocks = 0;
public static int sticks = 0;
public static int logs = 0;
public static void main(String[]a){
JFrame frame = new JFrame(gamename + versionnumber);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JPanel panel = new JPanel();
frame.add(panel);
JButton dig = new JButton("Dig"); //Dig mechanic allows players to find things
JButton stickscounter = new JButton("Sticks: " + sticks);
JButton rockscounter = new JButton ("Rocks: " + rocks);
JButton logscounter = new JButton("logs" + logs);
JButton craft = new JButton("Craft"); //uses things found by digging to create more advanced things
panel.add(dig);
panel.add(stickscounter);
panel.add(rockscounter);
panel.add(logscounter);
panel.add(craft);
dig.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
dig();
}
});
}
public static void dig(){
int counter = 0;
while(counter < 5){
Random random = new Random();
int number;
number = 1+random.nextInt(50); //Gets random number to select what you dug up
switch(number){
case 1:
System.out.println("You find a rock");
rocks = rocks + 1;
break;
case 2:
System.out.println("You find a log");
logs = logs + 1;
break;
case 3:
System.out.println("You find a stick");
sticks = sticks + 1;
break;
default:
System.out.println("You dig deeper...");
break;
}
counter = counter + 1;
}
}
}