CREATING ROUND SWING BUTTONS 2

Cortex-R52处理器比较器逻辑与DCLS配置解析 嵌入式处理器中的容错设计是确保系统可靠性的关键技术,其中双核锁步(DCLS)架构通过硬件比较器实现执行结果实时校验。Cortex-R52系列处理器提供三种配置模式:无冗余逻辑、锁步模式和分锁模式,分别对应不同的可靠性需求和功耗表现。锁步模式通过每个时钟周期的全量比较实现最高安全等级,适用于汽车电子等关键领域;分锁模式则兼顾灵活性和可靠性,适合工业控制场景。理解比较器逻辑的工作原理和配置方法,对开发高可靠性嵌入式系统至关重要,特别是在需要满足ISO 26262等安全认证要求的应用中。 阅读详情
CREATING ROUND SWING BUTTONS

This tip is about round Swing buttons. Actually, the information in
this tip applies to a button of any arbitrary shape but to keep the
discussion simple, we're just going to use a round shape.

There are two things you need to do when creating a round button. 
The first is to override the appropriate painting methods in order
to paint the round shape. The second is to set things up so that
the button responds only when you click within the round button
(not just within the rectangle that contains the round button).

Here's an example program that implements a round button.

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class RoundButton extends JButton {
    public RoundButton(String label) {
        super(label);

        // These statements enlarge the button so that it
        // becomes a circle rather than an oval.
        Dimension size = getPreferredSize();
        size.width = size.height = Math.max(size.width, size.height);
        setPreferredSize(size);

        // This call causes the JButton not to paint the background.
        // This allows us to paint a round background.
        setContentAreaFilled(false);
    }

    // Paint the round background and label.
    protected void paintComponent(Graphics g) {
if (getModel().isArmed()) {
            // You might want to make the highlight color
            // a property of the RoundButton class.
            g.setColor(Color.lightGray);
        } else {
            g.setColor(getBackground());
        }
g.fillOval(0, 0, getSize().width-1, getSize().height-1);

        // This call will paint the label and the focus rectangle.
super.paintComponent(g);
    }

    // Paint the border of the button using a simple stroke.
    protected void paintBorder(Graphics g) {
        g.setColor(getForeground());
        g.drawOval(0, 0, getSize().width-1, getSize().height-1);
    }

    // Hit detection.
    Shape shape;
    public boolean contains(int x, int y) {
        // If the button has changed size, make a new shape object.
        if (shape == null || !shape.getBounds().equals(getBounds())) {
            shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
        }
        return shape.contains(x, y);
    }

    // Test routine.
    public static void main(String[] args) {
        // Create a button with the label "Jackpot".
        JButton button = new RoundButton("Jackpot");
        button.setBackground(Color.green);

        // Create a frame in which to show the button.
        JFrame frame = new JFrame();
        frame.getContentPane().setBackground(Color.yellow);
        frame.getContentPane().add(button);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.setSize(150, 150);
        frame.setVisible(true);
    }
}


The RoundButton class extends JButton because we want to keep most
of functionality of a JButton. In the RoundButton constructor, the
method setContentAreaFilled() is called. This causes the button to
paint the focus rectangle, but not to paint the background.

Now we need to paint the circular background. That's done by
overriding the paintComponent() method. That method uses
Graphics.fillOval() to paint a solid circle. Then paintComponent()
calls super.paintComponent() to paint the label on top of the solid
circle.

This example also overrides paintBorder() in order to paint a border
around the round button. If you don't want a border, you would not
override this method. This method calls Graphics.drawOval() to
paint a thin border around the circle.

Finally, we want the button to respond only when the user clicks on
it, but not respond to clicks outside of it. By default, a JButton
responds to mouse clicks in a rectangular area around the
button. A JButton has no idea about the real shape of the button,
and so it just assumes that the button is rectangular. To tell
JButton the real shape of a button you need to override the
contains() method. The contains() method takes a coordinate and
returns true if the coordinate is inside the button and false
otherwise. The method uses a Shape object (Ellipse2D) to determine
whether the coordinate is inside the circle.

Note: In JDK 1.2.2, there's a small bug in how JButton behaves when
you drag the mouse in and out of its perimeter. Ideally, if you
clickon the circular button and then drag the mouse outside of the
button's perimeter, the button should change its appearance. When
you drag the mouse back into the circular button's perimeter, the
button should restore its appearance. Unfortunately, the code that
implements this behavior does not call the contains() method.
Instead it just uses the "bounds" of the button (this is the
smallest rectangular area containing the button). Notice that if
you drag the mouse slightly beyond the circular perimeter, that is,
outside of the circle but not outside the bounds, the button won't
change it's appearance. There is no workaround for this minor bug
except to implement all of the functionality yourself.


FORMATTING BIGDECIMAL NUMBERS

Floating and double precision variables are fine for doing
statistical or graphics-related calculations. However they are not
recommended forfinancial calculations. That's because the results
produced by floating and double precision arithmetic are not always
precise.  For example, the following example subtracts 1.1 from 2
using floating point numbers.

        double f = 2.9 - 1.1;
        System.out.println( f );

It produces the result 1.7999999999999998 rather than 1.8.

If this kind of result is unacceptable in your application, as is
the case with most financial applications, you should use BigDecimal
numbers instead of floating point numbers.  Here's a quick example
of using BigDecimal numbers.


import java.math.*;

class BigDecimalTest {
    public static void main(String[] args) {
        BigDecimal a = new BigDecimal("2.9");
        BigDecimal b = new BigDecimal("1.1");
        BigDecimal c = a.subtract(b);
        System.out.println(c);    // 1.8
    }
}


One of the features missing from the BigDecimal class is formatting
methods. When you print a BigDecimal number, all the digits are
printed (e.g. 12.3456000). This isn't what you want if you have to
print a value in dollar and cents format, for example (12.35).
Formatting features might be added in a later release but in the
meantime, here are some quick routines to perform the two most
common operations: stripping trailing zeroes and displaying with a
specified precision.


class FormatBigDecimal {
    // Returns the BigDecimal value n with trailing zeroes removed.
    static BigDecimal trim(BigDecimal n) {
        try {
            while (true) {
                n = n.setScale(n.scale()-1);
            }
        } catch (ArithmeticException e) {
            // no more trailing zeroes so exit.
        }
        return n;
    }

    // Returns the BigDecimal value n with exactly 'prec' decimal places.
    // Zeroes are padded to the right of the decimal point if necessary.
    static BigDecimal format(BigDecimal n, int prec) {
        return n.setScale(prec, BigDecimal.ROUND_HALF_UP);
    }

    // Some examples.
    public static void main(String[] args) {
        System.out.println(trim(new BigDecimal("12.3230000")));    // 12.323
        System.out.println(format(new BigDecimal("12.32534"), 2)); // 12.33
        System.out.println(format(new BigDecimal("12"), 2));       // 12.00
    }
}


The trim() method attempts to eliminate the last digit from the
number. If the digit is zero, it attempts to eliminate another.
If it tries to eliminate a non-zero digit, setScale() throws an
exception, and the method returns the result.

The trim() method does not use exceptions in a proper way. You
should only use exceptions for exceptional cases and not for
breaking out of loops as it is done here. However, this technique
is currently the most efficient way to implement this functionality.
(If you do use this method, you have to promise to correct it when
a better way comes along!)

The format() method simply returns a version of the BigDecimal
number with the scale of the number set to the specified precision.
It rounds the number such that 5's or greater are rounded up and
4's or lesser are rounded down.

.  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .

- NOTE
The names on the JDC mailing list are used for internal Sun
Microsystems(tm) purposes only.  To remove your name from the list,
see Subscribe/Unsubscribe below.


- FEEDBACK
Comments?  Send your feedback on the JDC Tech Tips to:

jdc-webmaster


- SUBSCRIBE/UNSUBSCRIBE
The JDC Tech Tips are sent to you because you elected to subscribe
when you registered as a JDC member.  To unsubscribe from JDC Email,
go to the following address and enter the email address you wish to
remove from the mailing list:

http://developer.java.sun.com/unsubscribe.html


To become a JDC member and subscribe to this newsletter go to:

http://java.sun.com/jdc/


- ARCHIVES
You'll find the JDC Tech Tips archives at:

http://developer.java.sun.com/developer/TechTips/index.html


- COPYRIGHT
Copyright 1999 Sun Microsystems, Inc. All rights reserved.
901 San Antonio Road, Palo Alto, California 94303 USA.

This document is protected by copyright.  For more information, see:

http://developer.java.sun.com/developer/copyright.html


This issue of the JDC Tech Tips is written by Patrick Chan,
the author of the publication "The Java(tm) Developers Almanac"
(http://java.sun.com/docs/books/almanac/index.html).

JDC Tech Tips
August 26, 1999
【C++】lambda表达式 本篇文章我们要学习的是lambda表达式,它是C++11新增的一种特别方便的语法,相较于之前的函数指针以及仿函数都方便了不少,下面就让我们一起来学习吧。 阅读详情

相关推荐

记一次完整的RPG Maker MV游戏逆向过程(思路一)

了解RPG Maker MV的文件建构 上一篇文章,我们已经成功在PC上运行了游戏,那我们如何对游戏进行逆向呢? 首先要了解正常的RPG Maker MV制作的游戏应该具有哪些文件,以及他的结构 那如何了解他的结构呢,很简单,我们只需要用RPG Maker MV创建一个默认工程,来看看一个游戏的最简结构是怎么样的 创建新项目 项目创建完成 查看项目目录结构 是不是和之前解包出来的很像呢? 通...

Ciiiiiing的博客 1万+

TWo buttons

***TWo buttons*** 薇尔莉特在一个机器前,有一个红色按钮、一个蓝色按钮和一个只能显示正整数的屏幕。按下红色按钮后,机器的数字会乘 2。按下蓝色按钮后,机器的数字会减 1。如果在某时刻,数字不再是正整数,机器会当场宕机,因此不能让数字小于或等于零。屏幕可以显示任意大的正整数。 初始状态下,机器的数字为 n。薇尔莉特想要在显示屏幕上得到数字为 m。为了获得这个结果,她最少需要...

weixin_44824383的博客 360

高云FPGA开发实战:手把手教你用ModelSim做功能仿真与时序分析(附Testbench写法)

本文详细介绍了高云FPGA开发中如何使用ModelSim进行功能仿真与时序分析,包括环境搭建、Testbench编写、波形调试和时序优化等实战技巧。通过具体案例和代码示例,帮助开发者掌握FPGA仿真验证的核心方法,提升设计可靠性。特别针对高云GW5A系列器件提供了专业的仿真库配置指南和时序分析策略。

weixin_30412167的博客 470

2019湖南省赛 4 Buttons(推公式)

4 Buttons Bobo lives in an infinite chessboard. Initially he locates at (0,0)(0, 0)(0,0). There are 444 buttons. When the first button is pressed, Bobo moves right for at most aaa cells. When the seco...

tomjobs的博客 858

慕课软件质量保证与测试(习题集)

慕课金陵科技学院.软件质量保证与测试.期末复习.习题汇总0 总目录1 绪论1.1 软件质量保证与测试的产生与发展1.2 软件缺陷,软件错误,软件故障1.3 软件质量保证与测试的意义,原则和挑战1.4 单元测试1.5 课后作业2 软件测试策略2.1 软件测试的模型,过程和生命周期2.2 软件测试的方法和技术2.3 单元测试2.4 课后作业3 黑盒测试3.1 黑盒测试概述3.2 等价类划分测试3.3 边界值测试3.4 错误推测法3.5 判定表驱动法3.6 因果图法3.7 场景法3.8 正交实验法3.9 单元测试

weixin_42473228的博客 5万+

高效 DEM 拼接

通过以上步骤的系统实施,能够实现高效、准确的大型地理信息系统 DEM 数据拼接,满足复杂和大规模项目的应用需求。

llhllq2015的博客 1035

Glyph 26426 missing from current font.解决matplotlib画图中文字体乱码问题

1. 问题复现 环境:Ipython 3.8 import matplotlib.pyplot as plt import pandas as pd data = pd.read_csv('/Users/me/Documents/small_cust.csv') data['first_catg'].value_counts().plot() plt.show() 图是画出来了...

fwj_ntu的博客 5万+

rk3568 修改开机动画

bootanimation.zip是一个Android设备启动时播放的动画文件,它包含了一系列的图片和描述文件,用于描述动画的播放顺序和持续时间。

weixin_35723192的博客 2730

洛谷4965 薇尔莉特的打字机(Trie,DP)

神仙题。 考虑在一棵 Trie 上进行染色,将可能出现的串的末尾染成黑色。答案就是黑点的个数。一开始只有 \(A\) 的末尾点是黑色。 当出现一个字符(不是退格)\(c\) 时,就要将每个黑点的 \(c\) 儿子都染成黑色。 然而这样一个点可能会有重复染色,不能直接乘 \(2\)。 不妨记录一个 \(f[c]\) 表示有儿子 \(c\) 且该儿子是黑色的点的个数。 那么此时答案 \(an...

angzuo8655的博客 697

基于STM32设计的智能家居系统(采用ESP8266+OneNet云平台)

一、环境介绍 单片机采用:STM32F103C8T6 上网方式:采用ESP8266,也可以使用其他设备代替,只要支持TCP协议即可。比如:GSM模块、有线网卡等。 云平台: 采用中国移动OneNet. 也可以采用腾讯、阿里云、华为云、百度天工物接入、机智云等等。 前面文章有讲解。 协议: 采用MQTT协议 开发软件:keil5 完整项目源码下载:https://download.youkuaiyun.com/download/xiaolong1126626497/19766925 二、包含的硬件与实...

1万+

7.26华为OD机试真题 新系统 - 炸弹人的雷区数量 (Java/Py/C/C++/Js/Go)

7.26华为OD机试真题 新系统 - 炸弹人的雷区数量 (Java/Py/C/C++/Js/Go)

算法大师! 796

CREATING ROUND SWING BUTTONS 2 (转)

CREATING ROUND SWING BUTTONS 2 (转)[@more@]CREATING ROUND swing BUTTONSThis tip is about round Swing buttons. Actua...

csd3176的博客 103

ContextCapture系列教程(三):大疆精灵4RTK版无人机POS数据提取、处理(处理后勉强达到免相控要求)

大疆精灵 Phantom 4 RTK于2018年发布,是大疆为高精度建图与精准飞行设计的行业级无人机,在精灵4无人机外形的基础上,机身增加了RTK模块,可以实现高精度 RTK 定位导航,相机与 RTK 系统采用微秒级时间同步,可以通过app 进行航线规划飞行

pausau的博客 1万+

创建圆形的SWING BUTTON

CREATING ROUND SWING BUTTONSThis tip is about round Swing buttons. Actually, the information in this tip applies to a button of any arbitrary shape but to keep the discussion simple, were just go

programlover的专栏 994

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

创建圆形的SWING BUTTON (转)

创建圆形的SWING BUTTON (转)[@more@]CREATING ROUND swing BUTTONS This tip is about round Swing buttons. Actually, the...

csd3176的博客 185

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

一个很久以前写的 Cool Buttons 脚本

很久前写了一个Cool Buttons! 脚本,可以把页面当中的所有 input type="button" 和 reset / submit 按钮用自定义的样式替换,包含了一些动态效果。看在无忧脚本下载量有了一千多,就放在自己的blog 上吧现在注重web标准,我已经不用它了,也停止了开发。

melopia 887

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

The Science of JavaTM Sound Technology

  The Science of JavaTM Sound TechnologyBy Michael D. Meloan(June 1999) Sound creates mood, triggers memories, and in conjunction with visual imagery weaves whole worlds of fantasy. Sound is t

CanFly的专栏 2653

jar-The Java Archive Tool

jar-The Java Archive ToolCombines multiple files into a single JAR archive file. SYNOPSISjar [ options ] [manifest] destination input-file [input-files]DESCRIPTIONThe jar tool is a java

CanFly的专栏 1786

Compressing and Decompressing Data using JavaTM APIs

Compressing and Decompressing Data using JavaTM APIsby Qusay H. Mahmoud with contributions from Konstantin KladkoFebruary 2002 Many sources of information contain redundant data or data that adds

CanFly的专栏 1733

What's New in the JMF 2.0 Reference Implementations

   Whats New in the JMF 2.0 Reference Implementations New Features in JMF 2.1.1 FCS Improved RTP API Added support for H.263/1998 (RFC 2429) - now can interoperate with Darwin based RTSP

CanFly的专栏 1639

Drag and Drop: New Data Transfer Capabilities in the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4

New Data Transfer CapabilitiesJohn ZukowskiNovember 2001 Sun is currently undergoing their third beta release of the JavaTM 2 Platform, Standard Edition (J2SETM), version 1.4. This latest release

CanFly的专栏 1582

Distributed Java Programming with RMI and CORBA

Distributed Java Programming with RMI and CORBAQusay H. MahmoudJanuary 2002 The Java Remote Method Invocation (RMI) mechanism and the Common Object Request Broker Architecture (CORBA) are the two

CanFly的专栏 1464

New I/0 Functionality for JavaTM 2 Standard Edition 1.4

New I/0 Functionality for JavaTM 2 Standard Edition 1.4 John ZukowskiOctober, 2001Back in January 2000, while many people were arguing about whether the year 2000 was the last or first year of the

CanFly的专栏 1434

JINI NETWORK TECHNOLOGY DEFENDS THE ENVIRONMENT

JINITM NETWORK TECHNOLOGY DEFENDS THE ENVIRONMENT by Jon Byous November 8, 2001 -- Scientists at the U.S. Department of Energys Pacific Northwest National Laboratory (PNNL), in Richland,

CanFly的专栏 1335

NLEASHING J2EETM TECHNOLOGY'S POWER WITH EJBTM COMPONENTS

NLEASHING J2EETM TECHNOLOGYS POWER WITH EJBTM COMPONENTS by Michael Meloan March 20, 2001 -- The benefits of building ecommerce software applications from pretested, server-side JavaTM c

CanFly的专栏 1305

Understanding the Manifest

Understanding the Manifest JAR files can support a wide range of functionality, including electronic signing, version control, package sealing, extensions, and others. What gives JAR files the abi

CanFly的专栏 1271
上一篇: Lightweight UI Framework(有產生圓形Button的源碼)
下一篇: New I/0 Functionality for JavaTM 2 Standard Edition 1.4
CanFly
博客等级 码龄25年 0粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值