清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
/** * */ package com.suziwen import com.trolltech.qt.core.QPoint import com.trolltech.qt.core.QTime import com.trolltech.qt.core.QTimer import com.trolltech.qt.gui.QApplication import com.trolltech.qt.gui.QColor import com.trolltech.qt.gui.QHideEvent import com.trolltech.qt.gui.QPaintEvent import com.trolltech.qt.gui.QPainter import com.trolltech.qt.gui.QPen import com.trolltech.qt.gui.QPolygon import com.trolltech.qt.gui.QShowEvent import com.trolltech.qt.gui.QWidget /** * @author suziwen * */ class Clock extends QWidget { QTimer qtimer = new QTimer(); static def hourHand = new QPolygon([new QPoint(7,8),new QPoint(-7,8),new QPoint(0,-30)]); static def minuteHand = new QPolygon([new QPoint(7,8),new QPoint(-7,8),new QPoint(0,-70)]); static def secondHand = new QPolygon([new QPoint(3,8),new QPoint(-3,8),new QPoint(0,-90)]); static def hourColor = new QColor(127,0,127); static def minuteColor = new QColor(0,129,129,129); static def secondColor = new QColor(0,100,100,100); Clock(){ super(); qtimer.timeout.connect(this, "update()"); } void hideEvent (QHideEvent event){ qtimer.stop(); } void showEvent(QShowEvent event){ qtimer.start(1000); } void paintEvent(QPaintEvent e){ def side = Math.min(this.width(),this.height()); def time = QTime.currentTime(); def painter = new QPainter(this); painter.translate(this.width()/2, this.height()/2); painter.setRenderHint(QPainter.RenderHint.Antialiasing); painter.scale(side/200, side/200); painter.setPen(QPen.NoPen); painter.setBrush(hourColor); painter.save(); painter.rotate(30.0*(time.hour() + time.minute()/60.0)); painter.drawConvexPolygon(hourHand); painter.restore(); painter.setPen(hourColor); for( def i in 0..12){ painter.drawLine(0, 92, 0, 96); painter.rotate(30.0); } painter.setPen(QPen.NoPen); painter.setBrush(minuteColor); painter.save(); painter.rotate(6.0*(time.minute() + time.second()/60.0)); painter.drawConvexPolygon(minuteHand); painter.restore(); painter.setPen(minuteColor); for(def i in 0..60){ if(i % 5 != 0 ){ painter.drawLine(0, 94, 0, 96); } painter.rotate(6.0); } painter.setPen(QPen.NoPen); painter.setBrush(secondColor); painter.save(); painter.rotate(6.0*time.second()); painter.drawConvexPolygon(secondHand); painter.restore(); } static main(args) { QApplication app = new QApplication(args); def clock = new Clock(); clock.resize(500, 500); clock.show(); app.exec(); } }