Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.88 KB | None | 0 0
  1.  
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.geom.*;
  5. import javax.swing.*;
  6. import java.util.*;
  7.  
  8. public class Display extends Frame {
  9.  
  10.     int xmou = 400; //set the center of circle
  11.     int ymou = 400; //set the center of circle
  12.     int x = xmou; //x position of Second's hand
  13.     int y = ymou; //y position of second's hand
  14.     double theta = -0.1047; //theta for second's hand
  15.     double the = -0.1047; //theta for creating outer circle
  16.     double thetan = -0.0;          //theta for numbers of Radar
  17.     int xn = xmou; //x position of Radar numbers
  18.     int yn = ymou; //y position of Radar numbers
  19.     int pn, bn; //perpendicular and base of Radar numbers
  20.     int num = 0; //for writing the numbers
  21.     int h = 340;
  22.  
  23.     public class Interface {
  24.  
  25.         public Interface(Graphics2D g) {
  26.             Shape border = new Ellipse2D.Float(50.0f, 50.0f, 700.0f, 700.0f);
  27.             Shape circle = new Ellipse2D.Float(55.0f, 55.0f, 690.0f, 690.0f);
  28.             Shape square = new Rectangle2D.Double(0, 0, 800, 800);
  29.             g.draw(square);
  30.             g.fill(square);
  31.             g.draw(circle);
  32.             g.setPaint(Color.black);
  33.             g.fill(circle);
  34.             g.setPaint(Color.green);
  35.             g.fill(border);
  36.             g.setPaint(Color.black);
  37.             g.fill(circle);
  38.         }
  39.     }
  40.  
  41.     public class Building {
  42.  
  43.         public Building(Graphics2D g) {
  44.             Shape walls = new Rectangle2D.Double(300, 300, 100, 300);
  45.             g.draw(walls);
  46.             g.setPaint(Color.red);
  47.             g.fill(walls);
  48.         }
  49.     }
  50.  
  51.     public class Aircraft {
  52.  
  53.         public Aircraft(Graphics2D g) {
  54.             int bx = 500, by = 500;
  55.             Shape body = new Ellipse2D.Float(bx, by, 20, 20);
  56.             g.draw(body);
  57.             g.setPaint(Color.pink);
  58.             g.fill(body);
  59.         }
  60.     }
  61.  
  62.     public void paint(Graphics g) {
  63.         Graphics2D ga = (Graphics2D) g;
  64.         Interface i = new Interface(ga);
  65.         Building r = new Building(ga);
  66.         Aircraft a = new Aircraft(ga);
  67.         for (int p = 0; p < 360; p++) {
  68.  
  69.             int xocir = xmou;      //x position of outer circle
  70.             int yocir = ymou;      //y position of outer circle
  71.             int pocir, bocir;     //perpendicular and base of outer circle
  72.  
  73.             pocir = (int) (Math.sin(the) * (h + 23));
  74.             bocir = (int) (Math.cos(the) * (h + 23));
  75.             xocir = xocir - pocir;
  76.             yocir = yocir - bocir;
  77.             the = the - 0.1047;
  78.  
  79.             g.setColor(Color.BLUE);
  80.             g.drawLine(xocir + 5, yocir + 5, xocir, yocir);
  81.             //g.setColor(Color.BLACK);
  82.             if (p % 5 == 0) {
  83.                 num++;
  84.                 if (num > 1) {
  85.                     num = 1;
  86.                 }
  87.  
  88.                 xn = xmou;
  89.                 yn = ymou;
  90.  
  91.                 if (thetan <= -6.28318531) {
  92.                     thetan = 0.0;
  93.  
  94.                 }
  95.                 thetan = thetan - 0.0872;
  96.                 pn = (int) (Math.sin(thetan) * (h + 20));
  97.                 bn = (int) (Math.cos(thetan) * (h + 20));
  98.                 xn = xn - pn;
  99.                 yn = yn - bn;
  100.                 g.drawString("" + num, xn - 3, yn + 5);
  101.  
  102.             }
  103.  
  104.         }
  105.  
  106.         //for drawing Radar hands
  107.  
  108.         g.setColor(Color.BLACK);
  109.  
  110. //        g.drawLine(xmou, ymou, xm, ym); //drawing minute's hand
  111. //        g.drawLine(xmou, ymou, xh, yh); //drawing hour's hand
  112.  
  113.         g.setColor(Color.RED);
  114.         g.drawLine(xmou, ymou, x, y); //drawing second's hand
  115.  
  116.  
  117.     }
  118.  
  119.     public static void main(String args[]) {
  120.         Frame frame = new Display();
  121.         frame.addWindowListener(new WindowAdapter() {
  122.  
  123.             public void windowClosing(WindowEvent we) {
  124.                 System.exit(0);
  125.             }
  126.         });
  127.         frame.setSize(800, 800);
  128.         frame.setVisible(true);
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement