민들레를 흔들다
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* 。。。。( , )
* @author LONG
*
*/
public class TheTree extends JFrame {
private static final long serialVersionUID = 1L;
private Dimension di = null;
private Graphics2D gr = null;
private int x,y; //
private JPanel jp = null; //
private int count = 0; //
/**
*
* @param args
*/
public static void main(String[] args){
TheTree tt = new TheTree();
tt.showFrame();
}
/**
* ,
*/
public void showFrame(){
this.setTitle("The Tree");
Toolkit tl = Toolkit.getDefaultToolkit();
di = tl.getScreenSize();
this.setSize(di.width,di.height);
this.setDefaultCloseOperation(3);
jp = new JPanel();
jp.setPreferredSize(new Dimension(di.width,di.height));
x = di.width; // ,
y = di.height; // ,
this.add(jp);
this.setResizable(false);
jp.setBackground(Color.BLACK);
this.setVisible(true);
gr = (Graphics2D) jp.getGraphics();
// ,
jp.addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent e){
draw(e);
}
});
}
/**
* ,
* @param e
*/
public void draw(MouseEvent e){
while(y > 0){
if(count == 0){
x = e.getX(); //
y = e.getY();
}else{
y -= 5; // , ,
x += 6;
}
init(x,y); //
}
}
// ,
public void init(int xx,int yy){
BasicStroke bs = new BasicStroke(4);
gr.setStroke(bs);
gr.setColor(Color.GREEN);
gr.drawLine(xx, yy, xx, yy - 400); //
doSomething(xx,yy - 400,150);
}
/**
*
*
* @param x1 x
* @param y1 y
* @param h h
*/
public void doSomething(int x1, int y1, int h){
//
for(int i = 0; i < 90; i++){
double angle = i * 2 * Math.PI/90; //
int x2 = x1 + (int)(Math.sin(angle) * h);
int y2 = y1 - (int)(Math.cos(angle) * h);
BasicStroke bs_next = new BasicStroke();
gr.setStroke(bs_next);
gr.setColor(Color.gray);
gr.drawLine(x1, y1, x2, y2);
gr.setColor(Color.WHITE);
gr.fillOval(x2 - 1, y2 - 1, 5, 5);
}
try {
Thread.sleep(120);
} catch (InterruptedException e) {
e.printStackTrace();
}
// , , ,
BasicStroke bs = new BasicStroke(4);
gr.setStroke(bs);
gr.setColor(Color.BLACK);
gr.drawLine(x1, y1 + 400, x1, y1);
for(int i = 0; i < 90; i++){
double angle = i * 2 * Math.PI/90;
int x2 = x1 + (int)(Math.sin(angle) * h);
int y2 = y1 - (int)(Math.cos(angle) * h);
BasicStroke bs_next = new BasicStroke();
gr.setStroke(bs_next);
gr.setColor(Color.BLACK);
gr.drawLine(x1, y1, x2, y2);
gr.setColor(Color.BLACK);
gr.fillOval(x2 - 1, y2 - 1, 5, 5);
}
count++;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.