public class Start {
public static void main(String[] args) {
JFrame j = new JFrame();
final Graphics g = j.getGraphics();
JButton jb = new JButton("Start");
j.add(jb);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
HeavenlyBiome.spread(g);
}
});
}
}
...
public class HeavenlyBiome {
static Random r = new Random();
public static void spread(Graphics g){
g.setColor(Color.yellow);
int spread = r.nextInt(2)+1;
if (spread==1){
g.fillRect(0,600,10,10);
}
So I run this and everything compiles right with no errors but the problem is that no window appears! If it helps at all, this is all from a package that is not default, and maybe there’s something special you need to do when youre using a new package? I dont know because i’m a new coder so any help is appreciated!
Try calling
setVisible(true)on yourJFrameinstance.And read this: http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html