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

📄 buttonapplet.java

📁 java 中的button使用方法 通过点击改变背景色
💻 JAVA
字号:
/*
 * buttonApplet.java
 *
 * Created on 2007年5月4日, 上午8:01
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package testApplet;

import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author INST
 */
public class buttonApplet extends java.applet.Applet implements ActionListener{
    
    /** Initialization method that will be called after the applet is loaded
     *  into the browser.
     */
//    private int currentColor;
    public void init() {
        // TODO start asynchronous download of heavy resources
        testButton=new Button("Press me!");
        testButton.addActionListener(this);
        add(testButton);
        greenButton=new Button("Green");
        greenButton.addActionListener(this);
        add(greenButton);
//        currentColor= -1;
//        changeWindowColor();
    }
    private Button greenButton;
    private Button testButton;
//    private final Color bgColors[]=new Color[]{
//        Color.RED,Color.BLACK,Color.GRAY,Color.YELLOW
//    };
  
    // TODO overwrite start(), stop() and destroy() methods
//    public void paint(Graphics g)
//    {
//        setBackground(bgColors[currentColor]);
//        testButton.setForeground(bgColors[currentColor]);
//    }
    public void actionPerformed(ActionEvent e) {
        if(testButton==e.getSource())
        {
//            changeWindowColor();
//            repaint();
            setBackground(Color.BLACK);
        }
        if(greenButton==e.getSource()){
            greenButton.setForeground(Color.GREEN);
            setBackground(Color.GREEN);
        }
            
    }
//
//    private void changeWindowColor() {
//        throw new UnsupportedOperationException("Not yet implemented");
//        currentColor=currentColor+1;
//        if(currentColor==bgColors.length)
//        {
//            currentColor=0;
//        }
//    }
}

⌨️ 快捷键说明

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