javachxy 2012-03-13 22:03
浏览 223
已采纳

求小程序

请求java动态小程序

滚动的小球或者图形的自动变形(圆变方,变三角),计算器,计时器之类……

可以用 j buider 运行的

万分感谢

  • 写回答

4条回答 默认 最新

  • long13131462101 2012-03-13 22:05
    关注

    [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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条