<<Java语言程序设计>>基础篇 Exercise12_9 随机显示3张牌
2014-02-19 23:04
465 查看
import javax.swing.*; import java.awt.*; public class Exercise12_9 extends JFrame{ public Exercise12_9(){ setLayout(new GridLayout(1,3,2,2)); int a = (int)(Math.random()*65); int t = (int)(Math.random()*65); while (t == a) t = (int)(Math.random()*65); int b = t; t = (int)(Math.random()*65); while ((t == a) || (t == b)) t = (int)(Math.random()*65); int c = t; ImageIcon imagea = new ImageIcon("image/card/" + a + ".png"); ImageIcon imageb = new ImageIcon("image/card/" + b + ".png"); ImageIcon imagec = new ImageIcon("image/card/" + c + ".png"); add(new JLabel(imagea)); add(new JLabel(imageb)); add(new JLabel(imagec)); } public static void main(String[] args){ Exercise12_9 frame = new Exercise12_9(); frame.setTitle("Exercise12_9"); frame.setSize(1200,400); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
相关文章推荐
- <<Java语言程序设计>>进阶篇 Exercise22_3
- <<Java语言程序设计>>进阶篇 Exercise22_7
- <<Java语言程序设计>>进阶篇 Exercise22_5
- <<Java语言程序设计>>进阶篇 Exercise8_7
- _Java基础<二>_Java语言基础组成(上)
- 黑马程序员<java基础<面向对象基础知识点>>
- Java基础语法<十二> 泛型程序设计
- 黑马程序员<java基础<静态与非静态>>
- 黑马程序员<java基础<面向对象(封装,继承,多态,抽象)>>
- 黑马程序员<java基础<多线程同步异步问题>>
- Java基础知识<3>-面向对象程序设计
- 黑马程序员<java基础<多线程>>
- <<高级语言程序设计>>读书笔记
- 黑马程序员<java基础<常用类特点>>
- _Java基础<三>_Java语言基础组成(下)
- Java系列学习笔记------Java语言基础<2>
- 黑马程序员<java基础<选择,冒泡,折半,进制转换知识点>>
- 黑马程序员-Java语言基础– Map<K,V> 第16-17天
- Spring基础_在XML配置中引用JavaConfig<五>
- 理解Java 泛型 :<? super T> 和<? extends T>