当前位置:网站首页>How to thicken the brush in the graphical interface
How to thicken the brush in the graphical interface
2022-07-03 15:54:00 【Zhangjian Tianya 2.0】
public void actionPerformed(ActionEvent e) {
String bstr=e.getActionCommand();// Get the text content on the component ;\
str =e.getActionCommand();
// Determine whether the brush needs to be thickened ;setStoke The method can make the brush bold ; Understand that the object to be filled is an interface. Normally
// Is to create a class to implement the abstract method of the interface , But search interface Stroke You can know the class BasicStroke Rewriting has been implemented
if (str.equals(" In bold "))
{
BasicStroke stroke =new BasicStroke(2.0f);// Use an instance to host , Set the information of the brush
Graphics2D gr2 = (Graphics2D) gr;// I don't understand why gr2 Set the brush size , result gr Also set the size
gr2.setStroke(stroke);
}
if (str.equals(" Restore brush "))
{
BasicStroke stroke =new BasicStroke(1.0f);// Use an instance to host , Set the information of the brush
Graphics2D gr2 = (Graphics2D) gr;// I don't understand why gr2 Set the brush size , result gr Also set the size
gr2.setStroke(stroke);
}1. First of all, I know in Graphics There is no method to set the brush thickness in the component
2. So the introduction of Graphics2D Components , And use this class ( Components ) Another instance is created
3.gr2.setStroke(stroke)
stroke The role of : This instance stores brush thickness information , It through setStroke() Function passed to object gr2;
Observe setStroke() Source code for method

See that the type of its parameter needs to be an instance of a class (Stroke)
see Stroke Source code
The observed Stroke It's an interface , If you want to in setStroke() If you set parameters , According to the original method, you need to rewrite a class to inherit the interface , Rewrite the abstract methods of the interface
however Java There are already classes that inherit this interface ; We can use it directly and make the result simple ; Directly reference the inherited class ; Then create an instance with this class ; Store the brush thickness information in the instance , Add this instance to the brush
Document query image

Found already BrokeStroke Class inherits the interface
边栏推荐
- MongoDB 的安装和基本操作
- Tensorflow realizes verification code recognition (II)
- Microservices Seata distributed transactions
- “用Android复刻Apple产品UI”(3)—优雅的数据统计图表
- Detailed pointer advanced 2
- Jvm-06-execution engine
- ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
- Detailed explanation of string function and string function with unlimited length
- Distributed task scheduling XXL job
- 大csv拆分和合并
猜你喜欢

qt使用QZxing生成二维码

Microservice API gateway

How to use annotations such as @notnull to verify and handle global exceptions

Microservices - load balancing ribbon

UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)

深度学习之三维重建

Break through 1million, sword finger 2million!

WinDbg分析dump文件

Unity function - unity offline document download and use
![[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree](/img/cd/00954b9c592c253d42e6a3b8298999.jpg)
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
随机推荐
Distributed task scheduling XXL job
秒杀系统3-商品列表和商品详情
Principles of several common IO models
分布式事务(Seata) 四大模式详解
《微服务设计》读书笔记(上)
需要知道的字符串函数
子类隐藏父类的同名函数
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
找映射关系
Microservices - load balancing ribbon
Popular understanding of linear regression (II)
关于网页中的文本选择以及统计选中文本长度
WinDbg analysis dump file
Custom annotation
WinDbg分析dump文件
Visual upper system design and development (Halcon WinForm) -2 Global variable design
Large CSV split and merge
整形和浮点型是如何在内存中的存储
qt使用QZxing生成二维码
