Facebook
From Colorant Ibis, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 154
  1. package jpp;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.EventQueue;
  5. import java.awt.Graphics;
  6. import java.awt.Polygon;
  7. import java.awt.Toolkit;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10.  
  11. import javax.swing.*;
  12.  
  13.  
  14. public class niewiem extends JFrame{
  15.  
  16.         MyComponent komponent;
  17.         int MAXN=400;
  18.         int n=0;
  19.         Timer timer;
  20.        
  21.         class MyComponent extends JComponent{
  22.  
  23.                 @Override
  24.                 protected void paintComponent(Graphics g) {
  25.                         int w=getWidth();
  26.                         int h=getHeight();
  27.                         int x=0, y=0;
  28.                         int R=((w<h)?w:h)*9/20;
  29.                         int x0=w/2;
  30.                         int y0=h/2;
  31.                        
  32.                        
  33.                         g.drawArc(x0-R,y0-R , 2*R, 2*R, 0       , 270);
  34.                         g.drawLine(x0, y0, x0+R, y0);
  35.                         g.drawLine(x0, y0, x0, y0+R);
  36.                         double kat;
  37.                         int kolo = (int)Math.round(Math.PI*R/2.0);
  38.                         int obw=2*R+3*kolo;
  39.                         int nb=MAXN*R/obw;
  40.                         int na=(MAXN-2*nb)/3;
  41.                         if(n<nb) {
  42.                                 x=x0+R-R*n/nb;
  43.                                 y=y0;
  44.                                
  45.                         }else if(n<2*nb) {
  46.                                 x=x0;
  47.                                 y=y0+R*(n-nb)/nb;
  48.                        
  49.                         }else {
  50.                                 kat = Math.PI/2.0+Math.PI/2.0*(n-2*nb)/na;
  51.                                 x=(int)Math.round(x0+R*Math.cos(kat));
  52.                                 y=(int)Math.round(y0+R*Math.sin(kat));
  53.                         }
  54.                        
  55.                        
  56.                        
  57.                         g.fillOval(x-6,y-6, 12, 12);
  58.                         super.paintComponent(g);
  59.                 }
  60.                
  61.         }
  62.         public niewiem(String string) {
  63.                 super(string);
  64.                 setDefaultCloseOperation(EXIT_ON_CLOSE);
  65.                 Toolkit kit=Toolkit.getDefaultToolkit();
  66.                 Dimension d=kit.getScreenSize();
  67.                 setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
  68.                 add(komponent=new MyComponent());
  69.                 timer=new Timer(20,new ActionListener() {
  70.                        
  71.                         @Override
  72.                         public void actionPerformed(ActionEvent e) {
  73.                                 n++;
  74.                                 if(n>MAXN)
  75.                                         n-=MAXN;
  76.                                 komponent.repaint();
  77.                         }
  78.                 });
  79.                 timer.start();
  80.                 setVisible(true);
  81.         }
  82.  
  83.         public static void main(String[] args) {
  84.                 EventQueue.invokeLater(new Runnable() {
  85.                        
  86.                         @Override
  87.                         public void run() {
  88.                                 new niewiem("Animek 2");
  89.                         }
  90.                 });
  91.         }
  92.  
  93. }