All links here !!!
Hello, I had a desire to make an animated curtain with a gradual increase in transparency, but the output is this. (See the first link)
Animation code (See second link)
public void update(Graphics g) { //g.setColor(Color.WHITE); //g.fillRect(startX,startY,endX-startX,endY - startY); if (/*Позиция мышки*/ MyMouseAdapter.keyPress && posY > startY) if (speed == 0) speed = defaultSpeed; else if (!MyMouseAdapter.keyPress) { speed -= everyTick; posY += speed; } else if (posY <= endY) { speed += everyTick; posY -= speed; } draw(g); } public void draw(Graphics g) { int everyTick = 0; int thisalpha = 255; if (endY != posY) if ((endY - posY) <= 256) { everyTick = (int) 256 / (endY - posY); } else { everyTick = 1; } for (int y = endY; y > posY; y--) { if (thisalpha > 0) drawLine(thisalpha, y, g); else thisalpha = 0; if (thisalpha != 0) thisalpha = thisalpha - everyTick; } } void drawLine(int alpha, int y, Graphics g) { g.setColor(new Color(mainColor.getRed(), mainColor.getGreen(), mainColor.getBlue(), alpha)); g.drawLine(startX, y, endX, y); } Swing Element Code (See third link)
public class PaintPanel extends JPanel { Down down; public PaintPanel(){ super(); down = new Down(100,100,500,300); } @Override protected void paintComponent(Graphics g) { down.update(g); } } Also in a separate thread is updating the entire page. (See 4 link)
public SwingFrame() { JFrame jFrame = new JFrame("RMLauncher"); jFrame.setSize(1000, 1000); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); PaintPanel paintPanel = new PaintPanel(); jFrame.add(paintPanel); jFrame.setVisible(true); while (true) { try { Thread.sleep(1000 / FPS); } catch (InterruptedException e) { } jFrame.update(jFrame.getGraphics()); } } I would like to get rid of the jerk animation and understand where I nakosyachil. For me, working with graphs in Java for the first time, so many obvious things I may not know.