Advertisement
sergAccount

Untitled

Oct 18th, 2020
2,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package game;
  7.  
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import javax.swing.JPanel;
  11. import javax.swing.Timer;
  12.  
  13. public class Pole extends JPanel{
  14.    
  15.     int slogn;
  16.     Image fon, shapka;
  17.     //
  18.     int shapkaX = 400;
  19.     // static final - константа
  20.     static final int shapkaY = 460;
  21.     // Timer
  22.     Timer timerDraw, timerUpdate;
  23.    
  24.     public Pole(int slogn){
  25.         this.slogn = slogn;
  26.         fon = ImageUtil.loadImage(Game.getFonPath());
  27.         shapka = ImageUtil.loadImage(Game.getShapkaPath());
  28.         // 50 - интервал времени в миллисекундах
  29.         // repaint() - для период обновления экрана
  30.         timerDraw = new Timer(50, (e) -> repaint());
  31.         // вызов метода start
  32.         timerDraw.start();      
  33.         //
  34.         timerUpdate = new Timer(4000, (e) -> updateStart());
  35.         timerUpdate.start();
  36.     }
  37.     // метод для появления объектов типа Podar
  38.     private void updateStart() {
  39.         System.out.println("updateStart");
  40.     }
  41.     //
  42.     public int getShapkaX(){
  43.         return shapkaX;
  44.     }
  45.     public void setShapkaX(int shapkaX){
  46.         this.shapkaX = shapkaX;
  47.     }
  48.     //
  49.     public void moveL(int shift){
  50.         shapkaX = shapkaX - shift;
  51.     }
  52.     public void moveR(int shift){
  53.         shapkaX = shapkaX + shift;
  54.     }
  55.     //
  56.     public void paintComponent(Graphics gr){
  57.         //
  58.         //System.out.println("paintComponent");        
  59.         super.paintComponent(gr);
  60.         // отображение граф информации
  61.         // drawImage - для отображения информации на основе объекта типа Image        
  62.         //String fileName = "k:/images/fon.jpg";        
  63.         //Image i = ImageUtil.loadImage(fileName);
  64.         // drawImage - для отображения информации на основе объекта типа Image
  65.         gr.drawImage(fon, 0, 0, null);
  66.         gr.drawImage(shapka, shapkaX, shapkaY, null);
  67.     }        
  68.  
  69.    
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement