java画板学习笔记

java画板学习笔记:
1.JToggleButton用于按下后不会自动弹起的按钮
2.PathIterator 接口
通过允许调用者一次一段地获取边界的路径,为实现 Shape 接口的对象提供返回其边界几何形状的机制。
Methods:
int currentSegment(double[] coords)
使用迭代返回当前路径段的坐标和类型。返回值就是路径段类型:SEG_MOVETO、SEG_LINETO、SEG_QUADTO、SEG_CUBICTO 或 SEG_CLOSE。
必须传入长度为 6 的 double 数组,该数组可用于存储点的坐标。每个点都存储为一对 double x、y 坐标。
    
3.Paint 接口
定义如何为 Graphics2D 操作生成颜色模式。
将实现 Paint 接口的类添加到 Graphics2D 上下文中,以便定义 draw 和 fill 方法所使用的颜色模式。

使用:
public abstract void setPaint(Paint paint)
为 Graphics2D 上下文设置 Paint 属性

GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
GradientPaint类使用线性颜色渐变模式填充 Shape 的方法

4.Stroke空心矩形类
Stroking a Shape is like tracing its outline with a marking pen of the appropriate size and shape.
 
5.设置快捷键
jMenu[i].setMnemonic(menuBar[i].split("\(")[1].charAt(0));

jMenuItem[i][j].setAccelerator(KeyStroke.getKeyStroke(Integer.parseInt(menuItem[i][j].split("\|")[1]),  
ActionEvent.CTRL_MASK) );
其中split()方法是将指定字符串按某指定的分隔符进行拆分,拆分将会形成一个字符串的数组并返回

如:string str = "aa.bb.cc.dd";
    string[] strArray = str.Split('.');

所得到的结果strArray的值为 string[]{"aa","bb","cc","dd"}

6.为下拉菜单的菜单项间添加分隔符
jMenu.addSeparator();

7.GridLayout(int rows,int cols, int hgap,int vgap)第三、四个参数分别为行间距和列间距

8.JScrollPane是带有滚动条的面板,但是只能添加一个组件。
JScrollPane的一般用法是先将一些组件添加到一个JPanel中,然后再把这个JPanel添加到JScrollPane中。

原文地址:https://www.cnblogs.com/jenayfighting/p/5180388.html