Results 1 to 5 of 5
- 08-01-2012, 02:50 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 11
- Rep Power
- 0
If I create multiple frames within a method, will it work?
I'm using this code:
to create multiple frames. Say I create nine frames using the method without closing any of them, will it work properly?Java 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); }
- 08-01-2012, 03:29 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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 :)
Website: Learn Java by Examples
-
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?
- 08-01-2012, 03:21 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 11
- Rep Power
- 0
-
Re: If I create multiple frames within a method, will it work?
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.Last edited by Fubarable; 08-01-2012 at 03:46 PM.
Similar Threads
-
Resizing of frames doesn't work.
By Amanoo in forum AWT / SwingReplies: 3Last Post: 03-18-2012, 06:46 AM -
4 frames work toghether
By Shima in forum Threads and SynchronizationReplies: 4Last Post: 08-09-2010, 03:14 AM -
Help with multiple frames/classes
By Celletti in forum AWT / SwingReplies: 1Last Post: 04-28-2010, 03:18 AM -
Usually work with C++, need help replacing multiple inheritance in this case
By Stravant in forum New To JavaReplies: 2Last Post: 12-24-2009, 06:41 PM -
will java webBrowser work with frames
By elipford in forum New To JavaReplies: 2Last Post: 06-04-2007, 03:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks