当前位置:网站首页>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
边栏推荐
- 子类隐藏父类的同名函数
- 坚持输出需要不断学习
- [系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
- 详解指针进阶1
- Three dimensional reconstruction of deep learning
- Jvm-06-execution engine
- CString getbuffer and releasebuffer instructions
- Project -- high concurrency memory pool
- Creation and destruction of function stack frames
- 求字符串函数和长度不受限制的字符串函数的详解
猜你喜欢
随机推荐
Jmeter线程组功能介绍
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
App mobile terminal test [5] file writing and reading
Unity功能——Unity离线文档下载及使用
Problems of CString in multithreading
详解指针进阶2
Calibre LVL
Popular understanding of ovo and ovr
六月 致 -.-- -..- -
[combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
Halcon and WinForm study section 2
Download and install common programs using AUR
半监督学习
Break through 1million, sword finger 2million!
Shell script import and export data
Location of software installation information and system services in the registry
Reflection on some things
App移动端测试【4】apk的操纵
WinDbg analysis dump file
How idea starts run dashboard










