189 8069 5689

java非整型常量代码 java 非

java代码看不懂,求高手每句解释一下意思,非常感谢~~

package com.test;

成都创新互联公司专注于企业成都全网营销、网站重做改版、龙泉网站定制设计、自适应品牌网站建设、H5页面制作商城网站建设、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为龙泉等各大城市提供网站开发制作服务。

import java.awt.Graphics;

import java.util.Calendar;

import java.util.GregorianCalendar;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class MultiThreadClock extends JFrame { //继承JFrame

public MultiThreadClock() { //构造方法

ClockPanel jp_clock = new ClockPanel(); //一个自定义的Panel

add(jp_clock); //添加到frame

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置默认关闭模式

setSize(400, 400); //设置窗口或孙大小

this.setLocationRelativeTo(null);

setVisible(true); //设为可见

Thread ClockRun = new Thread(jp_clock);

ClockRun.start(); //线程启动

}

public static void main(String[] args) {

// TODO Auto-generatedmethod stub

new MultiThreadClock();

}

}

class ClockPanel extends JPanel implements Runnable { //一个自定义的继承了JPanel的有多毁渗线程特性的类

private double CenterX, CenterY; //看上去是坐标

private double Radius = 150; //半径

private double HPointX, HPointY, MPointX, MPointY, SPointX, SPointY; //看上去又是很多坐标

private int Year, Month, Day, WeekDay, Hour, Minute, Second; //年月日什么时分秒

private final double PI = 3.1415926;

public synchronized void paintComponent(Graphics g) { //这个方法是覆盖JPanel的绘制方法,用于在JPanel上画东西

super.paintComponent(g); //要首先调用一下父类方法

CenterX = this.getWidth() / 2; //设置坐标

CenterY = this.getHeight() / 2;

double HRadian = (PI / 6) * Hour + (PI / 360) * Minute + (PI / 21600) //三纤团脊句话貌似计算时分秒针的半径

* Second;

double MRadian = (PI / 30) * Minute + (PI / 1800) * Second;

double SRadian = (PI / 30) * Second;

HPointX = CenterX + Radius * 0.6 * Math.sin(HRadian); //这几句话貌似在算时分秒针的外圈坐标

HPointY = CenterY - Radius * 0.6 * Math.cos(HRadian);

MPointX = CenterX + Radius * 0.8 * Math.sin(MRadian);

MPointY = CenterY - Radius * 0.8 * Math.cos(MRadian);

SPointX = CenterX + Radius * Math.sin(SRadian);

SPointY = CenterY - Radius * Math.cos(SRadian);

g.drawOval((int) (CenterX - Radius), (int) (CenterY - Radius), //画圆

(int) (2 * Radius), (int) (2 * Radius));

g.drawString("12", (int) (CenterX), (int) (CenterY - Radius) + 10); //在钟表的圆圈位置写字 3 6 9 12啥的

g.drawString("3", (int) (CenterX + Radius) - 6, (int) (CenterY));

g.drawString("6", (int) (CenterX), (int) (CenterY + Radius));

g.drawString("9", (int) (CenterX - Radius), (int) (CenterY));

g.drawLine((int) (CenterX), (int) (CenterY), (int) (SPointX), //画时分秒的线

(int) (SPointY));

g.drawLine((int) (CenterX), (int) (CenterY), (int) (MPointX),

(int) (MPointY));

g.drawLine((int) (CenterX), (int) (CenterY), (int) (HPointX),

(int) (HPointY));

g.drawString(WeekDay + " " + Month + " " + Day + " " + Hour + ":"

+ Minute + ":" + Second + " " + Year, 20, 350); //写那个,字符表示的时间

}

@Override

public void run() {

// TODO Auto-generatedmethod stub

while (true) {

try {

setCurrentTime();

repaint(); //重新绘制当前panel上的图形

Thread.sleep(1000); //线程休眠1秒钟

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

public void setCurrentTime() {

Calendar calendar = new GregorianCalendar(); //获取当前时间

Year = calendar.get(Calendar.YEAR);

Month = calendar.get(Calendar.MONTH);

Day = calendar.get(Calendar.DAY_OF_MONTH);

WeekDay = calendar.get(Calendar.DAY_OF_WEEK);

Hour = calendar.get(Calendar.HOUR);

Minute = calendar.get(Calendar.MINUTE);

Second = calendar.get(Calendar.SECOND);

}

}

java中不存在byte/short型常量的表示法。但可以把一定范围内的int型常量赋

1、所谓常量,就是在程序运行时,不会被修改的量,在java中定义常量的表达式是声明物吵的时候加上 static final修饰符,表明该变量不可被修改,称之为常量

2、java中可以声明byte/short的常量,比如码岁:public static final byte a = 1;但是,byte的值必须在byte类型的范围内,即:-128~+127

3、java中的整数,像:1,2,234,1000等默认都是int类型的,在-128~+127范围内的值可以直接迟蚂睁赋值给byte类型,自动识别为byte,同理,在-32768~+32767之间值也可以直接赋值给short


当前文章:java非整型常量代码 java 非
当前路径:http://cdxtjz.cn/article/dsphipe.html

其他资讯