![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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 |
|
|
|
|
|
#4 |
|
Programmer
|
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? |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|