交通信号灯
来源:互联网 发布:华为p8淘宝打不开 编辑:程序博客网 时间:2024/06/11 19:39
编写程序,模拟交通信号灯。程序让用户从红、黄、绿三色灯中选择一种。当选
择一个单选按钮后,相应的灯被打开,并且一次只能亮一种灯。如下图所示:
import java.awt.*;import javax.swing.*;public class Car extends JFrame { public static void main(String[] args) { JFrame frame = new Car(); frame.setSize(300, 300); frame.setTitle("Circle"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); // Center the frame frame.setVisible(true); } public Car() { add(new PieChart1()); }}class PieChart1 extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); int w = getWidth(); int h = getHeight(); int xCenter = w / 2; int yCenter = h / 2; int radius = (int)(Math.min(w, h) * 0.8 / 2); int x = xCenter - radius; int y = yCenter - radius; g.setColor(Color.red); g.fillArc(x, y, 2 * radius, 2 * radius, 0, (int)(20 * 360 / 100)); g.setColor(Color.black); g.drawString("Projects -- 20%", (int)(xCenter + radius*Math.cos(2 * Math.PI * 0.1)), (int)(yCenter - radius*Math.sin(2 * Math.PI * 0.1))); g.setColor(Color.blue); g.fillArc(x, y, 2 * radius, 2 * radius, (int)(20 * 360 / 100), (int)(10 * 360 / 100)); g.setColor(Color.black); g.drawString("Quizzes -- 10%", (int)(xCenter + radius * Math.cos(2 * Math.PI * 0.25)), (int)(yCenter - radius * Math.sin(2 * Math.PI * 0.25))); g.setColor(Color.green); g.fillArc(x, y, 2 * radius, 2 * radius, (int)(30*360/100), (int)(30 * 360 / 100)); g.setColor(Color.black); g.drawString("Midterms -- 30%", (int)(xCenter + radius*Math.cos(2 * Math.PI * 0.45)) - 40, (int)(yCenter - radius*Math.sin(2 * Math.PI * 0.45))); g.setColor(Color.white); g.fillArc(x, y, 2 * radius, 2 * radius, (int)(60 * 360 / 100), (int)(40 * 360 / 100)); g.setColor(Color.black); g.drawString("Final -- 40%", (int)(xCenter + radius*Math.cos(2 * Math.PI * 0.8)), (int)(yCenter - radius*Math.sin(2 * Math.PI * 0.8))); }}
0 0
- 交通信号灯
- 交通信号灯
- 单片机交通信号灯程序
- 模拟交通信号灯
- 黑马程序员--交通信号灯
- 交通信号灯系统
- 交通信号灯Proteus仿真
- java(交通信号灯系统)
- JS实现交通信号灯
- 智能交通信号灯管理系统
- 小项目_交通信号灯
- (黑马程序员)交通信号灯系统
- 交通信号灯管理系统总结
- Andrino 卡片3交通信号灯
- 模拟交通信号灯(Java)
- 黑马程序员_java 交通信号灯系统
- 黑马程序员:交通信号灯(java实现)
- 黑马程序员——交通信号灯问题
- 采矿工程师的程序人生:从0.5K到年入百万的成长之路
- 假期训练——POJ - 1163 The Triangle dp
- U3D贴图格式 GENERATE MIP MAPS
- bzoj 1001 最小割
- 《离经叛道》-读书摘要(1)
- 交通信号灯
- Flink运行时之TaskManager执行Task
- 领域专用语言DSL简介
- 程序的健壮性
- 史上最简单的 Spring MVC 教程(二)
- 多文件、多图片上传时遇到Error Initializing Session的解决办法
- centos6.6搭建apache+mysql+php环境(3)
- Pie HDU - 1969
- 蓝桥杯-查找整数