第六周作业
2016-05-07 22:02
323 查看
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashSet;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class choujiang extends JFrame {
private JPanel imagePanel, p2;
private ImageIcon background, anniu;
private JButton kaishi, one, second, third, four, five, six;
protected Object s;
public static int b = 1; public JTextField jt; public String text="记录:\n"; public void run() { System.out.println("1"); } public choujiang() { background = new ImageIcon("img/1.jpg");// 背景图片 anniu = new ImageIcon("img/2.png"); JLabel label = new JLabel(background);// 把背景图片显示在一个标签里面 label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight()); // //把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明 imagePanel = (JPanel) this.getContentPane(); imagePanel.setOpaque(false); // //内容窗格默认的布局管理器为BorderLayout kaishi = new JButton(anniu); kaishi.setSize(45, 40); kaishi.setLocation(168, 249); kaishi.setBackground(Color.yellow); kaishi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(b<=3){ b++; t t = new t(); t.run(); Random r = new Random(); int a = r.nextInt(6) + 1; chushihua(); if (a == 1) { one.setBackground(Color.yellow); jt.setText("恭喜您获得了一等奖"); text=text+"恭喜您获得了一等奖\n"; } else if (a == 2) { second.setBackground(Color.yellow); jt.setText("恭喜您获得了二等奖"); text=text+"恭喜您获得了二等奖\n"; } else if (a == 3) { third.setBackground(Color.yellow); jt.setText("恭喜您获得了三等奖"); text=text+"恭喜您获得了三等奖\n"; } else if (a == 4) { four.setBackground(Color.yellow); jt.setText("恭喜您获得了优秀奖"); text=text+"恭喜您获得了优秀奖\n"; } else if (a == 5) { five.setBackground(Color.yellow); jt.setText("恭喜您获得了再抽一次"); text=text+"恭喜您获得了再抽一次\n"; } else if (a == 6) { six.setBackground(Color.yellow); jt.setText("别灰心,下次加油"); text=text+"别灰心,下次加油\n"; } }else{ JOptionPane.showMessageDialog(imagePanel, "您的抽奖次数已经用完请点击退出!","关闭!",JOptionPane.WARNING_MESSAGE); } } }); Random random = new Random(); Object[] values = new Object[6]; HashSet hashSet = new HashSet(); for(int i = 0;i < values.length;i++){ int number = random.nextInt(1000) + 1; hashSet.add(number); } values = hashSet.toArray(); one = new JButton("一"); one.setMargin(new Insets(0, 0, 0, 0)); one.setSize(30, 30); one.setLocation(108, 174); one.setBackground(Color.PINK); second = new JButton("二"); second.setMargin(new Insets(0, 0, 0, 0)); second.setSize(30, 30); second.setLocation(219, 162); second.setBackground(Color.PINK); third = new JButton("三"); third.setMargin(new Insets(0, 0, 0, 0)); third.setSize(30, 30); third.setLocation(305, 249); third.setBackground(Color.PINK); four = new JButton("四"); four.setMargin(new Insets(0, 0, 0, 0)); four.setSize(30, 30); four.setLocation(248, 332); four.setBackground(Color.PINK); five = new JButton("五"); five.setMargin(new Insets(0, 0, 0, 0)); five.setSize(30, 30); five.setLocation(128, 349); five.setBackground(Color.PINK); six = new JButton("六"); six.setMargin(new Insets(0, 0, 0, 0)); six.setSize(30, 30); six.setLocation(48, 259); six.setBackground(Color.PINK); jt = new JTextField(); jt.setSize(332, 32); jt.setLocation(36, 565); imagePanel.setLayout(null); imagePanel.add(kaishi); imagePanel.add(one); imagePanel.add(second); imagePanel.add(third); imagePanel.add(four); imagePanel.add(five); imagePanel.add(six); imagePanel.add(jt); this.getLayeredPane().setLayout(null); // 把背景图片添加到分层窗格的最底层作为背景 this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(background.getIconWidth(), background.getIconHeight()+42);
this.setVisible(true);
}
public static void main(String[] args) { choujiang t = new choujiang(); t.setVisible(true); } public void chushihua(){ one.setBackground(Color.PINK); second.setBackground(Color.PINK); third.setBackground(Color.PINK); four.setBackground(Color.PINK); five.setBackground(Color.PINK); six.setBackground(Color.PINK); } public JTextField getJT(){ return jt; }
}
class t extends Thread {
public void run() {
try {
sleep(1000);
System.out.println("a");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
相关文章推荐
- Problem-O
- hdu 4387 Stone Game
- Linux入门之入手开发板与开发环境的搭建 2016.5.7
- HDU 5115 Dire Wolf(区间DP)
- cqm题解报告04
- 20150228--Ajax2-01
- linux jenkins安装(四)
- cas4.2的安装
- opencv3.0 FaceRecongnizer说明
- unity源码解析Texture
- java Io流中对象序列化和反序列问题
- 百万用户级游戏服务器架构设计(一)
- 争吵的日子
- HDU 5113 Black And White(搜索+剪枝)
- js事件之event.preventDefault()与event.stopPropagation()用法区别
- 从头认识多线程-2.13 由同步的synchronized (newobject()) 引起的异步现象和脏读
- mysql 添加用户并授权
- 练习:C#---类(身份证号截取生日、验证邮箱、DateTime)
- bzoj1690:[Usaco2007 Dec]奶牛的旅行(分数规划+spfa判负环)
- 神奇的 BlocksKit (一)