java中模拟风扇的代码 模拟风扇控制系统原理图
用java做个风扇,求帮助
import java.awt.event.ActionEvent;
目前创新互联已为千余家的企业提供了网站建设、域名、虚拟主机、网站托管维护、企业网站设计、绥芬河网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.applet.AudioClip;
public class Fan extends JFrame implements ActionListener{
static int time=1;
static int ti;
Timer time_1 = new Timer(100,this);
x1 x=new x1() ;
static TransPane jp;
JButton add=new JButton("加速");
JButton stop=new JButton("暂停/开始");
JButton low=new JButton("减速");
JButton dingshi=new JButton("定时1分钟");
JTextField TextIn = new JTextField("100");
JPanel p=new JPanel();
public Fan(){
super("旋销友宏转");
add(jp);
p.setLayout(new FlowLayout(FlowLayout.CENTER,30,30));
p.add(add);
p.add(stop);
p.add(low);
p.add(dingshi);
add(p,BorderLayout.SOUTH);
add.addActionListener(new ButtonHandler());
low.addActionListener(new ButtonHandler());
stop.addActionListener(new ButtonHandler());
dingshi.addActionListener(new ButtonHandler());
time_1=new Timer(1,x);
time_1.start();
}
class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==add){
if(time=0)
time++;
else if(time告凳0)
time--;
}else if(e.getSource()==low){
if(time0)
time--;
else if(time亏册0)
time++;
}else if(e.getSource()==stop){
if(time!=0){
ti=time;
time=0;}
else
time=ti;
}
else if(e.getSource()==dingshi){
if(time!=1){
ti=time;
time=1;}
else time++;
}
}
}
public static void main(String[] args){
jp=new TransPane();
Fan tran=new Fan();
tran.setSize(250,300);
tran.setVisible(true);
tran.pack();
}
public void actionPerformed(ActionEvent arg0) {
}
class x1 implements ActionListener{
public void actionPerformed(ActionEvent e){
TransPane t1=new TransPane();
jp.i+=time;
jp.repaint();
}
}
}
class TransPane extends JPanel{
int i=0;
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d=(Graphics2D) g;
int xCenter=getWidth()/2;
int yCenter=getHeight()/2;
int radius=(int)(Math.min(getWidth(),getHeight()*0.4));
int x=xCenter-radius;
int y=yCenter-radius;
AffineTransform trans=new AffineTransform();
g2d.fillArc(x,y,2*radius,2*radius,i,30); g2d.setColor(Color.red);
g2d.fillArc(x,y,2*radius,2*radius,i+60,30); g2d.setColor(Color.yellow);
g2d.fillArc(x,y,2*radius,2*radius,i+120,30); g2d.setColor(Color.green);
g2d.fillArc(x,y,2*radius,2*radius,i+180,30); g2d.setColor(Color.gray);
g2d.fillArc(x,y,2*radius,2*radius,i+240,30); g2d.setColor(Color.blue);
g2d.fillArc(x,y,2*radius,2*radius,i+300,30); g2d.setColor(Color.black);
}
JAVA一道题,有个小问题。
这涉及到作用域的问题,还有成员变量和类变量的问题。你定义的SLOW应该用static修饰,并应该是虚或李public的。如public static final int SLOW = 1;这样定义就ok了。引用的时候,用Fan.SLOW引团判用此变量差迟
名称栏目:java中模拟风扇的代码 模拟风扇控制系统原理图
文章出自:http://cdiso.cn/article/dspgpod.html