1 | package gamegui;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 |
|
---|
6 | public class ScrollBar extends Member {
|
---|
7 | int size;
|
---|
8 | int position;
|
---|
9 | int scrollSpeed;
|
---|
10 |
|
---|
11 | public ScrollBar(String newName, int newX, int newY, int newWidth, int newHeight, int newScrollSpeed) {
|
---|
12 | super(newName, newX, newY, newWidth, newHeight);
|
---|
13 |
|
---|
14 | size = 0;
|
---|
15 | position = 0;
|
---|
16 | scrollSpeed = newScrollSpeed;
|
---|
17 | }
|
---|
18 |
|
---|
19 | public void clear() {
|
---|
20 | size = 0;
|
---|
21 | position = 0;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public boolean handleEvent(MouseEvent e) {
|
---|
25 | if(!(getX() < e.getX() && e.getX() < getX()+getWidth() && getY() < e.getY() && e.getY() < getY()+getHeight()))
|
---|
26 | return false;
|
---|
27 | else
|
---|
28 | return true;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void draw(Graphics g) {
|
---|
32 | g.setColor(Color.black);
|
---|
33 | g.fillRect(getX(), getY(), getWidth(), getHeight());
|
---|
34 |
|
---|
35 | g.setColor(Color.red);
|
---|
36 | g.drawRect(getX(), getY(), getWidth(), getHeight());
|
---|
37 |
|
---|
38 | g.drawLine(getX(), getY()+getWidth(), getX()+getWidth(), getY()+getWidth());
|
---|
39 | g.drawLine(getX(), getY()+getHeight()-getWidth(), getX()+getWidth(), getY()+getHeight()-getWidth());
|
---|
40 |
|
---|
41 | g.drawLine(getX(), getY()+getWidth()+position, getX()+getWidth(), getY()+getWidth()+position);
|
---|
42 | g.drawLine(getX(), getY()+getWidth()+position+size, getX()+getWidth(), getY()+getWidth()+position+size);
|
---|
43 |
|
---|
44 | g.drawLine(getX()+getWidth()*3/20, getY()+getWidth()*17/20, getX()+getWidth()*17/20, getY()+getWidth()*17/20);
|
---|
45 | g.drawLine(getX()+getWidth()*17/20, getY()+getWidth()*17/20, getX()+getWidth()/2, getY()+getWidth()*3/20);
|
---|
46 | g.drawLine(getX()+getWidth()/2, getY()+getWidth()*3/20, getX()+getWidth()*3/20, getY()+getWidth()*17/20);
|
---|
47 |
|
---|
48 | g.drawLine(getX()+getWidth()*3/20, getY()+getHeight()-getWidth()*17/20, getX()+getWidth()*17/20, getY()+getHeight()-getWidth()*17/20);
|
---|
49 | g.drawLine(getX()+getWidth()*17/20, getY()+getHeight()-getWidth()*17/20, getX()+getWidth()/2, getY()+getHeight()-getWidth()*3/20);
|
---|
50 | g.drawLine(getX()+getWidth()/2, getY()+getHeight()-getWidth()*3/20, getX()+getWidth()*3/20, getY()+getHeight()-getWidth()*17/20);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public int getPosition() {
|
---|
54 | return position;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public int getScrollSpeed() {
|
---|
58 | return scrollSpeed;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public int getSize() {
|
---|
62 | return size;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public int getMaxSize() {
|
---|
66 | return getHeight()-2*getWidth();
|
---|
67 | }
|
---|
68 |
|
---|
69 | public void setPosition(int position) {
|
---|
70 | this.position = position;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public void setSize(int size) {
|
---|
74 | this.size = size;
|
---|
75 | }
|
---|
76 | }
|
---|