请求java动态小程序
滚动的小球或者图形的自动变形(圆变方,变三角),计算器,计时器之类……
可以用 j buider 运行的
万分感谢
请求java动态小程序
滚动的小球或者图形的自动变形(圆变方,变三角),计算器,计时器之类……
可以用 j buider 运行的
万分感谢
[code="java"]我编了个计时器:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Timer extends JFrame implements ActionListener,Runnable
{
private JTextField text_timer;
private JButton button_start,button_pause,button_stop;
private Thread TimerThread;
public int changedata(String str)
{
int x=(str.charAt(0)-48)*10+str.charAt(1)-48;
return x;
}
public void addone()
{
String str1=text_timer.getText(),strh,strm,strs,strl;
int h,m,s,l;
h=changedata(str1.substring(0,2));
m=changedata(str1.substring(3,5));
s=changedata(str1.substring(6,8));
l=changedata(str1.substring(9,11))+1;
if(l==100)
{
l=0;
s=s+1;
}
if(s==60)
{
s=0;
m=m+1;
}
if(m==60)
{
m=0;
h=h+1;
}
if(h<10)
{
strh="0"+h;
}
else
{
strh=""+h;
}
if(m<10)
{
strm="0"+m;
}
else
{
strm=""+m;
}
if(s<10)
{
strs="0"+s;
}
else
{
strs=""+s;
}
if(l<10)
{
strl="0"+l;
}
else
{
strl=""+l;
}
text_timer.setText(strh+":"+strm+":"+strs+":"+strl);
}
public Timer()
{
super("计时器");
this.setSize(200,100);
this.setLocation(300,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new GridLayout(2,1));
text_timer=new JTextField("00:00:00:00");
button_start=new JButton("start");
button_pause=new JButton("pause");
button_stop=new JButton("stop");
this.add(text_timer);
this.add(button_start);
this.add(button_pause);
this.add(button_stop);
text_timer.addActionListener(this);
button_start.addActionListener(this);
button_pause.addActionListener(this);
button_stop.addActionListener(this);
TimerThread=new Thread(this);
this.setVisible(true);
}
public void run()
{
while(TimerThread.isAlive()&&!TimerThread.isInterrupted())
{
try
{
TimerThread.sleep(10);
addone();
}
catch(InterruptedException e)
{
break;
}
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button_start)
{
button_pause.setEnabled(true);
button_start.setEnabled(false);
button_stop.setEnabled(true);
TimerThread=new Thread(this);
TimerThread.setPriority(10);
TimerThread.start();
}
if(e.getSource()==button_pause)
{
button_pause.setEnabled(false);
button_start.setEnabled(true);
button_stop.setEnabled(true);
TimerThread.interrupt();
}
if(e.getSource()==button_stop)
{
TimerThread.interrupt();
button_pause.setEnabled(false);
button_start.setEnabled(true);
button_stop.setEnabled(false);
text_timer.setText("00:00:00:00");
}
}
public static void main(String arg[])
{
new Timer();
}
}
[/code]