post 텍스트 3 - 코드 클래스
5423 단어 post 코드
public class Clock extends JComponent{/**
//
g.setPaint(new GradientPaint(5,40,Color.blue,15,50,Color.yellow,true));
g.setStroke( new BasicStroke(3,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
g.drawOval(75, 40, 250, 250);
g.fillOval(195, 160, 10, 10);
g.setColor(Color.black);
// 60
for(int i = 0;i < 60;i++)
{
double[] co = new double[2];
co = paint_Dot(i * 2 * PI / 60);
x = co[0];
y = co[1];
if(i == 0 || i == 15 || i == 30 || i == 45)// 3,6,9,12
{
g.fillOval((int)(x - 5 + 200),(int)(y - 5 + 165),10,10);
}
else//
{
g.fillOval((int)(x - 2.5 + 200),(int)(y - 2.5 + 165),5,5);
}
}
//
g.setFont(f2);
g.drawString("3", 300, 171);
g.drawString("6", 195, 273);
g.drawString("9", 91, 171);
g.drawString("12", 190, 68);
// , ,
paint_HourPointer(hour*3600 + min*60 + sec,g);//
paint_MinutePointer(min*60 + sec,g);//
paint_SecondPointer(sec,g);//
}public void showUI(){new Thread() {br/>@SuppressWarnings("deprecation")public void run() {while (true) {now = new Date();hour = now.getHours();min = now.getMinutes();sec = now.getSeconds();try {Thread.sleep(1000);} catch (InterruptedException ex) {ex.printStackTrace();}showTime();repaint();}}}.start();} public void paint_HourPointer(int second·Graphic2D g) {//second는 현재 시간의 시계바늘이 00:00:00에 몇 초가 갔는지를 나타내는 Double x, y, angle; angle = second PI/21600;//시계바늘의 속도는 PI/21600(rad/s) x = 200+60 매h.sin(angle), y = 165∼60 매h.sin(angle) = 165∼60 * 매h.cos(angle), g.set Stroke(new BasicStroke Stroke(5, Basic Stroke. Basic Stroke. Base. Basic Base.CATTTT, BUUUUUUUUurPint Paint(new GradientPaint(200165, Color.red, 260165, Color.blue,true));g.drawLine(200, 165, (int)x, (int)y);} public void paint_미닛포인터(int second, Graphic2D g) {//second는 현재 시간의 분침이 00:00:00에 몇 초가 갔는지 보여주는 분침 x를 y, angle; angle = second PI/1800;/분침의 속도는 PI/1800(rad/s) x = 200+80 메이트시신(angle), y = 165-80 * 메이h.cos(angle), g.set Stroke(new Basic Stroke Stroke(3, Basic Stroke.Stroke.) x = 200+80 Math.sic.caTTTTT, BOint Buuuug, Bast Bast Bast Pint Pint Pint Point Pint Pint int(new GradientPaint(200165, Color.magenta, 280165, Color.blue,true));g.drawLine(200, 165, (int)x, (int)y);} public void paint_SecondPointer(int second, Graphics 2D g) {//second는 현재 시간의 초침이 00:00:00에 몇 초가 갔는지를 나타내는 초침x, y, x1, x2, x3, x3, y3, angle;더블cos = 90/Math.sqrt(8125),//90h.sqrt(8125), 90909090+55더블 sin = 5/x1, x1, y1, y1, y1, x2, y2, y2, y2, y2, y2, x3, x3, x3, y3, y3, angle, double cos = 90/마h.sqrt(8125),///////시침(시침) 시속 1650/300 + 3695 + 165시니=165, 165 = 165, - 95 Math.cos(angle), x1 = 200 + 20 Math.sin(angle + PI), y 1 = 165 - 20 Math.cos(angle + PI);x2 = 200 + Math.sqrt(8125) ( Math.sin(angle)cos - Math.cos(angle)sin );//sin(a-b)y2 = 165 - Math.sqrt(8125) ( Math.cos(angle)cos + Math.sin(angle)sin );//cos(a-b)x3 = 200 + Math.sqrt(8125) ( Math.sin(angle)cos + Math.cos(angle)sin );//sin(a+b)y3 = 165 - Math.sqrt(8125) ( Math.cos(angle)cos - Math.sin(angle)*sin );//cos(a+b)g.setStroke( new BasicStroke(2,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));g.setPaint(new GradientPaint(180,165,Color.CYAN,295,165,Color.MAGENTA,true));g.drawLine((int)x1, (int)y1, (int)x, (int)y);g.drawLine((int)x2, (int)y2, (int)x, (int)y);g.drawLine((int)x3, (int)y3, (int)x, (int)y);} public double[] paint_Dot(double angle) {double[]co = new double[2];co[0] = 115 Math.cos(angle);//가로 좌표co[1] = 115 Math.sin(angle);//세로 좌표return co;} @SuppressWarnings("deprecation")private void showTime(){String date;int hour_temp = hour,min_temp = min,sec_temp = sec;sec_temp += 1 ;if(sec_temp >= 60){sec_temp = 0;min_temp += 1 ;}if(min_temp>=60){min_temp=0;hour_temp+=1;}if(hour_temp < 10)strTime = "0"+ hour_temp + ":";elsestrTime = ""+ hour_temp + ":"; .public static void main(String args[]) {Clock c = new Clock(), c.showUI(), JFrame f = new JFrin main('Clock By XJXX')', Image Img=Toolkit.getDefaulTToolkit(), c.showCClock Clock(), c.showwwwwwwwwwwwwwwwwwwUI) ▲ ▲ ▲ ▲ ▲ pblic Cblic Cblic Clu676767676767913} 913} 146767913} 146767913} ▲ ▲ ▲ public pNTER), f.setLocationRelativeTo(null), f.setDefaultCloseOperation(JFrame.EXIT ON CLOSE), f.setVisible(true),}