im wondering of anyone can help me use the rotate method, i looked through previous questions and didnt find what i was looking for..
Code has been compacted so someelements might be missing.. screenshot below.
im currently adding and subtracting 10 from the line variables to rotate can anyone help me use the actual rotate method,,
Thanks in Advance..
public class Display extends JFrame{
private int Lx1 = CANVAS_WIDTH / 2; private int Mx1 = CANVAS_WIDTH / 2;
private int Ly1 = CANVAS_HEIGHT / 2; private int My1 = CANVAS_HEIGHT / 2;
private int Lx2 = CANVAS_WIDTH / 2; private int Mx2 = CANVAS_WIDTH / 2;
private int Ly2 = CANVAS_HEIGHT / 2; private int My2 = CANVAS_HEIGHT;
public Display() {
canvas = new DrawCanvas();
canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
canvas.setLayout(new GridLayout(8, 4, 80, 10));
canvas.setComponentOrientation(ComponentOrientation.UNKNOWN);
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
Altitude = new JTextField("Altitude", 5); Altitude.setHorizontalAlignment(JTextField.CENTER);
Altitude.setEditable(false); Altitude.setOpaque(false);
Altitude.setFont(Altitude.getFont().deriveFont(25f)); Altitude.setForeground(Color.WHITE);
TASpeed = new JTextField("TAs", 5); TASpeed.setHorizontalAlignment(JTextField.CENTER);
TASpeed.setEditable(false); TASpeed.setOpaque(false);
TASpeed.setFont(TASpeed.getFont().deriveFont(25f)); TASpeed.setForeground(Color.WHITE);
TargetAlt = new JTextField("Taralt", 5); TargetAlt.setHorizontalAlignment(JTextField.CENTER);
TargetAlt.setEditable(false); TargetAlt.setOpaque(false);
TargetAlt.setFont(TargetAlt.getFont().deriveFont(25f)); TargetAlt.setForeground(Color.WHITE);
TargetSpeed = new JTextField("TArsp", 5); TargetSpeed.setHorizontalAlignment(JTextField.CENTER);
TargetSpeed.setEditable(false); TargetSpeed.setOpaque(false);
TargetSpeed.setFont(TASpeed.getFont().deriveFont(25f)); TargetSpeed.setForeground(Color.WHITE);
BaroCorrectUp = new JTextField("BaroCorU", 5); BaroCorrectUp.setHorizontalAlignment(JTextField.CENTER);
BaroCorrectUp.setEditable(false); BaroCorrectUp.setOpaque(false);
BaroCorrectUp.setFont(BaroCorrectUp.getFont().deriveFont(25f)); BaroCorrectUp.setForeground(Color.WHITE);
BaroCorrectDown = new JTextField("BaroCorD", 5); BaroCorrectDown.setHorizontalAlignment(JTextField.CENTER);
BaroCorrectDown.setEditable(false); BaroCorrectDown.setOpaque(false);
BaroCorrectDown.setFont(BaroCorrectUp.getFont().deriveFont(25f)); BaroCorrectDown.setForeground(Color.WHITE);
WindDir = new JTextField("Wind dir", 5); WindDir.setHorizontalAlignment(JTextField.CENTER);
WindDir.setEditable(false); WindDir.setOpaque(false);
WindDir.setFont(WindDir.getFont().deriveFont(25f)); WindDir.setForeground(Color.WHITE);
EquivSpeed = new JTextField("EquivSpe", 5); EquivSpeed.setHorizontalAlignment(JTextField.CENTER);
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent evt) {
switch(evt.getKeyCode()) {
case KeyEvent.VK_LEFT:
Rx1 -= 10; Ry1 += 10; Rx2 += 10; Ry2 -= 10;
x1 -=10; x2 +=10; Mx1 += 10; Mx2 -= 10;
repaint();
break;
case KeyEvent.VK_RIGHT:
Rx1 -= 10; Ry1 -= 10; Rx2 += 10; Ry2 += 10;
x1 += 10; x2 += 10; Mx1 -= 10; Mx2 += 10;
repaint();
break;
case KeyEvent.VK_DOWN:
y1 -= 10; y2 -= 10; Ly1 -= 10; Ly2 -= 10;
Sy1 += 10; Sy2 -= 10; Ry1 +=10; Ry2 += 10;
repaint();
break;
case KeyEvent.VK_UP:
y1 += 10; y2 += 10; Ly1 += 10; Ly2 += 10;
Sy1 -= 10; Sy2 += 10; Ry1 -= 10; Ry2 -= 10;
repaint();
break;
case KeyEvent.VK_M:
System.exit(0);
break;
case KeyEvent.VK_4:
countAd++;
BaroCorrectDown.setText(countAd + "");
repaint();
break;
case KeyEvent.VK_3:
countAu++;
BaroCorrectUp.setText(countAu + "");
repaint();
break;
}
}
});
cp.add(canvas);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(CANVAS_WIDTH / 3, CANVAS_HEIGHT / 4, CANVAS_WIDTH, CANVAS_HEIGHT);
setTitle("FLIGHT DISPLAY"); pack();
setVisible(true); requestFocus();
}
class DrawCanvas extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
setBackground(CANVAS_BACKGROUND);
g.setColor(GROUND_COLOR);
//Draw ground Color
g.drawRect(Sx1 - Sx1,Sy1 /2, CANVAS_WIDTH, Sy2 /2);
g.fillRect(Sx1 - Sx1, Sy1 /2, CANVAS_WIDTH, Sy2 /2);
g.setColor(LINE_COLOR);
//Draw line centre horizontal
g.drawLine(Rx1, Ry1 /2, Rx2, Ry2 /2);
g.drawOval(x1 -15, y1 -15, 30, 30);
//Draw line dim
g.setColor(Color.YELLOW);
g.fillArc(CANVAS_WIDTH /2 -150, 10, 300, 170, 30, 120);
g.setColor(LINE_COLOR);
//Draw polyline centre plane
g.setColor(Color.YELLOW);
g.drawPolyline(xs, ys, 10);
g.fillPolygon(new Polygon(
new int[]{470, 350, 230, 350, 470},
new int[]{260, 205, 260, 225, 260},5));
g.setColor(Color.CYAN);
g.setColor(Color.BLACK);
g.drawArc(CANVAS_WIDTH / 2 -150, 10, 300, 170, 30, 120);
g.drawArc(CANVAS_WIDTH / 2 -150, 11, 300, 170, 30, 120);
g.setColor(CANVAS_BACKGROUND);
g.fillRect(0, 60, CANVAS_WIDTH, 50);
Color DarkTRANS = new Color(0.0f, 0.0f, 0.0f, 1.0f);
g.setColor(DarkTRANS);
g.fillRect(0, 400, CANVAS_WIDTH, 50);
g.fillRect(0, 345, 115, 55);
g.fillRect(585, 345, 115, 55);
g.setColor(LINE_COLOR);
g.drawLine(Lx1 -50, Ly1 -120, Lx2 +50, Ly2 -120);
g.drawLine(Lx1 -25, Ly1 -140, Lx2 +25, Ly2 -140);
g.drawLine(Lx1 -75, Ly1 -160, Lx2 +75, Ly2 -160);
g.drawLine(Lx1 -25, Ly1 +20, Lx2 +25, Ly2 +20);
g.drawLine(Lx1 -50, Ly1 +40, Lx2 +50, Ly2 +40);
g.drawLine(Lx1 -25, Ly1 +60, Lx2 +25, Ly2 +60);
g.drawLine(Lx1 -75, Ly1 +80, Lx2 +75, Ly2 +80);
g.drawLine(Lx1 -25, Ly1 +100, Lx2 +25, Ly2 +100);
g.drawLine(Lx1 -50, Ly1 +120, Lx2 +50, Ly2 +120);
//Draw line dim
g.drawLine(Lx1 -25, Ly1 -20, Lx2 +25, Ly2 -20);
g.drawLine(Lx1 -50, Ly1 -40, Lx2 +50, Ly2 -40);
g.drawLine(Lx1 -25, Ly1 -60, Lx2 +25, Ly2 -60);
g.drawLine(Lx1 -75, Ly1 -80, Lx2 +75, Ly2 -80);
g.drawLine(Lx1 -25, Ly1 -100, Lx2 +25, Ly2 -100);
//bottom triangles
g.setColor(DarkTRANS);
g.fillPolygon(new Polygon(
new int[]{115, 115, 200},
new int[]{400, 345, 400},3));
g.fillPolygon(new Polygon(
new int[]{585, 585, 500},
new int[]{400, 345, 400},3));
//top button triangle/shapes
g.fillPolygon(new Polygon(
new int[]{0, 200, 115, 0,},
new int[]{0, 0, 50, 50},4));
g.fillPolygon(new Polygon(
new int[]{500, 700, 700, 585,},
new int[]{0, 0, 50, 50},4));
//middle button shapes
g.fillPolygon(new Polygon(
new int[]{0, 100, 100, 117, 117, 130, 117, 117, 100, 100, 0},
new int[]{174, 174, 159, 159, 187, 197, 207, 235, 235, 220, 220},11));
//right hand shape
g.fillPolygon(new Polygon(
new int[]{700, 600, 600, 583, 583, 570, 583, 583, 600, 600, 700},
new int[]{174, 174, 159, 159, 187, 197, 207, 235, 235, 220, 220},11));
Color TRANS = new Color(0.0f, 0.0f, 0.0f, 0.35f);
g.setColor(TRANS);
g.fillRect(0, 0, 115, CANVAS_HEIGHT);
g.fillRect(585, 0, 115, CANVAS_HEIGHT);
g.setColor(LINE_COLOR);
g.drawLine(Mx1+20, My1 + My1, Mx2, My2-440);
g.drawLine(Mx1-20, My1 + My1, Mx2, My2-440);
g.drawLine(Mx1, My1 + My1, Mx2, My2-440);
g.drawString("10", Lx1 -90, Ly1 -75);
g.drawString("10", Lx1 +77, Ly1 -75);
g.drawString("10", Lx1 -90, Ly1 +85);
g.drawString("10", Lx1 +77, Ly1 +85);
g.drawString("20", Lx1 +77, Ly1 -155);
g.drawString("20", Lx1 -90, Ly1 -155);
g.drawString("Press alt + 3(U), 4(D)\n" , 582, 305);
g.drawString("To Initialize" , 595, 315);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Display();
}
});
}
}