
正文
流水灯java语言代码 流水灯数组代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java一个关于light类【灯】的编程
建议用eclipse工具流水灯java语言代码,这样流水灯java语言代码的一个类,用工具很快就生成流水灯java语言代码了。
public
class
light
{
private
int
watts;
private
boolean
indicator;
/**
*
@param
watts
*
:创建具有watts瓦的对象
*/
public
light(int
watts)
{
this.watts
=
watts;
}
/**
*
@param
watts
*
:创建具有watts瓦的对象
*
*
@param
indicator
*
:创建具有watts瓦,开关状态
为indicator的对象
*/
public
light(int
watts,
boolean
indicator)
{
super();
this.watts
=
watts;
this.indicator
=
indicator;
}
/**
*
开灯,即灯的状态置为开
*/
public
void
swithoh()
{
this.indicator
=
true;
}
/**
*
关灯
*/
public
void
printlnoff()
{
this.indicator
=
false;
}
/**
*
输出灯的瓦数信息和开灯的状态·
*/
public
void
printlnfo()
{
system.out.println("灯的瓦数是:"
+
this.watts
+
"\n开关状态是:"
+
this.indicator);
}
}
相关问答
Q1: java写的灯泡程序
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Ellipse2D;
public class test extends JFrame {
JComboBox cb = new JComboBox();
JPanel p1 = new JPanel();
drawPanel p2 = new drawPanel();
String str = "";
public test()
{
this.setLayout(new BorderLayout());
p1.setLayout(new GridLayout(1,1));
cb.addItem("红灯");
cb.addItem("绿灯");
cb.addItem("黄灯");
cb.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getItem().equals("红灯"))
{
p2.repaint();
p2.i = 1;
}
if(arg0.getItem().equals("绿灯"))
{
p2.i = 2;
p2.repaint();
}
if(arg0.getItem().equals("黄灯"))
{
p2.i = 3;
p2.repaint();
}
}
});
p1.add(cb);
this.add(p1,BorderLayout.NORTH);
this.add(p2,BorderLayout.CENTER);
this.setSize(200,400);
this.setVisible(true);
}
class drawPanel extends JPanel
{
int i = 0;
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
Ellipse2D circle1 = new Ellipse2D.Double();
Ellipse2D circle2 = new Ellipse2D.Double();
Ellipse2D circle3 = new Ellipse2D.Double();
circle1.setFrameFromCenter(90,60,130,100);
if(i == 1)
{
g2.setColor(Color.RED);
}else g2.setPaint(Color.GRAY);
g2.fill(circle1);
circle2.setFrameFromCenter(90,160,130,200);
if(i == 2)
{
g2.setColor(Color.GREEN);
}else g2.setColor(Color.GRAY);
g2.fill(circle2);
circle3.setFrameFromCenter(90,260,130,300);
if(i == 3)
{
g2.setPaint(Color.YELLOW);
}else g2.setPaint(Color.GRAY);
g2.fill(circle3);
}
}
public static void main(String[] args) {
test t = new test();
}
}
Q2: 51单片机八个灯的流水灯代码
51单片机八个灯的流水灯代码:
1、用精确定时的方法,设置流水灯运行时的时间间隔,延时时间为500MS。
2、#include "reg51.h"首先写出单片机的头函数。
3、#include "intrins.h"输入位移函数。
4、unsigned int count=0,led;定义函数。
5、输入主函数,定义单片机的端口,写入延时函数。
编辑推荐
对于刚接触单片机的学习者,似乎都很迷茫,C语言、汇编语言、电路、开发板,不知道从哪儿开始学起。其实在学习单片机原理与应用系统开发时,只有在学习一些理论知识的基础上,多阅读单片机应用系统开发案例,注重单片机应用系统开发实践训练,才能透彻地理解和掌握单片机结构与原理,才能更快更好地掌握单片机应用知识和单片机应用系统开发技能。
关于流水灯java语言代码和流水灯数组代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







