Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.KeyListener;
  7. import java.util.Timer;
  8.  
  9. public class Glowna extends Applet implements KeyListener {
  10.    
  11.     static Applet applet;
  12.    
  13.     Plansza plansza = new Plansza();
  14.     Timer timer = new Timer();
  15.    
  16.     int x = 0;
  17.     int y = 0;
  18.    
  19.     Image image;
  20.     Graphics graphics;
  21.    
  22.     int wielkoscX = 20*40;
  23.     int wielkoscY = 20*40;
  24.    
  25.     public Glowna() {
  26.         this.setFocusable(true);
  27.         this.addKeyListener(this);
  28.     }
  29.    
  30.     public void init() {
  31.         setSize(wielkoscX, wielkoscY);
  32.         setBackground(Color.BLUE);
  33.         image = createImage(wielkoscX, wielkoscY);
  34.         graphics = image.getGraphics();
  35.         timer.scheduleAtFixedRate(plansza, 10, 10);
  36.        
  37.         plansza.zrobPlansze();
  38.     }
  39.    
  40.     public void update (Graphics g) {
  41.         graphics.clearRect(0, 0, wielkoscX, wielkoscY);
  42.         paint(graphics);
  43.         g.drawImage(image, x, y, applet);
  44.     }
  45.    
  46.     public void paint (Graphics g) {
  47.         rysujPlansze(g);
  48.     }
  49.    
  50.     public void rysujPlansze(Graphics g) {
  51.         for (int i = 0; i < plansza.plansza.length; i++) {
  52.             for (int j = 0; j < plansza.plansza[0].length; j++) {
  53.                
  54.                 switch(plansza.plansza[i][j]) {
  55.                 case 0:
  56.                     break;
  57.                 case 1:
  58.                     g.setColor(Color.YELLOW);
  59.                     g.fillOval(40*j, 40*i, 15, 15);
  60.                     break;
  61.                 }
  62.             }
  63.         }
  64.     }
  65.    
  66.  
  67.     @Override
  68.     public void keyPressed(KeyEvent e) {
  69.        
  70.         switch (e.getKeyCode()) {
  71.         case 37:
  72.             break;
  73.         case 38:
  74.             break;
  75.         case 39:
  76.             break;
  77.         case 40:
  78.             break;
  79.         }
  80.     }
  81.  
  82.     @Override
  83.     public void keyReleased(KeyEvent e) {}
  84.  
  85.     @Override
  86.     public void keyTyped(KeyEvent e) {}
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement