Last change
on this file since 161 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
File size:
1.2 KB
|
Rev | Line | |
---|
[2] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | package routegui;
|
---|
| 7 |
|
---|
| 8 | import java.awt.Graphics;
|
---|
| 9 | import javax.swing.JPanel;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | *
|
---|
| 13 | * @author rick
|
---|
| 14 | */
|
---|
| 15 | public class Compass extends JPanel {
|
---|
| 16 | private int angle = 0;
|
---|
| 17 | private int margin = 10;
|
---|
| 18 |
|
---|
| 19 | @Override public void paintComponent(Graphics g) {
|
---|
| 20 | super.paintComponent(g); // paints background
|
---|
| 21 | int height = this.getHeight();
|
---|
| 22 | int width = this.getWidth();
|
---|
| 23 | g.drawOval(margin, margin,
|
---|
| 24 | height - (2 * margin), width - (2 * margin));
|
---|
| 25 | /* Make 0 degrees act like north */
|
---|
| 26 | double angle_rad = (angle - 90) * 2.0 * Math.PI/360.0;
|
---|
| 27 | int len = (height / 2) - 2 * margin;
|
---|
| 28 | int xMiddle = width / 2;
|
---|
| 29 | int yMiddle = height / 2;
|
---|
| 30 |
|
---|
| 31 | g.drawLine(xMiddle, yMiddle,
|
---|
| 32 | xMiddle + (int)(Math.cos(angle_rad) * len) ,
|
---|
| 33 | yMiddle + (int)(Math.sin(angle_rad) * len));
|
---|
| 34 | }
|
---|
| 35 | public void setAngle(int angleNew) {
|
---|
| 36 | angle = angleNew;
|
---|
| 37 | this.repaint();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public void setMargin(int marginNew) {
|
---|
| 41 | margin = marginNew;
|
---|
| 42 | this.repaint();
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.