Witam, mam problem, obiekt nie odbija się przy zetknięciu z krawędzią okna, tak jakby cały czas ten warunek
if(y>=getHeight()-95 )
nie był spełniony a jest, proszę o pomoc
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JApplet;
/**
*
* @author Damian
*/
public class Nowy extends JApplet {
int x =0, y=0;
/**
* Initialization method that will be called after the applet is loaded into
* the browser.
*/
public void init() {
setBackground(Color.LIGHT_GRAY);
setSize(500, 400);
// TODO start asynchronous download of heavy resources
}
public void paint(Graphics g){
int dy =3;
y+=dy;
if(y>=getHeight()-95 )
dy = -dy;
try {
Thread.sleep(20);
}catch(InterruptedException e){}
repaint();
g.clearRect(0, 0, getWidth(), getHeight());
Font f = new Font("SanSerif", Font.ITALIC, 22);
g.setFont(f);
String s ="Wesoły Bałwan ";
g.setColor(Color.blue);
g.drawString(s, 10,20);
g.setColor(Color.BLACK);
g.fillRect(x+(getWidth()/2)-5 , y+(getHeight()/2)-5 , 15, 15);
g.drawLine(x+(getWidth()/2) -10, y+(getHeight()/2) +10, x+(getWidth()/2) +15, y+(getHeight()/2) +10 );
g.setColor(Color.WHITE);
g.fillOval(x+(getWidth()/2) -10, y+(getHeight()/2) +10, 25, 20);
g.fillOval(x+(getWidth()/2) -20, y+(getHeight()/2) +30, 45, 35);
g.fillOval(x+(getWidth()/2) -30, y+(getHeight()/2) +65, 65, 45);
}
// TODO overwrite start(), stop() and destroy() methods
}