Results 1 to 5 of 5

Thread: graphics

  1. #1
    Joe2003 is offline Member
    Join Date
    Jan 2008
    Posts
    21
    Rep Power
    0

    Default 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

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default 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! :D
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    Joe2003 is offline Member
    Join Date
    Jan 2008
    Posts
    21
    Rep Power
    0

    Default

    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

  4. #4
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    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.
    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.

  5. #5
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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.
    Java 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.
    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

  1. Classes in graphics
    By CyberFrog in forum New To Java
    Replies: 0
    Last Post: 04-02-2008, 09:11 PM
  2. Graphics
    By Joe2003 in forum Advanced Java
    Replies: 1
    Last Post: 01-25-2008, 06:24 PM
  3. Graphics
    By feniger in forum New To Java
    Replies: 1
    Last Post: 12-29-2007, 04:22 PM
  4. Adding graphics to array
    By romina in forum Java 2D
    Replies: 1
    Last Post: 08-01-2007, 01:45 AM
  5. Updating Graphics
    By Greedful in forum Java 2D
    Replies: 2
    Last Post: 07-20-2007, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •