Double buffering circle not round anymore

I am making an applet where some circles are painted to the screen. When not using the double buffering scenario, the shapes appear correctly.
The problem is when i use the double-buffering technique, the circles are still there, but they look like very ugly. I would call that some "squarcles".
What is the bug here and how to get some decent double buffering with thoses circles?

Ok, i had some problem with the running thread when closing the applet viewer, but now this situation is corrected by setting the animation thread to null before calling stop().
Maybe explanation of the problem is not clear, so i made two versions of the same applet with only 2 lines of code different so that there is one applet that is not double buffered.
You can check these by yourself at this place:
Double buffered circles: http://www.geocities.com/xeneve/cooltrail/ demo_cooltrail.htm
No double buffer:
http://www.geocities.com/xeneve/cooltrail/demo_cooltrail_ndb.htm
This is just annoying to get this result. I realise that maybe not many peoples are coding applets so i guess there is few people that may have a workaround for this.

Similar Messages

  • Double buffering circle not round

    I am making an applet where some circles are painted to the screen. When not using the double buffering scenario, the shapes appear correctly.
    The problem is when i use the double-buffering technique, the circles are still there, but they look like very ugly. I would call that some "squarcles".
    What is the bug here and how to get some decent double buffering with thoses circles?

    Here is the code so far i have that is used for painting on the screen:
    // Declaration
    private BufferedImage ecran;
    private Graphics2D buffer_ecran;
    // Instantiation
    this.ecran = new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_ARGB);
    this.buffer_ecran = ecran.createGraphics();
    // In paint() method
    Graphics be = buffer_ecran;
      // Clean the surface
    be.setColor(Color.WHITE);
    be.fillRect(0, 0, getSize().width, getSize().height);
      // Draw the circles
    be.setColor(Color.RED);
    be.drawOval(x, y, ra, rb);
      // Output the buffer to the screen
    g.drawImage(ecran, 0, 0, this);I was previously using Image and changed to BufferedImage with the hope it would resolve the situation. I can't tell a significant change in image display.

  • Double escaping suddenly does not work anymore.

    Hello,
    We have WCF Data Service that is configured to use
    double escaping according to this article
    http://blogs.msdn.com/b/peter_qian/archive/2010/05/25/using-wcf-data-service-with-restricted-characrters-as-keys.aspx
    During a long time (a year or more) this solution worked well for us. And suddenly, a week ago, we found that on some our services (in cloud, in out of cloud)
    double escaping does not work anymore.
    For example, request to our service may looks like
    http://service-host/odata-service/ContentTreeNodes('ID-%257BFEE06CEE-F667-45A2-9014-394F4B7CD3B0%257D')/
    In sample above we have ID that without double escaping looks like ID-{FEE06CEE-F667-45A2-9014-394F4B7CD3B0}
    But when our service processes this request ID becomes like ID-%7BFEE06CEE-F667-45A2-9014-394F4B7CD3B0%7D.
    And that is means that .NET (WCF Data Services) infrastructure removes only single escaping and forget (ignore) to remove second one.
    We have an assumption that issue probably maybe caused by some Windows security update. Because on some PCs it works well.
    Does anybody have similar issues?

    Hi,
    I suppose you tried to uninstall this patch from Azure VM. If so then yes, it can not be done. Seems it prohibited by MS or at least I do not have answer how to do it.
    At the same time I had no such problems with out of cloud PCs.
    BWT, we recently found that we do not require double escaping anymore in our service, because single escaping now works well for us. Looks like MS fixed an issue regarding # symbol in URL path. Now if URL has # in some URL path (for example in entity ID),
    then single escaped # works well.

  • JNI native drawing - Double Buffering issue

    Hi,
    I use JNI to paint from a C++ DLL onto a canvas, which works fine.
    The problem is that double buffering is not working though.
    In C++ I create an offscreen HDC, draw something on it and finally i bitblit the offscreen HDC to the parent window HDC.
    That is how double buffering is supposed to work. But each time i repaint my Canvas in Java, i see flickering:
    the background color is displayed first, then the C++ paintings are drawn.
    Since i already do double buffering in my C++ drawings, i don't know why there still is flickering.
    Should i do double buffering on my canvas also?
    How would this work, since my paint method looks like;
         private native void drawChart(Graphics g);
         public void paint(Graphics g)
              drawChart(g);
         }

    this is my lucky day :)
    the following thread on http://forum.java.sun.com/thread.jspa?threadID=562392&messageID=2767046 suggested to override the update method on the canvas, which works.
         // overridden to eliminate flicker
        public void update(Graphics g)
            paint(g);
        }

  • So my Ipod touch hasn't been connecting to computer, or charging for a week or two until i turn it off completely and now i try to reset all content and setting, the circle goes round and round for like hrs(24) and it still does not complete the reset

    so my Ipod touch hasn't been connecting to computer, nor charging for a week or two until i turn it off completely and now i try to reset all content and setting,(thinking it may connect to the computer and itunes and also charge) but the circle goes round and round for like hrs(24) and it still does not complete the reset.
    pls pls pls pls help .
    i have tried alot of solutions, but non of them have worked.

    Have you tried walking it into the nearest Apple Store and asking for assistance there...?
    I'm guessing you don't have Apple Care on it.

  • Compile target 1.6 = JAR not executable anymore (double click)

    I made my JAR executable by adding "Main-Class:" and "Class-Path:" entries into the manifest file. This works great with Java 1.5 compiled code. But simple switching the compile target from "1.5" to "1.6", the generated JAR is not executable anymore and shows an error dialog instead:
    Java Virtual Machine Launcher
    Could not find the main class. Programm will exit.
    I create the JAR with an ANT script. Just toggling between target "1.5" and "1.6" forth and back results in an executable JAR (for target "1.5") or this error (for target "1.6").
    Strange: it works when I call the JAR from command line (java -jar myJar.jar), so the error above only occurs when double clicking. (Running on Windows 2000, JDK 1.6.0_03)
    I haven't found any notes about changes in the manifest file for target 1.6 compiled classes.

    PraveenKJain wrote:
    I have created a executable jar file of an swing desktop application, It is working fine if i use the command line (java -jar option) but when i try to execute it by double clicking its shows the error message (could not find the main class. program will exit).If this is a Windows icon, then I suspect the "Start in:" directory is wrong. Mind you, judging by the classpath, it doesn't look like whatever tool created your executable jar did a very good job.
    Winston

  • DAQEvent=2 not fired when double buffered operations stop

    Hi,
    I am using Config_DAQ_Event_Message with DAQEvent==2 to get an event when synchronous DAQ and WFM are finished. This works fine with single buffered operation, but i get no event in double buffered mode ?
    Especially I like to get an event in case of Buffer-Underrun etc. errors.
    My hardware: PCI6111
    Software: NIDAQ6.9.3 with VisualC++
    Thanks in advance
    Michael

    Hi Michael,
    One of the possible causes of this error-10608 is a high update rate. The update rate might be high enough that you are not allowing enough time to fill the buffer with new data. This error can also be the result of having the regeneration option, within software, set to OFF. If you turn the regeneration option to ON, the error will go away. You can also reduce the update rate to see at which point you stop getting the error -10608
    I found the following links about errorcode -10843:
    http://digital.ni.com/public.nsf/websearch/EC38736BBF430DDC8625677C006F395C?OpenDocument
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RNAME=ViewQuestion&HOID=506500000008000000CA780000&ECategory=Measurement+Hardware.Digital+I%2FO
    regards
    TN

  • My imac does not start anymore (stops at the screen with the apple and a rotating circle). An idea what I could try to make it start again?

    My Imac does not start anymore.
    ==> What I have already done:
    1) I tried with the tigger dvd to reinstall. It didn't succeed.
    2) Via the single mode, when starting I got the message "disk0s2: I/0 error" several times. After that I got "Root device is mounted read-only"
    3) Nevertheless, I tried the "fsck -yf" function. After checking "Journal HFS Plus volume", "extends overflow file", "catalog file"... and invalid record count
    ==> /dev/rdisk0s2 (hfs) EXITED WITH SIGNAL 8
    Can someone advices me? I red on the internet I could reformat the disk... loosing all the data I didn't backed up. How am I suppose to reformat?
    Thanks in advance,
    Fred

    Reset the SMC: http://support.apple.com/kb/HT3964
    Reset the PRAM: http://docs.info.apple.com/article.html?path=Mac/10.6/en/26871.html
    Restart the computer while holding down your mouse button which if you hold it down long enough (5 minutes at most) should eject the disk
    If the disk still doesn't come out at that point then you need hardware evaluation;
    contact Apple, contact an Apple Authorized Service Provider, or make an appointment with an Apple Retail Store.

  • How to draw a point without double buffering?

    Hello all,
    I am drawing points as small red circles, but they are a bit ugly without double buffering. Am I able to draw the points to be nice? I mean not to draw them as just circles, but some special circle with light border that will looks much more nicer?
    Or what radius and position of the circle must be to be a nice small circle containing only 5 pixels? (upper, lower, right, left, middle)
    ps - they are ugly in the way of having a strange dot on the left side

    I use this method:
        private static final float POINT_RADIUS = 2f;
        private static final float POINT_DIAMETER = POINT_RADIUS * 2;
    private void drawPoint(float x, float y, Color c) {
            Ellipse2D point = new Ellipse2D.Float(x - POINT_RADIUS, -y
                    - POINT_RADIUS, POINT_DIAMETER, POINT_DIAMETER);
            graphics.setStroke(new BasicStroke(0.2f));
            graphics.fill(point);
    // and points looks like this:
       ***

  • Can Flash create dashed line with blunt not rounded dashes ?

    Hi,
    using Flash8
    I can select line tool and dashed line in properties and draw a dashed line and get a line of sausages. How do I get a line of dashes without rounded ends to each dash ?
    Line option has end caps option with None (gives straight or blunt tip to line, round gives rounded tip .
    Draw a line with None and its got blunt ends, select it and choose dashed line option and it gets round ends to the dashes, the end cap option is greyed out !
    Are dashed lines with blunt dashes now possible again with CS4, a forum poster also found that CS3 no longer gave blunt dashes ?
    Why do I ask:-
    I am trying to bring a map into Flash8 from Illustrator (Illus version 10 as it allows blunt tip lines to remain blunt it was said on the forum)... which has blunt ends to roads and has blunt type dashed lines. The roads remain blunt..GOOD !..but the dashed lines become what looks like a solid line. BAD !
    I do a right click - break apart,  then double click one of those now solid lines that should be dashed, and I am able to select a portion of the line, it is no longer a continual line as drawn in Illustrator. Properties shows it as solid line. Flash8 obviously having a problem with supporting Illustrator 10 dashed line then !
    Select dashed in properties box and I get a portion of the line as sausage dashes, but working my way along the line doing each bit sees a far from correct dashed line result as sausages dont start stop evenly as each line is a separate entity and ignores the previous line.
    Looks like I shall have to try and draw the line as one long line again in flash but unless I can give it blunt dashes when done, there is no point even trying that method, hence my question.
    Would the latest Illustrator and Flash versions (CS4) allow blunt type dashed lines to appear in Flash ?
    This is crucial for bringing maps into Flash.
    Envirographics

    I noticed one problem with my solution.
    If you look, very carefully, at the end of the stream, it's flat. Not rounded like it should be. After a bit of trial and error, I tried a different brush:
    Note that, in addition to the rounded rectangle (done with the new corner controls in the latest version of Illustrator CC that just came out) and the three circles, there is also a rectangle, with no stroke and no fill, to provide a space at the end of the three dots. Here is the result:

  • Double buffering && repaint

    Hi there,
    I have a frame F that contains two panels P1 and P2.
    P1 uses double buffering for drawing circles and lines.
    P2 has buttons and a JList.
    When i click on a JList to have popup menu
    or when i move the frame F on the screen
    the panel P2 lost some of JList drawing.
    Actually i iconify the frame in order to oblige
    JVM to do repaint.
    How can i resolve this problem please.

    Do not ever mix heavyweight and lightweight, or else
    you won't be able to set up the correct zorder.But when i iconfiy and desiconify my frame Java
    repaint correctly.
    I need a nice tip article of how to simulate
    desiconify repainting process.
    Thabk u

  • "Class Circle not found in TryBouncingBalls" error message. Help !

    Dear People,
    I have an error message :
    "TryBouncingBalls.java": Error : class Circle not found in class stan_bluej_ch5_p135.TryBouncingBalls at line 67, "
    Circle circle = new Circle(xPos + 130, 30);
    below are the classes TryBouncingBalls, BouncingBall, BallDemo, Canvas
    Thank you in advance
    Stan
    package stan_bluej_ch5_p135;
    import java.awt.*;
    import java.awt.geom.*;
    public class TryBouncingBalls
    public static void main(String[] args)
    Canvas myCanvas = new Canvas("Creativity at its best");
    myCanvas.setVisible(true);
    BouncingBall ball = new BouncingBall(50,50,16, Color.red, 500, myCanvas);
    BouncingBall ball2 = new BouncingBall(70,80,20, Color.green, 500, myCanvas);
    BouncingBall ball3 = new BouncingBall(90,100,16, Color.red, 500, myCanvas);
    BouncingBall ball4 = new BouncingBall(30,30,20, Color.green, 500, myCanvas);
    ball.draw();
    ball2.draw();
    ball.draw();
    ball2.draw();
    // make them bounce
    boolean finished = false;
    while(!finished) {
    myCanvas.wait(50); // small delay
    ball.move();
    ball2.move();
    ball3.move();
    ball4.move();
    // stop once ball has travelled a certain distance on x axis
    if(ball.getXPosition() >= 550 && ball2.getXPosition() >= 550)
    finished = true;
    myCanvas.setFont(new Font("helvetica", Font.BOLD, 14));
    myCanvas.setForegroundColor(Color.red);
    myCanvas.drawString("We are having fun, ...\n\n", 20, 30);
    myCanvas.wait(1000);
    myCanvas.setForegroundColor(Color.black);
    myCanvas.drawString("...drawing lines...", 60, 60);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.gray);
    myCanvas.drawLine(200, 20, 300, 50);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.blue);
    myCanvas.drawLine(220, 100, 370, 40);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.green);
    myCanvas.drawLine(290, 10, 320, 120);
    myCanvas.wait(1000);
    myCanvas.setForegroundColor(Color.gray);
    myCanvas.drawString("...and shapes!", 110, 90);
    myCanvas.setForegroundColor(Color.red);
    myCanvas.drawString("to bring to focus creative ideas !", 310, 290);
    // the shape to draw and move
    int xPos = 10;
    Rectangle rect = new Rectangle(xPos + 40, 150, 30, 20);
    Rectangle rect2 = new Rectangle(xPos + 80, 120, 50, 25);
    Rectangle rect3 = new Rectangle(xPos+ 1200, 180, 30, 30);
    Rectangle rect4 = new Rectangle(xPos + 150, 220, 40, 15);
    myCanvas.fill(rect);
    myCanvas.fill(rect2);
    myCanvas.fill(rect3);
    myCanvas.fill(rect4);
    Circle circle = new Circle(xPos + 130, 30);
    // Circle circle2 = new Circle(xPos + 150, 50);
    // Circle circle3 = new Circle(xPos + 170, 30);
    // Circle circle4 = new Circle(xPos + 200, 40);
    // myCanvas.fill(circle);
    // myCanvas.fill(circle2);
    // myCanvas.fill(circle3);
    // myCanvas.fill(circle4);
    // move the rectangle and circles across the screen
    for(int i = 0; i < 200; i ++) {
    myCanvas.fill(rect);
    myCanvas.fill(rect2);
    myCanvas.fill(rect3);
    myCanvas.fill(rect4);
    myCanvas.wait(10);
    myCanvas.erase(rect);
    myCanvas.erase(rect2);
    myCanvas.erase(rect3);
    myCanvas.erase(rect4);
    xPos++;
    rect.setLocation(xPos, 150);
    rect2.setLocation(xPos, 120);
    rect3.setLocation(xPos, 180);
    rect4.setLocation(xPos, 220);
    // at the end of the move, draw once more so that it remains visible
    myCanvas.fill(rect);
    myCanvas.fill(rect2);
    myCanvas.fill(rect3);
    myCanvas.fill(rect4);
    package stan_bluej_ch5_p135;
    import java.awt.*;
    import java.awt.geom.*;
    * Class BouncingBall - a graphical ball that observes the effect of gravity. The ball
    * has the ability to move. Details of movement are determined by the ball itself. It
    * will fall downwards, accelerating with time due to the effect of gravity, and bounce
    * upward again when hitting the ground.
    * This movement can be initiated by repeated calls to the "move" method.
    * @author Bruce Quig
    * @author Michael Kolling (mik)
    * @author David J. Barnes
    * @version 1.1 (23-Jan-2002)
    public class BouncingBall
    private static final int gravity = 3; // effect of gravity
    private int ballDegradation = 2;
    private Ellipse2D.Double circle;
    private Color color;
    private int diameter;
    private int xPosition;
    private int yPosition;
    private final int groundPosition; // y position of ground
    private Canvas canvas;
    private int ySpeed = 1; // initial downward speed
    * Constructor for objects of class BouncingBall
    * @param xPos the horizontal coordinate of the ball
    * @param yPos the vertical coordinate of the ball
    * @param ballDiameter the diameter (in pixels) of the ball
    * @param ballColor the color of the ball
    * @param groundPos the position of the ground (where the wall will bounce)
    * @param drawingCanvas the canvas to draw this ball on
    public BouncingBall(int xPos, int yPos, int ballDiameter, Color ballColor,
    int groundPos, Canvas drawingCanvas)
    xPosition = xPos;
    yPosition = yPos;
    color = ballColor;
    diameter = ballDiameter;
    groundPosition = groundPos;
    canvas = drawingCanvas;
    * Draw this ball at its current position onto the canvas.
    public void draw()
    canvas.setForegroundColor(color);
    canvas.fillCircle(xPosition, yPosition, diameter);
    * Erase this ball at its current position.
    public void erase()
    canvas.eraseCircle(xPosition, yPosition, diameter);
    * Move this ball according to its position and speed and redraw.
    public void move()
    // remove from canvas at the current position
    erase();
    // compute new position
    ySpeed += gravity;
    yPosition += ySpeed;
    xPosition +=2;
    // check if it has hit the ground
    if(yPosition >= (groundPosition - diameter) && ySpeed > 0) {
    yPosition = (int)(groundPosition - diameter);
    ySpeed = -ySpeed + ballDegradation;
    // draw again at new position
    draw();
    * return the horizontal position of this ball
    public int getXPosition()
    return xPosition;
    * return the vertical position of this ball
    public int getYPosition()
    return yPosition;
    package stan_bluej_ch5_p135;
    import java.awt.*;
    import java.awt.geom.*;
    * Class BallDemo - provides two short demonstrations showing how to use the
    * Canvas class.
    * @author Michael Kolling and David J. Barnes
    * @version 1.0 (23-Jan-2002)
    public class BallDemo
    private Canvas myCanvas;
    * Create a BallDemo object. Creates a fresh canvas and makes it visible.
    public BallDemo()
    myCanvas = new Canvas("Ball Demo", 600, 500);
    myCanvas.setVisible(true);
    * This method demonstrates some of the drawing operations that are
    * available on a Canvas object.
    public void drawDemo()
    myCanvas.setFont(new Font("helvetica", Font.BOLD, 14));
    myCanvas.setForegroundColor(Color.red);
    myCanvas.drawString("We can draw text, ...", 20, 30);
    myCanvas.wait(1000);
    myCanvas.setForegroundColor(Color.black);
    myCanvas.drawString("...draw lines...", 60, 60);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.gray);
    myCanvas.drawLine(200, 20, 300, 50);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.blue);
    myCanvas.drawLine(220, 100, 370, 40);
    myCanvas.wait(500);
    myCanvas.setForegroundColor(Color.green);
    myCanvas.drawLine(290, 10, 320, 120);
    myCanvas.wait(1000);
    myCanvas.setForegroundColor(Color.gray);
    myCanvas.drawString("...and shapes!", 110, 90);
    myCanvas.setForegroundColor(Color.red);
    // the shape to draw and move
    int xPos = 10;
    Rectangle rect = new Rectangle(xPos, 150, 30, 20);
    // move the rectangle across the screen
    for(int i = 0; i < 200; i ++) {
    myCanvas.fill(rect);
    myCanvas.wait(10);
    myCanvas.erase(rect);
    xPos++;
    rect.setLocation(xPos, 150);
    // at the end of the move, draw once more so that it remains visible
    myCanvas.fill(rect);
    * Simulates two bouncing balls
    public void bounce()
    int ground = 400; // position of the ground line
    myCanvas.setVisible(true);
    // draw the ground
    myCanvas.drawLine(50, ground, 550, ground);
    // crate and show the balls
    BouncingBall ball = new BouncingBall(50, 50, 16, Color.blue, ground, myCanvas);
    ball.draw();
    BouncingBall ball2 = new BouncingBall(70, 80, 20, Color.red, ground, myCanvas);
    ball2.draw();
    // make them bounce
    boolean finished = false;
    while(!finished) {
    myCanvas.wait(50); // small delay
    ball.move();
    ball2.move();
    // stop once ball has travelled a certain distance on x axis
    if(ball.getXPosition() >= 550 && ball2.getXPosition() >= 550)
    finished = true;
    ball.erase();
    ball2.erase();
    package stan_bluej_ch5_p135;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.*;
    * Class Canvas - a class to allow for simple graphical
    * drawing on a canvas.
    * @author Michael Kolling (mik)
    * @author Bruce Quig
    * @version 1.8 (23.01.2002)
    public class Canvas
    private JFrame frame;
    private CanvasPane canvas;
    private Graphics2D graphic;
    private Color backgroundColor;
    private Image canvasImage;
    * Create a Canvas with default height, width and background color
    * (300, 300, white).
    * @param title title to appear in Canvas Frame
    public Canvas(String title)
    this(title, 600, 600, Color.white);
    * Create a Canvas with default background color (white).
    * @param title title to appear in Canvas Frame
    * @param width the desired width for the canvas
    * @param height the desired height for the canvas
    public Canvas(String title, int width, int height)
    this(title, width, height, Color.white);
    * Create a Canvas.
    * @param title title to appear in Canvas Frame
    * @param width the desired width for the canvas
    * @param height the desired height for the canvas
    * @param bgClour the desired background color of the canvas
    public Canvas(String title, int width, int height, Color bgColor)
    frame = new JFrame();
    canvas = new CanvasPane();
    frame.setContentPane(canvas);
    frame.setTitle(title);
    canvas.setPreferredSize(new Dimension(width, height));
    backgroundColor = bgColor;
    frame.pack();
    * Set the canvas visibility and brings canvas to the front of screen
    * when made visible. This method can also be used to bring an already
    * visible canvas to the front of other windows.
    * @param visible boolean value representing the desired visibility of
    * the canvas (true or false)
    public void setVisible(boolean visible)
    if(graphic == null) {
    // first time: instantiate the offscreen image and fill it with
    // the background color
    Dimension size = canvas.getSize();
    canvasImage = canvas.createImage(size.width, size.height);
    graphic = (Graphics2D)canvasImage.getGraphics();
    graphic.setColor(backgroundColor);
    graphic.fillRect(0, 0, size.width, size.height);
    graphic.setColor(Color.black);
    frame.show();
    * Provide information on visibility of the Canvas.
    * @return true if canvas is visible, false otherwise
    public boolean isVisible()
    return frame.isVisible();
    * Draw the outline of a given shape onto the canvas.
    * @param shape the shape object to be drawn on the canvas
    public void draw(Shape shape)
    graphic.draw(shape);
    canvas.repaint();
    * Fill the internal dimensions of a given shape with the current
    * foreground color of the canvas.
    * @param shape the shape object to be filled
    public void fill(Shape shape)
    graphic.fill(shape);
    canvas.repaint();
    * Fill the internal dimensions of the given circle with the current
    * foreground color of the canvas.
    public void fillCircle(int xPos, int yPos, int diameter)
    Ellipse2D.Double circle = new Ellipse2D.Double(xPos, yPos, diameter, diameter);
    fill(circle);
    * Fill the internal dimensions of the given rectangle with the current
    * foreground color of the canvas. This is a convenience method. A similar
    * effect can be achieved with the "fill" method.
    public void fillRectangle(int xPos, int yPos, int width, int height)
    fill(new Rectangle(xPos, yPos, width, height));
    * Erase the whole canvas.
    public void erase()
    Color original = graphic.getColor();
    graphic.setColor(backgroundColor);
    Dimension size = canvas.getSize();
    graphic.fill(new Rectangle(0, 0, size.width, size.height));
    graphic.setColor(original);
    canvas.repaint();
    * Erase the internal dimensions of the given circle. This is a
    * convenience method. A similar effect can be achieved with
    * the "erase" method.
    public void eraseCircle(int xPos, int yPos, int diameter)
    Ellipse2D.Double circle = new Ellipse2D.Double(xPos, yPos, diameter, diameter);
    erase(circle);
    * Erase the internal dimensions of the given rectangle. This is a
    * convenience method. A similar effect can be achieved with
    * the "erase" method.
    public void eraseRectangle(int xPos, int yPos, int width, int height)
    erase(new Rectangle(xPos, yPos, width, height));
    * Erase a given shape's interior on the screen.
    * @param shape the shape object to be erased
    public void erase(Shape shape)
    Color original = graphic.getColor();
    graphic.setColor(backgroundColor);
    graphic.fill(shape); // erase by filling background color
    graphic.setColor(original);
    canvas.repaint();
    * Erases a given shape's outline on the screen.
    * @param shape the shape object to be erased
    public void eraseOutline(Shape shape)
    Color original = graphic.getColor();
    graphic.setColor(backgroundColor);
    graphic.draw(shape); // erase by drawing background color
    graphic.setColor(original);
    canvas.repaint();
    * Draws an image onto the canvas.
    * @param image the Image object to be displayed
    * @param x x co-ordinate for Image placement
    * @param y y co-ordinate for Image placement
    * @return returns boolean value representing whether the image was
    * completely loaded
    public boolean drawImage(Image image, int x, int y)
    boolean result = graphic.drawImage(image, x, y, null);
    canvas.repaint();
    return result;
    * Draws a String on the Canvas.
    * @param text the String to be displayed
    * @param x x co-ordinate for text placement
    * @param y y co-ordinate for text placement
    public void drawString(String text, int x, int y)
    graphic.drawString(text, x, y);
    canvas.repaint();
    * Erases a String on the Canvas.
    * @param text the String to be displayed
    * @param x x co-ordinate for text placement
    * @param y y co-ordinate for text placement
    public void eraseString(String text, int x, int y)
    Color original = graphic.getColor();
    graphic.setColor(backgroundColor);
    graphic.drawString(text, x, y);
    graphic.setColor(original);
    canvas.repaint();
    * Draws a line on the Canvas.
    * @param x1 x co-ordinate of start of line
    * @param y1 y co-ordinate of start of line
    * @param x2 x co-ordinate of end of line
    * @param y2 y co-ordinate of end of line
    public void drawLine(int x1, int y1, int x2, int y2)
    graphic.drawLine(x1, y1, x2, y2);
    canvas.repaint();
    * Sets the foreground color of the Canvas.
    * @param newColor the new color for the foreground of the Canvas
    public void setForegroundColor(Color blue)
    graphic.setColor(Color.blue);
    * Returns the current color of the foreground.
    * @return the color of the foreground of the Canvas
    public Color getForegroundColor()
    return graphic.getColor();
    * Sets the background color of the Canvas.
    * @param newColor the new color for the background of the Canvas
    public void setBackgroundColor(Color newColor)
    backgroundColor = newColor;
    graphic.setBackground(newColor);
    * Returns the current color of the background
    * @return the color of the background of the Canvas
    public Color getBackgroundColor()
    return backgroundColor;
    * changes the current Font used on the Canvas
    * @param newFont new font to be used for String output
    public void setFont(Font newFont)
    graphic.setFont(newFont);
    * Returns the current font of the canvas.
    * @return the font currently in use
    public Font getFont()
    return graphic.getFont();
    * Sets the size of the canvas.
    * @param width new width
    * @param height new height
    public void setSize(int width, int height)
    canvas.setPreferredSize(new Dimension(width, height));
    Image oldImage = canvasImage;
    canvasImage = canvas.createImage(width, height);
    graphic = (Graphics2D)canvasImage.getGraphics();
    graphic.drawImage(oldImage, 0, 0, null);
    frame.pack();
    * Returns the size of the canvas.
    * @return The current dimension of the canvas
    public Dimension getSize()
    return canvas.getSize();
    * Waits for a specified number of milliseconds before finishing.
    * This provides an easy way to specify a small delay which can be
    * used when producing animations.
    * @param milliseconds the number
    public void wait(int milliseconds)
    try
    Thread.sleep(milliseconds);
    catch (InterruptedException e)
    // ignoring exception at the moment
    * Nested class CanvasPane - the actual canvas component contained in the
    * Canvas frame. This is essentially a JPanel with added capability to
    * refresh the image drawn on it.
    private class CanvasPane extends JPanel
    public void paint(Graphics g)
    g.drawImage(canvasImage, 0, 0, null);

    Dear Miciuli,
    I found the definition for the circle in the canvas class and used it to creates circles ! Thank you for jaring my brain into thinking !
    Stan
    Ellipse2D.Double circle = new Ellipse2D.Double(xPos, 70, 30 , 30);

  • Problem with Double Buffering and Swing

    Hi
    I made a game and basically it works pretty well, my only problem is it flickers really badly right now. I read up on a whole lot of forums about double buffering and none of those methods seemed to work. Then I noticed that Swing has double buffering built in so I tried that but then I get compilation errors and I'm really not sure why. My original code was a console application and worked perfectly, then I ported it into a JApplet and it still works but it flickers and thats what I'm tryign to fix now.
    The code below is in my main class under the constructor.
    Heres the double buffering code I'm trying to use, I'm sure you all seen it before lol
    public void update(Graphics g)
              // initialize buffer
              if (dbImage == null)
                   dbImage = createImage(this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics();
              // clear screen in background
              dbg.setColor(getBackground());
              dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
              // draw elements in background
              dbg.setColor(getForeground());
              paint(dbg);
              // draw image on the screen
              g.drawImage(dbImage, 0, 0, this);
         }My paint is right under neath and heres how it looks
    This snipet of code works but when I change the method to
    public paintComponent(Graphics g){
    super.paintComponent(g)...
    everythign stops working and get a compilation error and says that it can't find paintComponent in javax.swing.JFrame.
    public void paint(Graphics g)
              super.paint(g);
              //if game starting display menue
              if (show_menue)
                   //to restart lives if player dies
                   lives = 3;
                   menue.draw_menue(g);
                   menue_ufo1.draw_shape(g);
                   menue_ufo2.shape_color = Color.DARK_GRAY;
                   menue_ufo2.draw_shape(g);
                   menue_ufo3.shape_color = Color.BLUE;
                   menue_ufo3.draw_shape(g);
                   menue_ufo4.shape_color = new Color(82, 157, 22);
                   menue_ufo4.draw_shape(g);
                   menue_ufo5.draw_shape(g);
                   menue_ufo6.shape_color = new Color(130, 3, 3); ;
                   menue_ufo6.draw_shape(g);
                   menue_turret.draw_ship(g);
                   menue_ammo.draw_ammo(g);
              else
                   //otherwise redraw game objects
                   gunner.draw_ship(g);
                   y_ammo.draw_ammo(g);
                   grass.draw_bar(g);
                   o_ufo.draw_shape(g);
                   b_ufo.draw_shape(g);
                   m_ufo.draw_shape(g);
                   s_ufo.draw_shape(g);
                   z_ufo.draw_shape(g);
                   xx_ufo.draw_shape(g);
                   info.draw_bar(g);
                   live_painter.draw_lives(g, lives);
                   score_painter.draw_score(g, score);
                   level_display.draw_level(g, level);
                   explosion.draw_boom(g);
         }I just want to get rid of the flickering for now so any help will be greatly appreciated. Depending which will be simpler I can either try to double buffer this program or port it all to swing but I'm not sure which elements are effected by AWT and which by Swing. Also I read some of the Java documentation but couldn't really understand how to implement it to fix my program.
    Thanks in advance
    Sebastian

    This is a simple animation example quickly thrown together. I have two classes, an animation panel which is a JPanel subclass that overrides paintComponent and draws the animation, and a JApplet subclass that simply holds the animation panel in the applet's contentpane:
    SimpleAnimationPanel.java
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    class SimpleAnimationPanel extends JPanel
        private static final int DELAY = 20;
        public static final int X_TRANSLATION = 2;
        public static final int Y_TRANSLATION = 2;
        private Point point = new Point(5, 32);
        private BufferedImage duke = null;
        private Timer timer = new Timer(DELAY, new TimerAction());
        public SimpleAnimationPanel()
            try
                // borrow an image from sun.com
                duke = ImageIO.read(new URL(
                        "http://java.sun.com/products/plugin/images/duke.wave.med.gif"));
            catch (MalformedURLException e)
                e.printStackTrace();
            catch (IOException e)
                e.printStackTrace();
            setPreferredSize(new Dimension(600, 400));
            timer.start();
        // do our drawing here in the paintComponent override
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            if (duke != null)
                g.drawImage(duke, point.x, point.y, this);
        private class TimerAction implements ActionListener
            @Override
            public void actionPerformed(ActionEvent e)
                int x = point.x;
                int y = point.y;
                Dimension size = SimpleAnimationPanel.this.getSize();
                if (x > size.width)
                    x = 0;
                else
                    x += X_TRANSLATION;
                if (y > size.height)
                    y = 0;
                else
                    y += Y_TRANSLATION;
                point.setLocation(new Point(x, y)); // update the point
                SimpleAnimationPanel.this.repaint();
    }AnimationApplet.java
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class AnimationApplet extends JApplet
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    public void run()
                        // construct the panel
                        JPanel simpleAnimation = new SimpleAnimationPanel();
                        // put it in the contentPane of the JApplet
                        getContentPane().add(simpleAnimation);
                        setSize(simpleAnimation.getPreferredSize());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }Here's a 3rd bonus class that shows how to put the JPanel into a stand-alone program, a JFrame. It's very similar to doing it in the JApplet:
    AnimationFrame.java
    import javax.swing.JFrame;
    public class AnimationFrame
        private static void createAndShowUI()
            JFrame frame = new JFrame("SimpleAnimationPanel");
            frame.getContentPane().add(new SimpleAnimationPanel());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }Edited by: Encephalopathic on Mar 15, 2008 11:01 PM

  • Hp laserjet 100 color mfp m175nw not working anymore – MAC OSX YOSEMITE

    After installing the YOSEMITE update my hp laserjet 100 color mfp m175nw not printing anymore. Connection is USB. And OSX Drivers are all up-to-dae. Also i heared similar problems with other printers than HP.
    Any help? Thanks alot.

    Hi @Ankanb ,
    I understand that you are having issues since the Apple Security Update was done on the computer, after  uninstalling and reinstalling the software, you can't find the printer now.  I would be happy to help you.
    I have provided some steps to try, to see if we get the printer working again over the network.
    Print a Configuration page to see if the printer still has a valid IPv4 address.
    Printing a Configuration Report.
    If you have a valid IPv4 address for the printer then try and access the Embedded Web Server for the printer.
    Type the IP address into your web browser's address bar. (Safari)
    Did it load the webpage?
    Repair the Disk Permissions on the Mac:
    Close all applications.
    On the Apple menu bar, click Go, click Applications and then click Utilities.
    Double-click Disk Utility.
    Highlight your hard drive/partition on the left.
    Click Verify and then Repair Disk Permissions.
    Restart the computer..
    Reset the Printing System:
    Note: This will remove all printers in the print and Fax/Scan, any printer removed can be re-added later by clicking the plus (+) symbol.
    Click the Apple icon and then click System Preferences.
    Click Printers & Scanners.
    Right-click (or Ctrl +click) in the left white side panel, then click Reset printing system.
    Click OK to confirm the reset.
    Type the correct Name and Password.
    Click OK to reset the printing system.
    Then click the + sign to add the driver, highlight the printer. (you might have to click the drop down to select the printer's name) Then click on the Add button.
    If you are having network issues, then add the printer through the IP Protocol.
    After clicking the + button, select the IP icon across the top, type in the printer's IP address, select jet direct below and then Apply. (you won't be able to scan but you will be able to print, this way we will know if it is a Multicasting issue, if the Mac sees the printer)
    If the Multicasting is turned off on the router, you won't be able to add the printer as a bonjour device.
    Test the printer.
    How is the printer connected?  (Ethernet/Wireless)
    If there is anything else I can help you with, just let me know.
    Have a nice weekend!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • To double buffer or not double buffer..that is the question

    i am not very familiar with double buffering but am reading examples
    of it now. Im not doing animaiton and i dont think im doing alot of
    drawing to the screen but im arookie so its hard to tell. Can you tell
    me if i should implement double buffering by looking at my code. Im
    wondering cuz my webpage is a mess.(http://ktowndrivewaysealing.tripod.com).
    i have trailing components and flickering and i dont know how to fix it.
    thanx
    trin
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.*;
    public class MyProg extends Applet implements ActionListener
         Button btnOne = new Button("Home");
         Button btnTwo = new Button("Asphalt Sealing");
         Button btnThree = new Button("Crack Repairs");
         Button btnFour = new Button("Pressure Washing");
         Button btnFive = new Button("Free Estimates");
         Button btnSix = new Button("Contact Us");
         Font font1= new Font ( "TimesNewRoman",Font.BOLD,12);     
         Font font2=new Font("TimesNewRoman", Font.BOLD, 35);
         Font font3=new Font("TimesNewRoman", Font.BOLD, 25);
         Font font4=new Font("TimesNewRoman",Font.BOLD,20);
         Font font5=new Font("Dialog", Font.BOLD+Font.ITALIC, 16);
         Label title1=new Label("KINGSTON", Label.CENTER);
         Label title2 = new Label("Driveway Sealing", Label.CENTER);
         Label title3=new Label("613-531-3369", Label.CENTER);
         Label caption1=new Label("Your driveway is the first impression your home makes...", Label.CENTER);
         Label caption2=new Label("Make it a Good one.", Label.CENTER);
         Image drivewaypic1;
         Image drivewaypic2;
         URL homeUrl;
         URL asphaltUrl;
         URL crackUrl;
         URL pressureUrl;
         URL freeUrl;
         URL contactUrl;
         public void init()
              setLayout(null);
               try
                   homeUrl = new URL(getCodeBase(),"Home.html");
                   asphaltUrl=new URL(getCodeBase(),"AsphaltHtml.html");
                   crackUrl= new URL(getCodeBase(),"CrackHtml.html");
                   pressureUrl=new URL(getCodeBase(),"PressureHtml.html");
                   freeUrl= new URL(getCodeBase(),"FreeHtml.html");
                   contactUrl= new URL(getCodeBase(),"ContactUsHtml.html");
              catch (MalformedURLException e)
                    return;//maybe i should leave blank..will test later
              drivewaypic1=getImage(getCodeBase(),"drivewaypic1.jpg");
              drivewaypic2=getImage(getCodeBase(),"drivewaypic2.jpg");
              add(btnOne);
              add(btnTwo);
              add(btnThree);
              add(btnFour);
              add(btnFive);
              add(btnSix);
              add(title1);
              add(title2);
              add(title3);
              add(caption1);
              add(caption2);
              btnOne.setFont(font1);
              btnOne.setBounds(15,159,120,40);
              btnOne.setBackground(Color.black);
              btnOne.setForeground(Color.white);
              btnTwo.setFont(font1);
              btnTwo.setBounds(15,199,120,40);
              btnTwo.setBackground(Color.black);
              btnTwo.setForeground(Color.white);
              btnThree.setFont(font1);
              btnThree.setBounds(15,239,120,40);
              btnThree.setBackground(Color.black);
              btnThree.setForeground(Color.white);
              btnFour.setFont(font1);
              btnFour.setBounds(15,279,120,40);
              btnFour.setBackground(Color.black);
              btnFour.setForeground(Color.white);
              btnFive.setFont(font1);
              btnFive.setBounds(15,319,120,40);
              btnFive.setBackground(Color.black);
              btnFive.setForeground(Color.white);
              btnSix.setFont(font1);
              btnSix.setBounds(15,359,120,40);
              btnSix.setBackground(Color.black);
              btnSix.setForeground(Color.white);
              title1.setBounds(5,5,585,33);
              title1.setBackground(Color.lightGray);
              title1.setForeground(Color.black);
              title1.setFont(font3);
              title2.setBounds(5,39,590,36);
              title2.setBackground(Color.black);
              title2.setForeground(Color.white);
              title2.setFont(font2);
              title3.setBounds(5,75,590,30);
              title3.setBackground(Color.lightGray);
              title3.setForeground(Color.black);
              title3.setFont(font4);
              caption1.setBounds(163,113,450,23);
              caption1.setFont(font5);
              caption1.setBackground(Color.lightGray);
              caption1.setForeground(Color.blue);
              caption2.setBounds(163,134,446,23);
              caption2.setFont(font5);
              caption2.setBackground(Color.lightGray);
              caption2.setForeground(Color.blue);
              btnOne.addActionListener(this);
              btnTwo.addActionListener(this);
              btnThree.addActionListener(this);
              btnFour.addActionListener(this);
              btnFive.addActionListener(this);
              btnSix.addActionListener(this);
              btnOne.setActionCommand("Home");
              btnTwo.setActionCommand("Asphalt Sealing");
              btnThree.setActionCommand("Crack Repairs");
              btnFour.setActionCommand("Pressure Washing");
              btnFive.setActionCommand("Free Estimates");
              btnSix.setActionCommand("Contact Us");
         public void actionPerformed (ActionEvent e)
              String s=e.getActionCommand();
              if (s.equals("Home"))
                   getAppletContext().showDocument(homeUrl);
              if (s.equals("Asphalt Sealing"))
                   getAppletContext().showDocument(asphaltUrl);
              if (s.equals("Crack Repairs"))
                   getAppletContext().showDocument(crackUrl);
              if (s.equals("Pressure Washing"))
                   getAppletContext().showDocument(pressureUrl);
              if (s.equals("Free Estimates"))
                   getAppletContext().showDocument(freeUrl);
              if (s.equals("Contact Us"))
                   getAppletContext().showDocument(contactUrl);
         public void paint(Graphics g)
              super.paint(g);
              g.setColor(Color.lightGray);
              g.fillRect(1,1,600,600);
              //g.fillRect(1,1,147,650);
              g.setColor(Color.black);
              g.drawRoundRect(1,1,595,105,10,10);     
              g.drawRoundRect(2,2,593,103,10,10);     
              g.drawRoundRect(3,3,591,101,10,10);     
              g.drawRoundRect(4,4,589,99,10,10);
              g.drawImage(drivewaypic1,170,159,375,225,this);     
              g.drawImage(drivewaypic2,170,386,375,225,this);
              g.drawRoundRect(1,110,150,495,10,10);
              g.drawRoundRect(2,111,148,493,10,10);
              g.drawRoundRect(3,112,146,491,10,10);
              g.drawRoundRect(4,113,144,489,10,10);
         

    It seems you aren't using any animation in this applet, so you won't have to use double buffering... :)

Maybe you are looking for

  • Awesome systray is not showing all icons, perhaps overlapping widgets?

    I have a problem with my Awesome configuration that results in some of the icons being missing or partially missing from my systray. I suspect this is because of some overlapping, since they are partially hidden. You can see the problem in the top ri

  • My MacBook no longer recognizes its own screen!

    Recently I started using an external monitor along with my MacBook's screen in order to have a larger canvas to work with. Recently the internal monitor on the macbook stopped working, even when I unplug the external monitor and reset it. Occasionall

  • Macbook pro and airplay

    Hi I have a macbook pro 15 (late 2011) and a 3rd generation apple tv. According to this I should be able to get mirroring from my mac to tv - but I can't, there are no options is display settings for anything to do with airplay. Can anyone help? Soft

  • Can we detrmine Credit Check at delivery or billing level

    Hi Can we determine Credit Check at delivery or billing level other than at Sales Order level? If yes,what settings need to be done in IMG?

  • Info Record Vs Master Record Price

    Hi, I would like to know why in the project builder appears de master record price of a component instead of the price of the purchase requisition (info record price)? If I manually introduce the Info Record the price will be updated but would be pos