Re: Graphics help please



On Sat, 26 Jan 2008 20:31:18 -0000, Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

Actually, I don't think the code below helps me much with what I want to do (draw images pixel by pixel) as I don't want to clear the entire image before displaying the changes, which is effectively what happens below. I just used the circle as test code to render with pixels. How do I just add to the image and then display that without clearing it each time?

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class test2 extends JPanel implements Runnable {
private volatile int angle;

public test2() {
setPreferredSize(new Dimension(300,300));
}

public void run() {
while (--angle >= -360) {
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}

public void paintComponent(Graphics g2D) {
Graphics2D g = (Graphics2D)g2D;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.WHITE);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.BLUE);
g.drawArc(0,0,getWidth()-1,getHeight()-1,90,angle);
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test2 t2 = new test2();
f.add(t2);
f.pack();
f.setVisible(true);
new Thread(t2).start();
}
});
}
}


.



Relevant Pages

  • Really interesting graphics/image problem
    ... I created three gray 1600x1200 pixel images by creating a BufferedImage with type INT_RGB, getting a graphics and doing a fillRect on the whole image with Color.GRAY. ... public void actionPerformed{ ... public void setScroll(boolean scroll) { ...
    (comp.lang.java.gui)
  • Re: Graphics help please
    ... Actually, I don't think the code below helps me much with what I want to do (draw images pixel by pixel) as I don't want to clear the entire image before displaying the changes, which is effectively what happens below. ... The JPanel is buffered so that it doesn't actually clear the screen just the offscreen buffer. ... public void paintComponent{ ...
    (comp.lang.java.programmer)
  • Re: Draw a scaled arrow
    ... I am displaying an image, and want to draw arrows on this image at the scale the image is displayed at using the mouse, ... I guess I just need a pointer as to where to apply the scale factors to the arrow head so that it is scaled correctly if zoomed in or out and drawn to the image correctly. ... public void mousePressed{ ...
    (comp.lang.java.programmer)