zoukankan      html  css  js  c++  java
  • 模拟展示动态按钮

    动态展示按钮    没有运行出效果来

    package com.lsw.server;
    
    import java.applet.Applet;
    import java.awt.Button;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class HelloApplet extends Applet implements Runnable{
        private int fontSize = 8;
        private Thread changer;
        private boolean stopFlag = true;
        private Button contrlButton = new Button(" 开始动态显示!");
        
        public void init(){
            ActionListener actionListener = new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent e) {
                    if(stopFlag)
                        start();
                    else
                        stop();
                    
                }
            };
            
            contrlButton.addActionListener(actionListener);
            
            setBackground(Color.WHITE);
            add(contrlButton);
            setSize(100,100);
        }
        
        public void start(){
            changer = new Thread(this);
            stopFlag = false;
            fontSize = 8;
            contrlButton.setLabel("停止动态显示");
            changer.start();
        }
        
        public void paint(Graphics g){
            super.paint(g);
            g.setFont(new Font("newFont",Font.BOLD,fontSize));
            g.drawString("Hello", 30, 80);
        }
        
        public void stop(){
            stopFlag = true;
            contrlButton.setLabel("开始动态显示!");
        }
    
        @Override
        public void run() {
            while(!stopFlag){
                repaint();
                try{
                    Thread.sleep(1000);
                }
                catch(InterruptedException e){
                    e.printStackTrace();
                }
                if(fontSize++>40)
                    fontSize = 8;
            }
            
        }
    
    }
  • 相关阅读:
    beautiful number 数位DP codeforces 55D
    最长上升子序列
    0-1背包 codeforces 55 D
    概率DP HDU 4586 play the dice
    水题 不要62 HDU 2089
    抓老鼠 codeForce 148D
    ZOJ 3551 吸血鬼 概率DP
    poj 2151 Check the difficulty of problems 概率DP
    HDU 4681 string 求最长公共子序列的简单DP+暴力枚举
    HDU 1814 模板题 2-sat
  • 原文地址:https://www.cnblogs.com/batman425/p/7581818.html
Copyright © 2011-2022 走看看