Java: I hope it's not the alarm clock that wakes you up every day, but a dream !

 

 

Code design
import java.awt.*; import java.util.Date; import javax.swing.*; public class
Clock extends JComponent{ /** * */ private static final long serialVersionUID =
-5379472973578609775L; private Font f = new Font(" Microsoft YaHei ",Font.PLAIN,15); private
Font f2 = new Font(" Microsoft YaHei ",Font.BOLD,15); private JLabel l = new
JLabel(" current time :"); private JLabel display = new JLabel(); private JLabel display2
= new JLabel(""); private int hour = 0; private int min = 0; private int sec =
0; private Date now = new Date(); private Graphics2D g; final double PI =
Math.PI; private String strTime = "" ; @SuppressWarnings("deprecation") public
Clock(){ add(l); l.setBounds(120, 320, 80, 20); l.setFont(f); add(display);
display.setBounds(195, 320, 80, 20); display.setFont(f);
display.setBorder(BorderFactory.createLineBorder(Color.black)); add(display2);
display2.setBounds(90, 350, 250, 20); display2.setFont(f); hour =
now.getHours(); min = now.getMinutes(); sec = now.getSeconds();
setVisible(true); } public void paintComponent(Graphics g1){ double x,y;
super.paintComponent(g1); g = (Graphics2D) g1; // Anti aliasing switch on
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); // Drawing dial g.setPaint(new
GradientPaint(5,40,Color.red,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); // painting 60 Points
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)// painting 3,6,9,12 Four big points { g.fillOval((int)(x - 5 + 200),(int)(y - 5 + 165),10,10); }
else// Other small points { g.fillOval((int)(x - 2.5 + 200),(int)(y - 2.5 + 165),3,3); } }
// Draw four numbers g.setFont(f2); g.drawString("3", 300, 171); g.drawString("6", 195,
273); g.drawString("9", 91, 171); g.drawString("12", 195, 68);
//g.drawString("12", 190, 68); // Draw the hour hand , minute hand , second hand paint_HourPointer(hour*3600 + min*60
+ sec,g);// The number of seconds the clock goes by paint_MinutePointer(min*60 + sec,g);// Seconds passed by minute hand
paint_SecondPointer(sec,g);// Seconds passed by the second hand } public void showUI(){ new Thread() {
@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,Graphics2D g){//second Represents the relative hour of the current time 00:00:00 How many seconds did it take
double x,y,angle; angle = second * PI / 21600;// The speed of the hour hand is PI/21600 (rad/s) x = 200
+ 60 * Math.sin(angle); y = 165 - 60 * Math.cos(angle); g.setStroke( new
BasicStroke(5,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND)); g.setPaint(new
GradientPaint(200,165,Color.red,260,165,Color.blue,true)); g.drawLine(200, 165,
(int)x, (int)y); } public void paint_MinutePointer(int second,Graphics2D
g){//second Represents the minute hand relative to the current time 00:00:00 How many seconds did it take double x,y,angle; angle = second * PI /
1800;// The speed of minute hand is PI/1800 (rad/s) x = 200 + 80 * Math.sin(angle); y = 165 - 80 *
Math.cos(angle); g.setStroke( new
BasicStroke(3,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND)); g.setPaint(new
GradientPaint(200,165,Color.magenta,280,165,Color.blue,true)); g.drawLine(200,
165, (int)x, (int)y); } public void paint_SecondPointer(int second,Graphics2D
g){//second Represents the second hand relative to the current time 00:00:00 How many seconds did it take double x,y,x1,y1,x2,y2,x3,y3,angle; double
cos = 90 / Math.sqrt(8125);//90*90+5*5 double sin = 5 / Math.sqrt(8125); angle
= second * PI / 30;// The speed of the hour hand is PI/30 (rad/s) x = 200 + 95 * Math.sin(angle); y =
165 - 95 * Math.cos(angle); x1 = 200 + 20 * Math.sin(angle + PI); y1 = 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);// Abscissa co[1] = 115 * Math.sin(angle);// Ordinate 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 + ":"; else
strTime = "" + hour_temp + ":"; if(min_temp < 10) strTime = strTime + "0" +
min_temp + ":"; else strTime = strTime + "" + min_temp + ":"; if(sec < 10)
strTime = strTime + "0" + sec_temp; else strTime = strTime + "" + sec_temp;
// Set the display time on the form date = " " + (now.getYear()+1900) + " year " + (now.getMonth()+1) + " month "
+ now.getDate() + " day " + " week " ; switch (now.getDay()) { case 1: date += " One ";
break; case 2: date += " Two "; break; case 3: date += " Three "; break; case 4: date +=
" Four "; break; case 5: date += " Five "; break; case 6: date += " Six "; break; case 7:
date += " day "; break; } date += " CST"; //Chinese standard time strTime = " " +
strTime; display.setText(strTime); display2.setText(date); } public static void
main(String args[]){ Clock c = new Clock(); c.showUI(); JFrame f = new
JFrame("yunyaniu"); Image
img=Toolkit.getDefaultToolkit().getImage("image/logo Small .jpg");// Window icon
f.setIconImage(img); f.setSize(400,420); f.setResizable(false); f.add(c,
BorderLayout.CENTER); f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }
 

Technology
©2019-2020 Toolsou All rights reserved,
element-ui Of el-date-picker Component get value Thread.getContextClassLoader And Thread.getClassLoader() difference pytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%)( Essence )2020 year 7 month 21 day ASP.NET Core Use of global filters Programmer and architect Hua Shan Maximum security risk of cloud computing : Unclear safety responsibility exercises 11-5 Output string at specified position npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test_vue_0613@1.0.0 dev: Solutions to errors Keras Summary of training data loading ( Essence )2020 year 6 month 26 day C# Class library Enum( Extension method )