📄 dashedborder.java
字号:
/*====================================================================*\DashedBorder.javaDashed border class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage gui;//----------------------------------------------------------------------// IMPORTSimport java.awt.BasicStroke;import java.awt.Component;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Insets;import java.awt.Rectangle;import javax.swing.border.AbstractBorder;//----------------------------------------------------------------------// DASHED BORDER CLASSpublic class DashedBorder extends AbstractBorder{////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// public DashedBorder( float dashLength ) { float[] dash = { dashLength }; stroke = new BasicStroke( 1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : overriding methods//////////////////////////////////////////////////////////////////////// public Insets getBorderInsets( Component component ) { return new Insets( 1, 1, 1, 1 ); } //------------------------------------------------------------------ public Insets getBorderInsets( Component component, Insets insets ) { insets.top = insets.left = insets.bottom = insets.right = 1; return insets; } //------------------------------------------------------------------ public boolean isBorderOpaque( ) { return true; } //------------------------------------------------------------------ public void paintBorder( Component component, Graphics gr, int x, int y, int width, int height) { Graphics2D gr2d = (Graphics2D)gr; gr2d.setColor( component.getForeground( ) ); gr2d.setStroke( stroke ); gr2d.draw( new Rectangle( x, y, width - 1, height - 1 ) ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance variables//////////////////////////////////////////////////////////////////////// private BasicStroke stroke;}//----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -