求小程序

问题描述

请求java动态小程序 滚动的小球或者图形的自动变形(圆变方,变三角),计算器,计时器之类…… 可以用 j buider 运行的 万分感谢 问题补充:我试试高级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(); } }
解决方案二:
滚动的小球,这个网上很多啊,随便百度一个就有了,JBUILDER只是一个开发IDE吧,只要是JAVA的多能运行 贴个滚动的小球代码//Checkers.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;//Checkers类public class Checkers extends JFrame implements ActionListener { //变量定义 CheckersPanel checkers = new CheckersPanel(); JButton startButton = new JButton("start"); JButton stopButton = new JButton("stop"); //构造函数 public Checkers(){ super("Checkers"); setSize(210,170); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel(); BorderLayout border = new BorderLayout(); pane.setLayout(border); pane.add(checkers,"Center"); JPanel buttonPanel = new JPanel(); startButton.addActionListener(this); buttonPanel.add(startButton); stopButton.addActionListener(this); stopButton.setEnabled(false); buttonPanel.add(stopButton); pane.add(buttonPanel,"South"); setContentPane(pane); show(); } //响应用户动作 public void actionPerformed(ActionEvent evt){ if(evt.getSource() == startButton){ checkers.playAnimation(); startButton.setEnabled(false); stopButton.setEnabled(true); }else{ checkers.stopAnimation(); startButton.setEnabled(true); stopButton.setEnabled(false); } } //主函数 public static void main(String[] arguments){ Checkers ck = new Checkers(); }}//CheckersPanel类class CheckersPanel extends JPanel implements Runnable{ //变量定义 private Thread runner; int xPos = 5; int xMove = 4; //播放动画 void playAnimation(){ if (runner ==null);{ runner = new Thread(this); runner.start(); } } //停止动画 void stopAnimation(){ if (runner !=null);{ runner = null; } } //运行 public void run(){ Thread thisThread = Thread.currentThread(); while(runner ==thisThread){ xPos += xMove; if ((xPos > 105)|(xPos < 5)) xMove *= -1; repaint(); try{ Thread.sleep(100); }catch(InterruptedException e){} } } //画图形 public void paintComponent(Graphics comp){ Graphics2D comp2D = (Graphics2D)comp; comp2D.setColor(Color.blue); comp2D.fillRect(0,0,100,100); comp2D.setColor(Color.white); comp2D.fillRect(100,0,100,100); comp2D.setColor(Color.black); comp2D.fillOval(xPos,5,90,90); }}
解决方案三:
白天上班,晚上还得忙。。。哎
解决方案四:
果然如此,^_^

时间: 2024-07-30 05:21:02

求小程序的相关文章

结果是什么啊-一个小程序,求解答啊

问题描述 一个小程序,求解答啊 在别人文章里看到的程序 程序的输出结果是什么,why? #include int main() { int a[5] = {1,2,3,4,5}; int p = (int)(&a + 1); printf("%d, %dn", *(a + 1), *(p -1)); } 解决方案 int a[5] = {1,2,3,4,5}; int* p = (int*)(&a + 1); printf("%d, %dn", *(

VC++的win32小程序内存泄漏,求高手解答

问题描述 VC++的win32小程序内存泄漏,求高手解答 做的一个简单的交通模拟小程序,用三个定时器分别产生 汽车处理消息,红绿灯更换消息和汽车随机产生消息.但是最后程序内存越跑越大.求高手解答.http://download.csdn.net/detail/hdwbdbsm/6724747这个是程序的下载地址,求高手.

日历-求帮写一个java小程序

问题描述 求帮写一个java小程序 读取txt文件,文件中有一个8位的日期(任意),读出并打印此日期开始的一个月日历 解决方案 String s="20160221"; SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); try { Date startDate=sdf.parse(s); Calendar c2=Calendar.getInstance(); Calendar c=Calendar.getI

python-Python小程序求解答+++

问题描述 Python小程序求解答+++ 这是什么意思啊,我是照着书上来的啊. 解决方案 print只能接收一个参数,你需要先组合成一个字符串,然后给print 解决方案二: 标点符号的问题,所有的标点符号应该是英文状态下的. 解决方案三: 按照你的代码复制下来,我这里执行下来是正确,你重新看看,是不是你哪里的标点符号没写好.也贴上我的测试代码: def print_more(required1,required2,*args): print("required1:",required

c++-初学C++ 一个小程序 求大神帮忙看下

问题描述 初学C++ 一个小程序 求大神帮忙看下 //分秒显示函数 #include using namespace std; //全局引用std命名空间 void showTime(int ,int); int main() { int hours =0 , mins = 0;//定义且初始化分 和秒 cout << "Input the hour "; cin >> hours; cout << "Input the mins &quo

c#小程序换机子不能直接运行.EXE。需重新编译,求解答?

问题描述 c#小程序换机子不能直接运行.EXE.需重新编译,求解答? using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Management; namespace getid{ public partial

java源码-竞赛小程序,我不太会写,求大神教我

问题描述 竞赛小程序,我不太会写,求大神教我 这个题目不太会写,求大神教思路给源码?????????????????????????? 解决方案 http://blog.csdn.net/ocean20/article/details/5017538 解决方案二: 解决问题分步走: 1.判断是否为方阵,判断每行相邻数据是否有相等的,有即非方阵,判断行数据相等应该会不需提供代码: 2.判断是否标准反正,判断第一行相邻数据是否差值等于1,判断第一列相邻数据差值是否等于1,应该会不需提供代码.

java容器 collection-下面这个小程序打印出的为什么是true和false啊,求大神分析一下,万分感谢~

问题描述 下面这个小程序打印出的为什么是true和false啊,求大神分析一下,万分感谢~ public class BasicContainer { public static void main(String[] args) { Collection c = new HashSet(); c.add("hello"); c.add(new Name("lu","dongdong")); c.add(new Integer(100)); Sys

编程-有一个小程序急用,但是我不会编译,求大神帮忙编译啊~~~太感谢!!

问题描述 有一个小程序急用,但是我不会编译,求大神帮忙编译啊~~~太感谢!! 如题,是一个小程序,用的是自己的makefile,下载下来了但是不会编译啊~~~~要exe格式的,那位大神可以帮忙编译出来真是太感激不尽!或者教一下我~~~太感谢了!编译好请发zhaojialiangsuper@126.com~源码地址 源码:https://releases.stm32flash.googlecode.com/git/stm32flash-0.4.tar.gz 解决方案 http://download