Results 1 to 5 of 5
Thread: JFrame help
- 02-05-2012, 08:40 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
JFrame help
whenever i run this, it either opens with a white screen or it opens with the stuff behind it on the screen, and whenever i minimize it and unminimize it, the screen is black.
any suggestions?
Java Code:package firstgame; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class Game extends JFrame{ private static final Color BLUE = null; public Game(){ setTitle("First Game"); setBackground(BLUE); setSize(640,480); setResizable(false); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args){ new Game(); } public void paint(Graphics g){ g.drawString("hello", 5, 40); } }
- 02-05-2012, 09:13 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: JFrame help
Read the API documentation for the JFrame class: unlike a Frame, you can't draw on a JFrame; you draw on its ContentPane instead. You can supply your own ContentPane (usually a JPanel) and draw on it.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-05-2012, 09:19 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 35
- Rep Power
- 0
Re: JFrame help
Ok thanks! I found the api documentation, and am reading it now!
- 02-05-2012, 09:21 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 02-05-2012, 10:26 AM #5
Re: JFrame help
There's also a very god tutorial for Swing: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
The part you'll need to go through right away is Performing Custom Painting.
Moving this thread to AWT/Swing
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Calling another JFrame from a JFrame through a JButton...(Help Reqired)
By nish.singha20 in forum AWT / SwingReplies: 3Last Post: 11-27-2011, 05:18 AM -
to pass a parameter from a jframe children to its jframe mother
By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 06:10 PM -
Passing data from one JFrame to another JFrame. - need help.
By Unsub in forum New To JavaReplies: 6Last Post: 04-12-2010, 11:33 AM -
Passing data from one JFrame to another JFrame
By tarami in forum New To JavaReplies: 3Last Post: 08-06-2009, 05:44 PM -
How to make a Jframe un-focusable when another Jframe is active?
By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-22-2009, 11:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks