Thread: graphics
View Single Post
  #5 (permalink)  
Old 01-18-2008, 08:44 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
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
Reply With Quote