If I create multiple frames within a method, will it work?
I'm using this code:
Code:
public void CreateFrame() {
Graphics g=getGraphics();
JFrame frame=new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add("", frame);
g.drawImage(mole11, 128, 104, frame);
frame.pack();
frame.setVisible(true);
}
to create multiple frames. Say I create nine frames using the method without closing any of them, will it work properly?
Re: If I create multiple frames within a method, will it work?
What makes you think that it will not work? Try it for your self :)
Re: If I create multiple frames within a method, will it work?
Why are you adding a JFrame to another JFrame's contentPane? Why are you drawing with an unstable Graphics object obtained via getGraphics()? What's the driving force behind all of this?
Re: If I create multiple frames within a method, will it work?
Quote:
Originally Posted by
Fubarable
Why are you adding a JFrame to another JFrame's contentPane? Why are you drawing with an unstable Graphics object obtained via getGraphics()? What's the driving force behind all of this?
I am new at programming and was tasked with creating a whack-a-mole program using frames, something i have never learned before.
Re: If I create multiple frames within a method, will it work?
Quote:
Originally Posted by
gregsakas
I am new at programming and was tasked with creating a whack-a-mole program using frames, something i have never learned before.
What you have posted in your original post is not how you'd do it.
All Swing solutions would involve you creating one and only one single JFrame. A possible solution could be where the JFrame has a JPanel that holds a grid of JLabels in a GridLayout, and then change the ImageIcons held by the JLabels for when you want a mole to appear and disappear. A Swing Timer and the Random class could help you with the animation and the random selection of mole holes.