Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 11th, 2006, 5:14 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
2-d graphics

Hey,

So I've started to make a tetris game for java. So far, I've created a bunch of classes.

Now I need a class to control the drawing of my tetris shapes. What would be the best way to display an image to the screen (such as a jpeg)?

Please help me out. I looked around google and sources tell me that if I don't use the correct methods, that the picture flickers a lot.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 11th, 2006, 6:47 PM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 751
Rep Power: 3 Jimbo is on a distinguished road
You probably dont want to actually write an image file. Look into the Swing classes, especially Graphics or Graphics2D. I think you modify the paint() method of the JFrame or JPanel you're drawing in to call the draw method for your stuff, using the Graphics object you get in paint().
Jimbo is offline   Reply With Quote
Old May 11th, 2006, 7:48 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Jimbo is dead on. As for flickering, I wouldn't worry. Swing is double-buffered by default, IIRC.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old May 11th, 2006, 10:27 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 839
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
What is the difference between Graphics and Graphics2D? They both appear to be for 2D drawing...
titaniumdecoy is offline   Reply With Quote
Old May 11th, 2006, 10:47 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5 lectricpharaoh will become famous soon enough
You don't need raster images for this. After all, the shapes are quite simple: they're basically squares. You might want bevelled edges with shading, in which case you can draw the block in its regular color, two adjacent edges (using line drawing) in a lighter color, and the remaining two edges in a darker color. You could do what I did, and use rounded rectangles. If you want to see if it looks good enough, the .jar file is here, though I think you'll need to save it locally before running it.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old May 15th, 2006, 4:14 PM   #6
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Quote:
Originally Posted by lectricpharaoh
You don't need raster images for this.
Actually, I want import pictures as a .jpeg. I do not want to use the built in draw commands e.x (drawRect, drawOval).

I looked everywhere for swing methods i still can't find any. Please if anyone knows how to draw a jpeg to the screen your help in this would be greatly appreciated.
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 18th, 2008, 4:15 AM   #7
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: 2-d graphics

[delete me]
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote
Old May 12th, 2006, 1:47 PM   #8
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 294
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
Quote:
Originally Posted by titaniumdecoy
What is the difference between Graphics and Graphics2D? They both appear to be for 2D drawing...
For one, Graphics2D allows the use of double and float data types.
andro is offline   Reply With Quote
Old May 12th, 2006, 5:56 PM   #9
curiosity-killed-the-cat
Newbie
 
Join Date: May 2006
Location: England
Posts: 2
Rep Power: 0 curiosity-killed-the-cat is on a distinguished road
Quote:
Originally Posted by titaniumdecoy
What is the difference between Graphics and Graphics2D? They both appear to be for 2D drawing...
From memory, i recall one of the differences is the reuse of objects.

Graphics:
    // normal draw large rectangle
    g.drawRect(10,10,300,300);
    g.drawString("First Rectangle",10,10);

Graphics 2D:
    // define a Rectangle2D object and ask g2D to draw it
    Rectangle2D r = new Rectangle2D.Float( 200.0F,30.0F,50.0F,50.0F);
    g2D.draw(r);

    // redefine the position of the rectangle
    r.setRect(20.0F,150.0F,50.0F,50.0F);

Lisa
curiosity-killed-the-cat is offline   Reply With Quote
Old May 15th, 2006, 4:58 PM   #10
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 294
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
Just use an ImageIcon, and then g.drawImage().
andro is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC