⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorapp.java

📁 java用awt写的界面程序
💻 JAVA
字号:
//==============================================================
// ColorApp.java - Delegation event model AWT application
//
// 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.awt.event.*;
import java.util.Random;

public class ColorApp
 extends Panel 
 implements ActionListener {

 protected Random gen = new Random();
 
 // Constructor 
 public ColorApp() {
  Button clickMe = new Button("Click Me!");
  clickMe.addActionListener(this);
  add(clickMe);  // Add button to panel
 }

 // The button's event handler
 public void actionPerformed(ActionEvent e) {
  Color c;
  do {
   c = new Color(gen.nextInt());
  } while (c == getBackground());
  setBackground(c);
  repaint();
 }

 // The main program
 public static void main(String[] args) {

  // Create frame and set its size
  Frame frame = new Frame("Color Application Demo");
  frame.setSize(250, 200);
  frame.setLocation(50, 50);

  // End the program when the window is closed
  frame.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0);
   }
  });

  // Add the ColorApp panel to the frame and show it
  frame.add(new ColorApp(), BorderLayout.CENTER);
  frame.show();
 }
}

⌨️ 快捷键说明

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