Results 1 to 7 of 7
Thread: graphics won't work
- 06-12-2012, 07:43 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 49
- Rep Power
- 0
graphics won't work
I followed a youtuber called TheNewBoston.
The problem is that it just gives me a greyish screen, and I have no idea what the problem is...
here is the code I used.
class Main(the main class!)
and my second class.Java Code:package gui.basicGraphic; import javax.swing.*; public class Main { public static void main(String[] args) { JFrame f = new JFrame("the title"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawGraphic dg = new DrawGraphic(); f.add(dg); f.setSize(400, 250); f.setVisible(true); } }
class DrawGraphic(the class with the graphics stuff!)
I hope someone know a solution to this :): cause I want to make GUI stuff, but if it doesn't work I have to do something else... :/Java Code:package gui.basicGraphic; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DrawGraphic extends JPanel{ public void PaintComponent(Graphics g){ super.paintComponents(g); this.setBackground(Color.WHITE); g.setColor(Color.BLUE); g.fillRect(25, 25, 100, 30); g.setColor(new Color(190,81,215)); g.fillRect(25, 65, 100, 30); g.setColor(Color.RED); g.drawString("this is some tecxt", 25, 120); } }
- 06-12-2012, 07:53 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Re: graphics won't work
Java is case sensitive - check the case of your methods...the @Override annotation helps you verify you have not misspelled a method you are intending to override
Java Code:@Override public void PaintComponent(Graphics g){//compile time error ... }
- 06-12-2012, 07:59 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 49
- Rep Power
- 0
Re: graphics won't work
it just tells me that the @Override has to go away, and it didn't fix anything.
- 06-12-2012, 08:21 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: graphics won't work
The method 'paintComponent' is with a lower case 'p'.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2012, 08:24 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 49
- Rep Power
- 0
Re: graphics won't work
Thanks that worked!
- 06-12-2012, 08:31 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: graphics won't work
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2012, 08:39 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 49
- Rep Power
- 0
Similar Threads
-
applet call dll work in Win2000 but not work in WinXP
By manhcuongtin4 in forum Java AppletsReplies: 1Last Post: 07-14-2011, 01:45 PM -
Drawing a graphics onto another Graphics ?
By Ziden in forum Java AppletsReplies: 0Last Post: 01-08-2011, 07:30 PM -
How to use graphics
By Mattedatten in forum New To JavaReplies: 3Last Post: 03-18-2010, 02:10 PM -
graphics
By Joe2003 in forum Advanced JavaReplies: 4Last Post: 01-18-2008, 07:44 PM -
Graphics
By feniger in forum New To JavaReplies: 1Last Post: 12-29-2007, 04:22 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks