Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-18-2008, 12:39 PM
Member
 
Join Date: Jan 2008
Posts: 14
Joe2003 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-18-2008, 03:22 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 291
tim is on a distinguished road
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!
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 03:31 PM
Member
 
Join Date: Jan 2008
Posts: 14
Joe2003 is on a distinguished road
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.

thanks for the pointers
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-18-2008, 03:38 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 291
tim is on a distinguished road
Quote:
Originally Posted by Joe2003
image that may alter every 20 seconds
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.

It may be easier for you to create components extended from the javax.swing.* classes. Then, it may not be necessary to use graphics.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 01-18-2008 at 03:41 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 08:44 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,015
hardwired is on a distinguished road
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.
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 } } }
a image that may alter every 20 seconds
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.
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes in graphics CyberFrog New To Java 0 04-02-2008 10:11 PM
Graphics Joe2003 Advanced Java 1 01-25-2008 07:24 PM
Graphics feniger New To Java 1 12-29-2007 05:22 PM
Adding graphics to array romina Java 2D 1 08-01-2007 02:45 AM
Updating Graphics Greedful Java 2D 2 07-20-2007 08:12 PM


All times are GMT +3. The time now is 06:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org