当前位置:网站首页>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
边栏推荐
- Seckill system 2 redis solves the problem of distributed session
- Find mapping relationship
- Unity功能——Unity离线文档下载及使用
- The difference between RAR and zip files
- Qt常用语句备忘
- Digital image processing -- popular understanding of corrosion and expansion
- Go language self-study series | if else if statement in golang
- Create gradle project
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
- Visual upper system design and development (Halcon WinForm) -2 Global variable design
猜你喜欢
Microservices - load balancing ribbon
半监督学习
Distributed task scheduling XXL job
Function introduction of JMeter thread group
qt使用QZxing生成二维码
Visual host system design and development (Halcon WinForm)
Shell script import and export data
Seckill system 2 redis solves the problem of distributed session
App移动端测试【3】ADB命令
秒殺系統3-商品列錶和商品詳情
随机推荐
App移动端测试【4】apk的操纵
Popular understanding of decision tree ID3
坚持输出需要不断学习
Secsha system 1- login function
VS2017通过IP调试驱动(双机调试)
嵌入式开发:避免开源软件的7个理由
Location of software installation information and system services in the registry
Summary of JVM knowledge points
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
Persisting in output requires continuous learning
Visual host system design and development (Halcon WinForm)
Seckill system 2 redis solves the problem of distributed session
Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
Calibre LVL
首发!!lancet饿了么官方文档
Redis high availability and persistence
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
Tensorflow realizes verification code recognition (III)
子类隐藏父类的同名函数
Backtracking method to solve batch job scheduling problem