| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 501 人关注过本帖
标题:嵌入到HTML
只看楼主 加入收藏
josephzzq
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2007-3-18
收藏
 问题点数:0 回复次数:2 
嵌入到HTML

请问一下高手,下面是Clock.java的代码,请问一下怎样可以把它嵌入到HTML的代码中去呢??




package clock;

import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Clock extends JFrame implements Runnable{
public Clock()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Thread thread1;//定义线程对象
Color handColor;//定义表示时针、分针和秒针颜色的变量
Color numberColor;//定义表示时钟数字颜色的变量

JLabel jLabel1 = new JLabel();
public void init()
{
int x,y;
handColor = Color.blue;
numberColor = Color.darkGray;
setBackground(Color.white);
}
//paint is the main part of the program
public void paint(Graphics g)
{
int xh,yh,xm,ym,xs,ys,s = 0,m = 10,h=0,xpoint,ypoint;
int day,month,year,weekday;
Calendar c1 = Calendar.getInstance();
//或的当前时间
s = c1.get(Calendar.SECOND);
m = c1.get(Calendar.MINUTE);
h = c1.get(Calendar.HOUR_OF_DAY);
//获得当前日期
day = c1.get(Calendar.DATE);
month = c1.get(Calendar.MONTH) + 1;
year = c1.get(Calendar.YEAR);
weekday = c1.get(Calendar.DAY_OF_WEEK)-1;
//在标签控件上显示日期和时间
jLabel1.setText(" "+year+"年"+month+"月"+day+"日"+" "+"星期"+weekday+" "+h+":"+m+":"+s);
xpoint = 130;
ypoint = 100;
//计算时针、分针和秒针的位置
xs = (int)(Math.cos(s * 3.14f/30 -3.14f/2) * 45 + xpoint);
ys = (int)(Math.sin(s * 3.14f/30 -3.14f/2) * 45 + ypoint);
xm = (int)(Math.cos(m * 3.14f/30 -3.14f/2) * 40 + xpoint);
ym = (int)(Math.sin(m * 3.14f/30 -3.14f/2) * 40 + ypoint);
xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 +xpoint);
yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 +ypoint);
//绘制时钟背景
g.setColor(handColor);
g.clearRect(0,0,260,200);
g.drawOval(xpoint/2+10,ypoint/2-5,110,110);
g.setColor(numberColor);
g.drawString("9",xpoint-45,ypoint+3);
g.drawString("3",xpoint+40,ypoint+3);
g.drawString("12",xpoint-5,ypoint-37);
g.drawString("6",xpoint-3,ypoint+45);
g.setColor(getBackground());

g.setColor(numberColor);
g.drawString("",5,125);
//绘制时针、分针和秒针
g.drawLine(xpoint,ypoint,xs,ys);
g.setColor(handColor);
g.drawLine(xpoint,ypoint,xm,ym);
g.drawLine(xpoint,ypoint,xh,yh);
}

//定义线程的run方法
public void run()
{
Thread me = Thread.currentThread();
while(thread1 == me)
{
try
{
Thread.currentThread().sleep(100);
}
catch(InterruptedException e)
{

}
repaint();
}
}
//开始执行线程
public void start()
{
thread1 = new Thread(this);
thread1.start();
}
//停止线程
public void stop()
{
thread1 = null;
}
public void update(Graphics g)
{
paint(g);
}
private void jbInit() throws Exception
{
this.getContentPane().add(jLabel1,BorderLayout.SOUTH);
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if(e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}

}

public static void main(String[] args) {
Clock clock1 = new Clock();
clock1.init();
clock1.start();
clock1.setSize(280,230);
clock1.setResizable(false);
clock1.setVisible(true);

}
}


搜索更多相关主题的帖子: HTML 
2007-05-16 13:55
支离破碎
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:737
专家分:0
注 册:2007-1-4
收藏
得分:0 
你做成applet就可以了

人生漂泊無依,有如浮萍菱花,隨水飄流,你会在我这里停留吗?
[url=http://51mynet.]http://51mynet.[/url]
2007-05-17 09:22
china008
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-5-8
收藏
得分:0 
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
code = "***.class"
width = "500"
height = "300"
>
</APPLET>
</CENTER>
</BODY>
</HTML> 用textpad 写进去, 存成***.html ***.class 是你编译后的Class文件,放到一起就可以了
浏览器需要支持Applet

2007-05-19 11:43
快速回复:嵌入到HTML
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015706 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved