how2j.cn

下载区
文件名 文件大小
请先登录 1m
增值内容 1m
1m
步骤 1 : 先看效果   
步骤 2 : 恢复面板RecoverPanel 代码解读   

先看效果
步骤 2 :

恢复面板RecoverPanel 代码解读

edit
增值内容,请先登录
完整的J2SE桌面项目,从无到有完整的开发流程,涵盖全部52个知识点,154个开发步骤, 一共36个讲解视频,累计时长3小时10分59秒,大小1.94G,充实J2SE项目经验,为简历加上一个有吸引力的砝码
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package gui.panel; import javax.swing.JButton; import javax.swing.JPanel; import util.ColorUtil; import util.GUIUtil; public class RecoverPanel extends JPanel { static{ GUIUtil.useLNF(); } public static RecoverPanel instance = new RecoverPanel(); JButton bRecover =new JButton("恢复"); public RecoverPanel() { GUIUtil.setColor(ColorUtil.blueColor, bRecover); this.add(bRecover); } public static void main(String[] args) { GUIUtil.showPanel(RecoverPanel.instance); } }


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2018-06-08 按钮颜色设置不起作用?
rebortyang




设置按钮的颜色为ColorUtil里面的蓝色,不起作用
加载中
package gui.panel;

import util.ColorUtil;
import util.GUIUtil;

import javax.swing.*;

/**
 * RecoverPanel
 * @version 1.0
 * @author yangjiebin
 * */

public class RecoverPanel extends JPanel{
    static {
        GUIUtil.useLNF();
    }

    public JButton bRecover = new JButton("恢复");

    public static RecoverPanel instance = new RecoverPanel();

    private RecoverPanel(){
        GUIUtil.setColor(ColorUtil.blueColor,bRecover);
        this.add(bRecover);
    }

    public static void main(String[] args) {
        GUIUtil.showPanel(RecoverPanel.instance);
    }

}


package util;

import java.awt.*;

/**
 * Color Utility
 * @version 1.0
 * @author yangjiebin
 * */
public class ColorUtil {
    public static Color blueColor = Color.decode("#3399FF");
    public static Color grayColor = Color.decode("#999999");
    public static Color backgroundColor = Color.decode("#eeeeee");
    public static Color warningColor = Color.decode("#FF3333");

    /**
     * 通过百分比来获取显示的颜色
     * @param per 百分比
     * @return color
     * */
    public static Color getByPercentage(int per){
        if (per > 100){
            per = 100;
        }
        int r = 51;
        int g = 255;
        int b = 51;

        float rate = per / 100f;
        r = (int) ((255 - 51) * rate + 51);
        g = 255 - r + 51;
        Color color = new Color(r,g,b);
        return color;
    }

}

							


2 个答案

我不能太懒了
答案时间:2020-04-03
是不是你setcolor函数没有写对

how2j
答案时间:2018-06-10
我的可以,你比较一下和我的代码的区别



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到









提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-一本糊涂账-RecoverPanel 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图