用java实现一个风扇的转动,具体代码如下,可是运行却不转动,请高手帮帮忙

用java实现一个风扇的转动,具体代码如下,可是运行却不转动,请高手帮帮忙,第1张

class FengS

{

int fd = 0

int ft = 0

FengS(int d, int t)

{

this.fd = d

this.ft = t

}

void run()

{

if(fd == 0)

{

System.out.println("风扇停止运行")

}

else if (fd == 1)

{

System.out.println("风扇一档运行")

}

else if (fd == 2)

{

System.out.println("风扇二档运行")

}

else if (fd == 3)

{

System.out.println("风扇三档运行")

}

else

System.out.println("风扇档数出错")

}

void tRun()

{

if (ft == -1)

{

this.run()

}

else if(60>= ft &&ft>0)

{

for (int a = 0a<ft )

{

this.run()

System.out.println("剩余时间:"+ft+"分")

ft--

}

System.out.println("风扇停止运行")

}

else if (ft == 0)

{

System.out.println("风扇停止运行")

}

else

System.out.println("风扇定时出错")

}

}

class Feng

{

public static void main(String[] args)

{

FengS fs = new FengS(3,60)

fs.tRun()

}

}

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(time>0)

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)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12042684.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存