Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. private PaintableElevator paintableObject;
  2. private Line2D wallLeftSide = new Line2D.Double();
  3. private Line2D wallRightSide = new Line2D.Double();
  4. private Rectangle2D elevator = new Rectangle2D.Double();
  5.  
  6. @Override
  7. public void componentResized (ComponentEvent e)
  8. {
  9. wallLeftSide.setLine(new Point2D.Double(0, changeYCoordsOrigin(getHeight() * paintableObject.getTotalHeight())), new Point2D.Double(0, getWidth()));
  10.  
  11. wallRightSide.setLine(new Point2D.Double(getWidth(), changeYCoordsOrigin(getHeight() * paintableObject.getTotalHeight())), new Point2D.Double(getWidth(), getHeight()));
  12.  
  13. elevator.setRect(0, changeYCoordsOrigin(getHeight() * paintableObject.getHeightInShaft()), getWidth(), paintableObject.getCabinHeight() * getHeight() *-1);
  14. }
  15.  
  16. public double changeYCoordsOrigin (double coord)
  17. {
  18. return getHeight() - coord;
  19. }
  20.  
  21. @Override
  22. public void setHeigth (double height)
  23. {
  24. elevator.setRect(0, getHeight() * height, getWidth(), paintableObject.getCabinHeight());
  25. repaint();
  26. }
  27.  
  28. @Override
  29. public void paint (Graphics g)
  30. {
  31. if (g instanceof Graphics2D)
  32. {
  33. Graphics2D g2 = (Graphics2D) g;
  34. g2.draw(wallLeftSide);
  35. g2.draw(wallRightSide);
  36. g2.setBackground(Color.gray);
  37. g2.draw(elevator);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement