当前位置:网站首页>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
边栏推荐
- do{}while()的妙用
- Popular understanding of linear regression (I)
- 秒殺系統3-商品列錶和商品詳情
- Popular understanding of random forest
- Popular understanding of decision tree ID3
- Creation and destruction of function stack frames
- Calibre LVL
- [combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
- Unity function - unity offline document download and use
- GCC cannot find the library file after specifying the link library path
猜你喜欢

秒杀系统3-商品列表和商品详情

MB10M-ASEMI整流桥MB10M

Popular understanding of linear regression (I)

Second kill system 3 - list of items and item details

“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画

Tensorflow realizes verification code recognition (III)

Seckill system 2 redis solves the problem of distributed session

如何使用 @NotNull等注解校验 并全局异常处理

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

函数栈帧的创建和销毁
随机推荐
Detailed explanation of four modes of distributed transaction (Seata)
求字符串函数和长度不受限制的字符串函数的详解
Vs2017 is driven by IP debugging (dual machine debugging)
Reflection on some things
App mobile terminal test [5] file writing and reading
Go language self-study series | if else statement in golang
《微服务设计》读书笔记(下)
找映射关系
do{}while()的妙用
Tensorflow realizes verification code recognition (I)
Popular understanding of linear regression (II)
Go语言自学系列 | golang中的if else if语句
Driver and application communication
首发!!lancet饿了么官方文档
2022年Q2加密市场投融资报告:GameFi成为投资关键词
Calibre LVL
Creation and destruction of function stack frames
Digital image processing -- popular Canny edge detection
How to use annotations such as @notnull to verify and handle global exceptions
一些事情的反思
