Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jul 27th, 2005, 1:59 AM   #1
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
swing GUI stuff

Just wondering how I would actually load an image from a file and output it on a window I created. Its like I am making a simulation with 1000 pingpong balls bouncing off each other and need a way to draw ping pong balls on a spoecific coordinates.

My gui is too simple...
        JFrame window = new JFrame("1000 Ping-Pong Balls");
        JPanel panel = new JPanel();
        window.setContentPane(panel);
        
        panel.add((Component)icon);
        
        window.pack();
        window.show();
        
        
        window.setBounds(4,5,800, 600);

Thanks
__________________
Spread your wings and fly! Chicken!
rsnd is offline   Reply With Quote
Old Jul 27th, 2005, 8:04 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
I would just draw the "ping-ping" balls on the canvas. Look at Graphics2D, Circle, and Canvas.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 27th, 2005, 9:47 AM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
If you really want to load an image from file (this will be significantly slower than drawing the ping pong balls, of course, and I doubt you'd get a 1000 of them without the computer slowing down, but...) instantiate an Image object like so:

Image myImg = Toolkit.getDefaultToolkit().getImage("myImg.jpg");

Where you'd replace myImg.jpg with whatever image you want to load.

Then simply draw it in paint or whatever. The function is

drawImage(Image, x, y, height, width, this)

Use it just like you'd use the rectangle or oval function, except with those parameters.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Aug 9th, 2005, 9:06 PM   #4
EdSalamander
Programmer
 
EdSalamander's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ, USA
Posts: 80
Rep Power: 4 EdSalamander is on a distinguished road
Send a message via AIM to EdSalamander
You could also take the JLabel route.

JLabel ball = new JLabel(new ImageIcon("ball.jpg"));
ball.setBounds(xCoord, yCoord, imgWidth, imgHeight);
panel.add(ball);
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose?
EdSalamander is offline   Reply With Quote
Old Aug 10th, 2005, 4:39 AM   #5
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
Thanks guys...Im using a big buffered image with small images loaded by jordan's "Toolkit.getDefaultToolkit().getImage" shit
__________________
Spread your wings and fly! Chicken!
rsnd 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 11:05 PM.

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