zoukankan      html  css  js  c++  java
  • 线程的休眠

    public class SleepMethodTest extends JFrame {
    
        private Thread t;
        private static Color[] color = { Color.BLACK, Color.BLUE, Color.CYAN, Color.GREEN, Color.ORANGE, Color.YELLOW,
                Color.RED };
        private static final Random rand = new Random();
    
        private static Color getC() {
            return color[rand.nextInt(color.length)];
        }
    
        public SleepMethodTest() {
            // TODO Auto-generated constructor stub
            t = new Thread(new Runnable() {
                int x = 30;
                int y = 50;
                public void run() {
                    while (true) {
                        try {
                            Thread.sleep(100);
                        } catch (Exception e) {
                            // TODO: handle exception
                            e.printStackTrace();
                        }
                        Graphics graphics = getGraphics();
                        graphics.setColor(getC());
                        graphics.drawLine(x, y, 100, y++);
                        if(y>=80){
                            y=50;
                        }
                    }
    
                }
            });
            t.start();
        }
        public static void init(JFrame frame,int width,int height) {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(width, height);
            frame.setVisible(true);
        }
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            init(new SleepMethodTest(), 100, 100);
        }
    
    }
  • 相关阅读:
    HtmlAgilityPack
    随笔-20150513
    过滤掉html 标签
    json转换
    第28月第3天 c语言读写文件
    第27月第28天 iOS bundle
    第27月第27天 https
    第27月第25天 clang -rewrite-objc main.m
    第27月第24天 git pull fetch
    第27月第18天 epoll lt et
  • 原文地址:https://www.cnblogs.com/dulute/p/10648040.html
Copyright © 2011-2022 走看看