码迷,mamicode.com
首页 > 编程语言 > 详细

java day2一个模拟双色球的代码

时间:2017-01-07 01:29:07      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:private   hang   import   解决办法   etc   lov   代码   event   实现   

package day2;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.event.MouseAdapter;
import java.util.Random;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

//继承
public class day2_c extends JPanel{
    /**
             * 
             */
        private static final long serialVersionUID = 1L;
        
        public int[] Rednumber = {0,0,0,0,0,0,0};
        public int[] checknum = new int[7];
        Random mrRandom = new Random();
        boolean Ischange = false;
        boolean state = false;
        public int counterrun = -1;
        
        public static void main (String args[])
        {
            JFrame myFrame = new JFrame("NEF");
            myFrame.setSize(1200, 650);
            myFrame.setDefaultCloseOperation(2);
            myFrame.setLocationRelativeTo(null);
            myFrame.setResizable(false);
            
            day2_c mypanel = new day2_c();
            myFrame.add(mypanel); 
            
            myFrame.setVisible(true);
            mypanel.changeN();
        }
        
        public void paint(Graphics myg)
        {
            //画点击口
            myg.setColor(Color.orange);
            myg.fillRect(550, 50, 100, 50);
            myg.setFont(new Font("楷体", 1,25));
            myg.setColor(Color.BLACK);
            myg.drawString("点击开始", 547, 80);
            
            //画红球
            int x_axis = 100;
            int y_axis = 250;
            myg.setColor(Color.red);
            for(int i = 0; i < 6; i++)
            {
                myg.fillOval(x_axis, y_axis, 100, 100);
                x_axis += 150;
            }
            myg.setColor(Color.blue);
            myg.fillOval(1000, 250, 100, 100);
            
            //是否change
            if(Ischange)
            {
                //画数字
                int T_axisX = 125;
                int T_axisY = 320;
                int nud = 0;
                for(int i = counterrun; i < 6; i++)
                {
                    nud = mrRandom.nextInt(33) + 1;
                    for(int h = 0; h < i; h++)
                    {
                        if(nud == Rednumber[i])
                        {
                            i--;
                            break;
                        }
                    }
                    Rednumber[i] = nud;
                }
                Rednumber[6] = mrRandom.nextInt(16) + 1;
                myg.setFont(new Font("", 1, 45));
                myg.setColor(Color.GREEN);

                for(int i = 0;i < 7;i++)
                {
                    if(Rednumber[i] % 10 == 0)
                    {
                        myg.drawString(" " + Rednumber[i],T_axisX , T_axisY);
                    }
                    else{
                        myg.drawString("" + Rednumber[i],T_axisX , T_axisY);
                    }
                    T_axisX += 150;
                }
                //myg.drawString(""+Rednumber[6], T_axisX, T_axisY);
            }
        }
        
        public void changeN()
        {
            MouseAdapter MA = new MouseAdapter() {
            public void mouseClicked(MouseEvent e)
            {
                int x = e.getX();
                int y = e.getY();
                
                if(x > 550 & x < 650 & y > 50 & y < 100 )
                {
                    Ischange = true;
                    //repaint();
                }
            }
            };
            addMouseListener(MA);        //鼠标时间的监听实际上是和main函数main线程分开的
            //监听是简单事件,无法执行循环
                for(int i = 0; i < 140; i++)
                {
                    try{
                        Thread.sleep(50);
                    }
                    catch(Exception e3){
                        e3.printStackTrace();
                    }
                    if(i % 20 == 0)
                    {
                        counterrun ++;
                    }
                    repaint();
                }
                counterrun = 0;
        }
}

程序有bug,目前还没有找到好的解决办法,有兴趣的可以留言,我发老师的代码,实现的过程不太一样
本来还有一个小功能是排序的,但是太简单了,就没写,,,,一直和bug斗争,就一冒泡排序。

有人愿意帮我解决一下这程序的bug不。。。

java day2一个模拟双色球的代码

标签:private   hang   import   解决办法   etc   lov   代码   event   实现   

原文地址:http://www.cnblogs.com/NEFPHYS/p/6257916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!