backcolor.java

来自「Java学习源代码检索系统免费版」· Java 代码 · 共 41 行

JAVA
41
字号
//==============================================================
// BackColor.java - AWT Applet using old inheritance event model
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import java.applet.Applet;
import java.awt.*;
import java.util.Random;

public class BackColor extends Applet {
 Random gen;  // Random number generator for color selction
 String buttonLabel = "Click Me!";

 // Initialize applet
 public void init() {
  gen = new Random();
  Button colorButton = new Button(buttonLabel);
  add(colorButton);  // Added to Applet container
 }

 // Respond to button click
 public boolean action(Event evt, Object what) {
  Color c;
  if (buttonLabel.equals(what)) {  // Is it our button?
   do {
    c = new Color(gen.nextInt());
   } while (c == getBackground());
   setBackground(c);
   repaint();
  }
  return true;  // Kill event
 }
}
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?