日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

用java编写打印时间_编写一个java程序,读取系统时间,然后将时间用中文输出...

發布時間:2024/9/19 windows 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用java编写打印时间_编写一个java程序,读取系统时间,然后将时间用中文输出... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

展開全部

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import java.util.Calendar;

import javax.swing.*;

public class Clock extends JPanel implements ActionListener

{

//創建時鐘的外形

protected static Ellipse2D face = new Ellipse2D.Float( 3, 3, 94, 94 );

//創建時鐘的標記

protected static GeneralPath tick = new GeneralPath();

static

{

tick.moveTo( 100, 100 );

tick.moveTo( 49, 0 );

tick.lineTo( 51, 0 );

tick.lineTo( 49, 6 );

tick.lineTo( 49, 0 );

}

//創建時針

protected static GeneralPath hourHand = new GeneralPath();

static

{

hourHand.moveTo( 50, 15 );

hourHand.lineTo( 53, 50 );

hourHand.lineTo( 50, 53 );

hourHand.lineTo( 47, 50 );

hourHand.lineTo( 50, 15 );

}

//創建分針

protected static GeneralPath minuteHand = new GeneralPath();

static

{

minuteHand.moveTo( 50, 2 );

minuteHand.lineTo( 53, 50 );

minuteHand.lineTo( 50, 58 );

minuteHand.lineTo( 47, 50 );

minuteHand.lineTo( 50, 2 );

}

//創建秒針

protected static GeneralPath secondHand = new GeneralPath();

static

{

secondHand.moveTo( 49, 5 );

secondHand.lineTo( 51, 5 );

secondHand.lineTo( 51, 62 );

secondHand.lineTo( 49, 62 );

secondHand.lineTo( 49, 5 );

}

//設置時鐘的顏色e69da5e887aa3231313335323631343130323136353331333262383636

protected static Color faceColor = new Color( 220, 220, 220 );

protected static Color hourColor = Color.red.darker();

protected static Color minuteColor = Color.blue.darker();

protected static Color secondColor = new Color( 180, 180, 0 );

protected static Color pinColor = Color.gray.brighter();

//設置時鐘的樞紐

protected Ellipse2D pivot = new Ellipse2D.Float( 47, 47, 6, 6 );

protected Ellipse2D centerPin = new Ellipse2D.Float( 49, 49, 2, 2 );

//創建饒時鐘樞紐轉的變換

protected AffineTransform hourTransform =

AffineTransform.getRotateInstance( 0, 50, 50 );

protected AffineTransform minuteTransform =

AffineTransform.getRotateInstance( 0, 50, 50 );

protected AffineTransform secondTransform =

AffineTransform.getRotateInstance( 0, 50, 50 );

//創建每秒觸發一次的Timer

protected Timer timer = new Timer( 1000, this );

protected Calendar calendar = Calendar.getInstance();

public Clock()

{

setPreferredSize( new Dimension( 100, 100 ) );

}

public void addNotify()

{

super.addNotify();

timer.start();

}

public void removeNotify()

{

timer.stop();

super.removeNotify();

}

public void actionPerformed( ActionEvent event )

{

//更新calendar的時間

this.calendar.setTime( new java.util.Date() );

int hours = this.calendar.get( Calendar.HOUR );

int minutes = this.calendar.get( Calendar.MINUTE );

int seconds = this.calendar.get( Calendar.SECOND );

//設置變換, 使得時針、分針、秒針各自繞樞紐旋轉一定的角度

hourTransform.setToRotation( ( ( double ) hours ) * ( Math.PI / 6.0 ), 50, 50 );

minuteTransform.setToRotation( ( ( double ) minutes ) * ( Math.PI / 30.0 ), 50, 50 );

secondTransform.setToRotation( ( ( double ) seconds ) * ( Math.PI / 30.0 ), 50, 50 );

repaint();

}

public void paint( Graphics g )

{

super.paint( g );

//得到圖形上下文和抗鋸齒處理

Graphics2D g2 = ( Graphics2D ) g;

g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,

RenderingHints.VALUE_ANTIALIAS_ON );

g2.setPaint( faceColor );

g2.fill( face );

g2.setPaint( Color.black );

g2.draw( face );

//產生鐘面上12個滴答位置

for( double p = 0.0; p < 12.0; p += 1.0 )

{

//利用變換畫出同心的滴答的標線

g2.fill( tick.createTransformedShape(

AffineTransform.getRotateInstance( ( Math.PI / 6.0 ) * p, 50, 50 ) ) );

}

g2.setPaint( hourColor );

g2.fill( hourHand.createTransformedShape( hourTransform ) );

g2.setPaint( minuteColor );

g2.fill( minuteHand.createTransformedShape( minuteTransform ) );

g2.setPaint( secondColor );

g2.fill( secondHand.createTransformedShape( secondTransform ) );

g2.fill( pivot );

g2.setPaint( pinColor );

g2.fill( centerPin );

}

public static void main( String[] args )

{

JFrame frame = new JFrame();

frame.setLocation( 700, 400 );

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

frame.getContentPane().add( new Clock() );

frame.pack();

frame.show();

}

}

已贊過

已踩過<

你對這個回答的評價是?

評論

收起

總結

以上是生活随笔為你收集整理的用java编写打印时间_编写一个java程序,读取系统时间,然后将时间用中文输出...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。