Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Estradi extends JFrame implements Runnable{
- //x max = 471
- //x min = 9
- // y max = 471
- // y min = 32
- // mistä pallo lähtee
- int x = 9;
- int y = 32;
- // maksimit enne ruudulta poistumista
- int minX = 9;
- int minY = 32;
- int maxX = 471;
- int maxY = 471;
- private Thread t=null;
- //sleepmetodin tauko
- int tauko=1;
- public Estradi(){
- // ikkuna
- this.setSize(500,500);
- this.setTitle("Ikkuna");
- // Pysäyttää suorituksen painettaessa raksia
- this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- }
- public void run(){
- //suuntaliput
- int suuntay = 0;
- int suuntax = 0;
- int tulostustoisto=0;
- while(tulostustoisto<1){
- if(x < minX)
- {
- suuntax = 1;
- }
- if(x > maxX)
- {
- suuntax = 0;
- }
- if(y < minY)
- {
- suuntay = 1;
- }
- if(y > maxY)
- {
- suuntay = 0;
- }
- if (suuntay == 1)
- {
- y++;
- }
- else
- --y;
- if (suuntax == 1)
- {
- x++;
- }
- else
- --x;
- try{
- repaint();
- t.sleep(tauko);
- --tulostustoisto;
- }
- catch(InterruptedException e) {}
- }
- }
- // neliön piirto
- public void paint(Graphics g) {
- super.paint(g);
- g.setColor(Color.MAGENTA);
- g.fillRect(x, y, 30, 30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement