JAVA中七段码 想画七段码,但是不知道具体用什么函数?求解 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用Graphics2D自己画罗……楼主想画华丽点的,还是想画个简单点的 写了个例子给楼主参考下import java.awt.Graphics;import javax.swing.JFrame;import javax.swing.JPanel;public class SevenLight extends JFrame { private MyPanel pnlMain; public SevenLight() { super(); initialize(); } private void initialize() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(400, 300); this.setLocationRelativeTo(null); pnlMain = new MyPanel(); this.getContentPane().add(pnlMain); } public static void drawSeven(Graphics g, int x, int y, int num) { switch (num) { case 1: g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); break; case 2: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 3: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 4: g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); break; case 5: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 6: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x, y+42, 8, 32, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 7: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); break; case 8: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x, y+42, 8, 32, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 9: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x+6, y+36, 32, 8, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; case 0: default: g.drawRoundRect(x+6, y, 32, 8, 8, 8); g.drawRoundRect(x, y+6, 8, 32, 8, 8); g.drawRoundRect(x+36, y+6, 8, 32, 8, 8); g.drawRoundRect(x, y+42, 8, 32, 8, 8); g.drawRoundRect(x+36, y+42, 8, 32, 8, 8); g.drawRoundRect(x+6, y+72, 32, 8, 8, 8); break; } } class MyPanel extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); drawSeven(g, 1, 1, 0); drawSeven(g, 51, 1, 1); drawSeven(g, 101, 1, 2); drawSeven(g, 151, 1, 3); drawSeven(g, 201, 1, 4); drawSeven(g, 1, 101, 5); drawSeven(g, 51, 101, 6); drawSeven(g, 101, 101, 7); drawSeven(g, 151, 101, 8); drawSeven(g, 201, 101, 9); } } public static void main(String[] args) { SevenLight frame = new SevenLight(); frame.setVisible(true); }} JDBC相关的问题 求解:不用数据库,用程序实现数据的统计: getSource() 属于哪个类? 关于unicode编码 散分----马上找工作,想找JAVA方面的相关职业,最近比较迷茫,希望各位指点 请问如何用java实现文件的拷贝? String和toString()的问题 初学者请教:编写计算器程序中遇到的问题,50分求教! 有关java的白痴问题 这是什么问题 一个绘图的程序。看看哪错了? java中如何实现数据库数据循环显示
楼主想画华丽点的,
还是想画个简单点的
import java.awt.Graphics;import javax.swing.JFrame;
import javax.swing.JPanel;public class SevenLight extends JFrame {
private MyPanel pnlMain;
public SevenLight() {
super();
initialize();
}
private void initialize() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setLocationRelativeTo(null);
pnlMain = new MyPanel();
this.getContentPane().add(pnlMain);
}
public static void drawSeven(Graphics g, int x, int y, int num) {
switch (num) {
case 1:
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
break;
case 2:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 3:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 4:
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
break;
case 5:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 6:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 7:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
break;
case 8:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 9:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+36, 32, 8, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
case 0:
default:
g.drawRoundRect(x+6, y, 32, 8, 8, 8);
g.drawRoundRect(x, y+6, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+6, 8, 32, 8, 8);
g.drawRoundRect(x, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+36, y+42, 8, 32, 8, 8);
g.drawRoundRect(x+6, y+72, 32, 8, 8, 8);
break;
}
}
class MyPanel extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawSeven(g, 1, 1, 0);
drawSeven(g, 51, 1, 1);
drawSeven(g, 101, 1, 2);
drawSeven(g, 151, 1, 3);
drawSeven(g, 201, 1, 4);
drawSeven(g, 1, 101, 5);
drawSeven(g, 51, 101, 6);
drawSeven(g, 101, 101, 7);
drawSeven(g, 151, 101, 8);
drawSeven(g, 201, 101, 9);
}
}
public static void main(String[] args) {
SevenLight frame = new SevenLight();
frame.setVisible(true);
}
}