Note that there are some explanatory texts on larger screens.

plurals
  1. POJava 2D object repeatition
    primarykey
    data
    text
    <p>I built a Java 2d circle using the Java <code>g.drawstring()</code> methods and using the Breseham's Circle algorithm and I used it to draw a smiley but when I move the smiley it repeats all over the screen I know for sure that the <code>PaintComponent(Graphics g)</code> Method keeps re-drawing the simley at different location specified but how to correct this logic error is my problem. Here are the codes i wrote.</p> <pre><code>public class Midsemester extends JPanel implements ActionListener { // objects class static Movement move = new Movement(); public int x = 0, y = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0; private int inix = 0, iniy = 0; static String[] st = {"xy","x1y1","x2y2","x3y3","x4y4"}; static shapes shaper = new shapes();//object class contain the algorithms used to draw the circles using the Breseham's Circle algorithm public Midsemester() { } /****/ @Override public void paintComponent(Graphics g) { super.paintComponents(g); x = (int)move.x; y = (int)move.y; x1 = (int)move.x1; y1 = (int)move.y1; x2 = (int)move.x2; y2 = (int)move.y2; x3 = (int)move.x3; y3 = (int)move.y3; x4 = (int)move.x4; y4 = (int)move.y4; shaper.draw_floor(100, 350, 1350, g); shaper.draw_wall(100, 0, 350, g); shaper.create(x,y,50,g, Color.yellow);//creates the smileys in there different colors shaper.create(x1,y1,50,g, Color.BLUE); shaper.create(x2,y2,50,g, Color.pink); shaper.create(x3,y3,50,g, Color.magenta); shaper.create(x4,y4,50,g, Color.orange); repaint(); } @Override public void actionPerformed(ActionEvent ae) { float[] values = move.firstscenemovement(500,200,st[0]); repaint(); System.out.println("x:"+values[0] + "\ny:" + values[1]); } } </code></pre> <p>The image repeats or trails as it moves would have posted an image but i need a 10 reputation to do.</p> <p>How can I correct this error? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload