Lightweight UI Framework(有產生圓形Button的源碼)

工商银行数据智能架构实践 工商银行大数据平台技术创新与实践摘要(149字): 工商银行构建了企业级大数据云基础设施,形成包含批量计算、流计算、联机分析等核心能力的技术架构。平台创新性地实现流批一体处理,将个人储蓄存款监测时效提升至分钟级;通过实时数仓技术将报送时效缩短至1-5分钟;融合内外部数据构建风控模型,债券违约预警准确率达100%。平台还支撑了"码上赢"精准营销和空间数据服务等创新应用,未来将向存算分离、实时数仓和云数智融合方向演进,持续提升数据价值转化能力。 阅读详情
Java AWT: Lightweight UI Framework

The Problem

One of the issues with the 1.0 AWT is that creating new components requires creating subclasses of java.awt.Canvas or java.awt.Panel, which means that each new component owns its own opaque native window. This one-to-one mapping between components and native windows results in three problems:
  1. Native windows can be heavyweight, so it's undesirable to have too many of them.
  2. Native windows are opaque, so they can't be used to implement transparent regions.
  3. Native windows are handled differently across platforms, so the AWT has to struggle to maintain a consistent view across these varied platforms.
Hooks have been implemented that enable the creation of "lightweight" UI components; these hooks are called the Lightweight UI Framework.

Lightweight UI Framework

The Lightweight UI Framework is very simple -- it boils down to the ability to now directly extend the java.awt.Component and java.awt.Container classes in order to create components which do not have native opaque windows associated with them. These lightweight components and containers fit right into the existing AWT models, such as painting, layout, and events, and as such, require no special handling or additional APIs. Existing subclasses of Canvas and Panel can be easily migrated to lightweight versions by simply changing their superclass appropriately.

The advantages of creating lightweight components are the following:

  • The Lightweight component can now have transparent areas by simply not rendering to those areas in its paint() method (although, until we get full shape support from Java2D, the bounding box will remain rectangular).
  • The Lightweight component is "lighter" in that it requires no native data-structures or peer classes.
  • There is no native code required to process lightweight components, hence handling of lightweights is 100% implemented in common java code, which leads to complete consistency across platforms.

We are using this framework in an upcoming version of the toolkit (beyond 1.1) to implement pure-java versions of the base UI controls (Button, List, etc.) which implement a common look-and-feel across the platforms (and don't use the native peers).

Mixing Lightweight & Heavyweight Components

Lightweight components can be freely mixed with existing heavyweight components. This means that lightweight components can be made direct children of heavyweight containers, heavyweight components can be made direct children of lightweight containers, and heavyweight and lightweights can be mixed within containers (with the one caveat that the heavyweight sibling will always be "on top" if it overlaps with a lightweight, regardless of the specified z-order).

Putting Lightweight components in Existing Panels

The painting and event dispatching mechanism for lightweight components is handled by the Container class. This means that the painting of lightweight components is triggered from within the paint() method of its container. Therefore, if a lightweight component is placed inside of a Container instance where the paint method has been overridden but which does not call super.paint(), the paint() method of the lightweight component will never be called. This could be a common occurrence if you're using existing classes which extend Panel in order to implement the painting of a border or bevel, but which don't call "super.paint()" (because it was not an issue with 1.0.2). So if your lightweight components are not showing up, this is the first thing to check!

Double Buffering

Because lightweight components are entirely rendered in Java, the use of double-buffering in their containers can really smooth out their rendering to avoid flashing. By default, the Container class does not implement double-buffering, but this is extremely easy to do! Following is an example of a double-buffered Panel which implements smooth rendering for any lightweight components placed inside it:

public class DoubleBufferPanel extends Panel {    
  Image offscreen;

  /**
   * null out the offscreen buffer as part of invalidation
   */
  public void invalidate() {
      super.invalidate();
      offscreen = null;
  }

  /**
   * override update to *not* erase the background before painting
   */
  public void update(Graphics g) {
      paint(g);
  }

  /**
   * paint children into an offscreen buffer, then blast entire image
   * at once.
   */
  public void paint(Graphics g) {
      if(offscreen == null) {
         offscreen = createImage(getSize().width, getSize().height);
      }
      Graphics og = offscreen.getGraphics();
      og.setClip(0,0,getSize().width, getSize().height);
      super.paint(og);
      g.drawImage(offscreen, 0, 0, null);
      og.dispose();
  }
}

Sample Code

Following is sample code showing the creation of a lightweight round button class, which shows off the transparency aspect of lightweight components.

import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

/**
 * RoundButton - a class that produces a lightweight button.
 */
public class RoundButton extends Component {

  String label;                      // The Button's text
  protected boolean pressed = false; // true if the button is detented.
  
  /**
   * Constructs a RoundButton with the specified label.
   * @param label the label of the button
   */
  public RoundButton(String label) {
      this.label = label;
      enableEvents(AWTEvent.MOUSE_EVENT_MASK);
  }
  
  /**
   * paints the RoundButton
   */
  public void paint(Graphics g) {
      int s = Math.min(getSize().width - 1, getSize().height - 1);
      
      // paint the interior of the button
      if(pressed) {
          g.setColor(getBackground().darker().darker());
      } else {
          g.setColor(getBackground());
      }
      g.fillArc(0, 0, s, s, 0, 360);
      
      // draw the perimeter of the button
      g.setColor(getBackground().darker().darker().darker());
      g.drawArc(0, 0, s, s, 0, 360);
      
      // draw the label centered in the button
      Font f = getFont();
      if(f != null) {
          FontMetrics fm = getFontMetrics(getFont());
          g.setColor(getForeground());
          g.drawString(label,
                       s/2 - fm.stringWidth(label)/2,
                       s/2 + fm.getMaxDescent());
      }
  }
  
  /**
   * The preferred size of the button. 
   */
  public Dimension getPreferredSize() {
      Font f = getFont();
      if(f != null) {
          FontMetrics fm = getFontMetrics(getFont());
          int max = Math.max(fm.stringWidth(label) + 40, fm.getHeight() + 40);
          return new Dimension(max, max);
      } else {
          return new Dimension(100, 100);
      }
  }
  
  /**
   * The minimum size of the button. 
   */
  public Dimension getMinimumSize() {
      return new Dimension(100, 100);
  }
   
   /**
    * Paints the button and distribute an action event to all listeners.
    */
   public void processMouseEvent(MouseEvent e) {
       Graphics g;
       switch(e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
            // render myself inverted....
            pressed = true;

            // Repaint might flicker a bit. To avoid this, you can use
            // double buffering (see the Gauge example).
            repaint(); 
            break;
          case MouseEvent.MOUSE_RELEASED:
            // render myself normal again
            if(pressed == true) {
                pressed = false;
                // Repaint might flicker a bit. To avoid this, you can use
                // double buffering (see the Gauge example).
                repaint();
            }
            break;
          case MouseEvent.MOUSE_ENTERED:
            break;
          case MouseEvent.MOUSE_EXITED:
            if(pressed == true) {
                // Cancel! Don't send action event.
                pressed = false;

                // Repaint might flicker a bit. To avoid this, you can use
                // double buffering (see the DoubleBufferPanel example above).
                repaint();

                // Note: for a more complete button implementation,
                // you wouldn't want to cancel at this point, but
                // rather detect when the mouse re-entered, and
                // re-highlight the button. There are a few state
                // issues that that you need to handle, which we leave
                // this an an excercise for the reader (I always
                // wanted to say that!)
            }
            break;
       }
       super.processMouseEvent(e);
   }   
}


Send feedback to:java-awt@java.sun.com
Copyright © 1997, Sun Microsystems, Inc. All rights reserved.
C#上位机通信层封装:西门子S7NetPlus库的优雅使用 支持S7-1200/1500(机架号0,槽号1)、S7-300/400(机架号/槽号需根据实际配置);支持位(Bit)、字节(Byte)、字(Word)、双字(DWord)、浮点数(Float/Double)等数据类型的读写;支持DB块、输入寄存器(I)、输出寄存器(Q)、内存寄存器(M)、定时器(T)、计数器(C)的操作;轻量无依赖,兼容.NET 5+。首先定义核心枚举和常量,统一规范参数类型,避免硬编码。/// 西门子PLC型号(对应不同的机架/槽号默认配置) 阅读详情

相关推荐

基于HPM5E00的EtherCAT从站开发实战:从硬件解析到软件调试

实时工业以太网通信是工业自动化与运动控制领域的核心技术,它通过硬件与协议栈的协同,实现了微秒级的高确定性数据交换。其技术价值在于为多轴同步、机器人控制等复杂场景提供了高实时性、高同步精度的通信基础。在应用场景上,广泛服务于数控机床、包装机械、半导体设备等高端制造领域。本文聚焦于EtherCAT从站开发,深入解析了基于先楫HPM5E00高性能MCU与专用从站控制器(ESC)的硬件架构设计,并详细阐述了开源协议栈SOES的移植、对象字典配置以及过程数据(PDO)映射等核心软件实践,为开发者快速构建稳定可靠的实时

weixin_30915951的博客 501

lwuit 的ui开发

   一、LWUIT简介Sun公司在2008年的Java One会议上向开发者社区推荐了LWUIT,即Light Weight UI Toolkit。LWUIT是一个轻量级Java ME UI工具包,类似Swing 的MVC架构, 支持多种布局, 皮肤更换, 字体, 触摸屏, 动画效果, Rich控件, 3D集成, Painter, 模式对话框, I18N/L10N等。Sun公司已发布了LWUI...

小科学家的专栏 281

【具身算法】VLA算法-Diffusion Policy

《扩散策略:多模态机器人控制的新方法》摘要 本文提出了一种基于扩散模型的机器人控制策略(DiffusionPolicy),用于解决视觉运动控制中的多模态行为、高维动作空间和训练稳定性问题。该方法利用去噪扩散概率模型(DDPM)生成动作序列,通过迭代优化处理复杂动作分布,显著提升了性能。实验表明,在15项机器人操作任务中,扩散策略平均性能提升46.9%,有效解决了传统显式/隐式策略的局限性。其核心优势在于:1)优雅建模多模态动作分布;2)适应高维动作空间;3)训练过程稳定。未来工作将探索与强化学习的结合及计算

puzhinan7781的博客 1393

如何使用Adonis UI打造专业WPF应用界面:轻量级UI工具包完全指南

Adonis UI是一款专为WPF应用程序设计的轻量级UI工具包,它提供了经典而增强的窗口视觉效果,帮助开发者快速构建美观、一致的用户界面。无论是桌面应用新手还是有经验的开发者,都能通过Adonis UI轻松实现专业级界面设计。 ## Adonis UI核心优势:为何选择这款WPF工具包? Adonis UI作为轻量级WPF UI工具包,具有三大核心优势: - **简洁高效**:无需复杂配置

gitblog_00928的博客 863

Apifox 自动化测试新增流程控制条件,复杂测试场景不再是问题

在 if 条件后的输入框填写请求接口得到的变量 viewed ,选择条件为「小于」,输入比较数值 10 ,并在 if 条件下添加「宠物下架处理」步骤。借助新增的自动化测试流程控制条件,测试人员就可以使用 Apifox 去实现更深层更多样的测试应用场景,帮助提升测试效率,减少复杂场景的测试操作。「查询新建宠物」、「修改宠物状态为已售出」和「查询宠物状态是否修改」步骤为当前在售宠物信息盘点的三个标准步骤,所以将这三个步骤合成一组。在循环中添加「查询在售宠物」和「修改宠物状态」步骤;

878

如何使你的直流电机闭环?(PID讲解)

看了看很多大佬写的PID讲解很全面也很复杂,实在是不适合很多萌新入坑,所以想按自己的理解写一篇通俗易懂的PID算法讲解

a2001444的博客 1万+

真香!又一款轻量级的UI前端框架!

  大家好,我是为广大程序员兄弟操碎了心的小编,每天推荐一个小工具/源码,装满你的收藏夹,每天分享一个小技巧,让你轻松节省开发效率,实现不加班不熬夜不掉头发,是我的目标!   今天小编推荐一款轻量级开源的前端框架UIkit,UIkit可以帮助你快速的开发和创建前端UI界面,支持LESS、模块化、自定义主题、及响应式设计。 案例展示   下面小编收集几个基于UIkit框架制作的优秀网页作品,小编就不上链接了,自己搜索哈,避免广告嫌疑。 UIkit 代码汇 魔工坊 衫小寨 融聚通 班得瑞全球网 宾果

Github导航站 1103

NLP高频面试题(三十一)——多模态预训练模型的主要结构、特征对齐与融合方法及对比损失函数详解

多模态预训练模型通过创新的架构设计和训练策略,在跨模态理解和表示学习上取得了显著进展。从单塔到双塔,从编码器-解码器混合到图结构模型,研究者们探索了不同的模态融合途径;配合显式与隐式对齐手段以及有效的对比学习损失,当前的多模态模型已经能够在图文检索、视觉问答、图像描述生成等任务上接近甚至超越专门的有监督模型。可以说,多模态预训练成为了继NLP和CV单模态预训练之后的又一个AI热点领域。模型规模与泛化:与单模态的大型预训练模型类似,多模态模型的参数规模和训练数据规模在迅速增长。

WeLearnNLP 2925

Lightweight UI Framework(有產生圓形Button的源碼) (转)

Lightweight UI Framework(有產生圓形Button的源碼) (转)[@more@]Java AWT: Lightweight UI framework The ProblemOne of the i...

ciya3282的博客 123

从 Chat 提示词到可运行 Fiori 应用,ADT for VS Code 正在把 RAP 开发带进 Agent 时代

本文探讨了在VS Code中使用AI辅助进行ABAP RAP开发的新模式。文章指出,传统RAP开发需要手工创建数据库表、CDS视图、行为定义等十多个关联对象,命名和关联关系容易出错。现在通过GitHub Copilot Agent Mode配合ADT MCP Server,开发者可用自然语言描述业务场景直接生成完整的RAP业务对象。这种生成式开发的核心价值在于:1)通过标准化工具接口(MCP)连接ABAP后端,确保生成符合规范的RAP对象;2)能正确处理多实体组合场景下的命名一致性和关联关系;3)保持生成结

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 89

DICOM图像知识:深入详解DICOM的层级关系

解析DICOM的四个主要层级:Patient(患者)、Study(检查)、Series(序列)和SOP(服务-对象对),探讨它们之间的关系、各自的唯一标识符以及在实际应用中的用途

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 3305

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

双重机器学习模型中解释变量是连续变量的代码,看到好多都是0/1变量,如何解决?

🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!    📌 特别说明: 文中部分技术问题来源于真实生产环境及网络公开案例,均经过精挑细选与系统化整理,并结合多位一线资深架构师和工程师多年实战经验沉淀,提

**My Coding Family** 854

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的专栏 1785

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

SAP B1中文培訓教材_SDK

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

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的专栏 1732

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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的专栏 1303

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

GENERATING INTEGER RANDOM NUMBERS(幾種產生隨機數方法的效率分析)

GENERATING INTEGER RANDOM NUMBERSThere are many ways to generate random numbers with the base libraries found in the Java 2 SDK, Standard Edition. If you havent kept up to date with changes to the

CanFly的专栏 1246

CREATING ROUND SWING BUTTONS 2

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

CanFly的专栏 1192

Adding Undo and Redo to a Text Component

 These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Adding Undo and Redo to a Text Component JTextArea textarea = new JTextArea(); final UndoManager

CanFly的专栏 1167
上一篇: Adding Undo and Redo to a Text Component
下一篇: CREATING ROUND SWING BUTTONS 2
CanFly
博客等级 码龄25年 0粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值