Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import javax.swing.JComponent;
- /*
- * 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.
- */
- /**
- *
- * @author sused
- */
- public class Rampa extends JComponent {
- protected int x1;
- protected int y1;
- protected int x2;
- protected int y2;
- public Rampa() {
- x1 = 10;
- y1 = 170;
- x2 = 180;
- y2 = 170;
- setBounds(0,0,200,300);
- }
- public void up(){
- if(x1 < x2 ) {
- x1+=2;
- y1-=2;
- }
- repaint();
- }
- public void down() {
- if (y1 < y2) {
- x1-=2;
- y1+=2;
- }
- repaint();
- }
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.fillRect(160, 160, 30, 130);
- g.setColor(Color.yellow);
- g.drawLine(x1, y1, x2, y2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement