Results 1 to 5 of 5
Thread: graphics
- 01-18-2008, 11:39 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 21
- Rep Power
- 0
graphics
Hey
I want to do some basic graphics, it will just be lines of different colour at different angles, nothing special. Anyway I wanted your opinion on what would be best to do it with. So far Its either gonna be a java applet, or using the graphics/paint class in swing? Anyways, I want to be able to add it to a scroll pane too. Its a stand alon app, nothing web realated
So any opinions, sugestions, warnings?
thanks!
Joe
- 01-18-2008, 02:22 PM #2
Buffers and Threading
Hello Joe2003
Read up on buffers and threading for graphics. These concepts are very important for graphical programs. Buffers are used to prevent flickering while threading is for animation. I have created program that uses graphics to draw an animated yin yang. This should help you, since the source is documented. Please take a look.
Hope you have fun! :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-18-2008, 02:31 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 21
- Rep Power
- 0
Hey Tim, thanks for that
I will read into that, its not animation as such, just static a image that may alter every 20 seconds or so. Im trying to display the output from an array of sensors I have encorparated onto some hardware, i have the raw data, I just need a simple way of displaying it. :rolleyes:
thanks for the pointers
- 01-18-2008, 02:38 PM #4
Joe2003, if an image changes, it is animation, even if it is every 20 seconds. You will still need to use some kind of threading; unless the user clicks "refresh" every 20 seconds.
Originally Posted by Joe2003
It may be easier for you to create components extended from the javax.swing.* classes. Then, it may not be necessary to use graphics.Last edited by tim; 01-18-2008 at 02:41 PM.
Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 01-18-2008, 07:44 PM #5
lines of different colour at different angles
An esay way to do this is to draw them in the paintComponent method of a JPanel. You can add it to your top–level container, viz, JFrame or JApplet. You may need to set a preferredSize on the panel; depends on its parent layout manager among other things.
a image that may alter every 20 secondsJava Code:class Pseudo extends JPanel implements Runnable { BufferedImage image; // animation variables as needed protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, x, y, this); g.setColor(Color.red); g.drawLine(x1, y1, x2, y2); } public void run() { while(boolean) { try Thread.sleep(millis) reassign image or change animation variables repaint } } }
You can draw an image inside paintComponent and change the image inside a background Thread. Or you can wrap the image in an ImageIcon and mount it in a JLabel; a simpler way.
Java Code:BufferedImage image = ImageIO.read(file_url_stream_options); ImageIcon icon = new ImageIcon(image); JLabel label = new JLabel(icon); label.setHorizontalAlignment(JLabel.CENTER); // add to top–level container
Similar Threads
-
Classes in graphics
By CyberFrog in forum New To JavaReplies: 0Last Post: 04-02-2008, 09:11 PM -
Graphics
By Joe2003 in forum Advanced JavaReplies: 1Last Post: 01-25-2008, 06:24 PM -
Graphics
By feniger in forum New To JavaReplies: 1Last Post: 12-29-2007, 04:22 PM -
Adding graphics to array
By romina in forum Java 2DReplies: 1Last Post: 08-01-2007, 01:45 AM -
Updating Graphics
By Greedful in forum Java 2DReplies: 2Last Post: 07-20-2007, 07:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks