Advertisement
ljukk

Rampa

May 10th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import javax.swing.JComponent;
  4.  
  5. /*
  6.  * To change this license header, choose License Headers in Project Properties.
  7.  * To change this template file, choose Tools | Templates
  8.  * and open the template in the editor.
  9.  */
  10.  
  11. /**
  12.  *
  13.  * @author sused
  14.  */    
  15. public class Rampa extends JComponent {
  16.    
  17.     protected int x1;
  18.     protected int y1;
  19.     protected int x2;
  20.     protected int y2;
  21.    
  22.    
  23.    
  24.    
  25.     public Rampa() {
  26.        
  27.     x1 = 10;
  28.     y1 = 170;
  29.     x2 = 180;
  30.     y2 = 170;
  31.     setBounds(0,0,200,300);
  32.     }
  33.    
  34.     public void up(){
  35.       if(x1 < x2 )  {  
  36.         x1+=2;
  37.         y1-=2;
  38.       }
  39.       repaint();
  40.     }
  41.    
  42.     public void down() {
  43.       if (y1 < y2) {  
  44.         x1-=2;
  45.         y1+=2;
  46.       }
  47.       repaint();
  48.     }
  49.  
  50.     @Override
  51.     protected void paintComponent(Graphics g) {
  52.         super.paintComponent(g);
  53.         g.fillRect(160, 160, 30, 130);
  54.         g.setColor(Color.yellow);
  55.         g.drawLine(x1, y1, x2, y2);
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement