📄 mylineaction.java~26~
字号:
package myshapeaction;/** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: * @author * @version 1.0 */import java.awt.event.*;import myshape.*;import java.math.*;import java.util.*;public class MyLineAction extends MyActionAdapter{ private boolean canDragged=true; private MyPoint startPoint; private MyPoint endPoint=null; private MyLine line; private boolean isSecondPoint=false; public MyLineAction(boolean b) { canDragged=b; } public boolean mousePressed(MouseEvent e,Object o){ // System.out.print("lkdflskfd"); LinkedList l=(LinkedList)o; // if(startPoint==null) endPoint=startPoint; if(l.isEmpty()){ startPoint=new MyPoint(e.getX(),e.getY()); } else{ startPoint=((MyShape)l.getFirst()).getPoint(); } startPoint.setDefaultColor(MyShape.controlColor); startPoint.setColor(startPoint.getDefaultColor()); drawedItemList.add(startPoint); if(!canDragged){ if(isSecondPoint){ line=new MyLine(endPoint,startPoint); drawedItemList.add(line); isSecondPoint=false; } else{ isSecondPoint=true; } } return true; } public boolean mouseDragged(MouseEvent e,Object o){ if(canDragged &&startPoint!=null){ endPoint=new MyPoint(e.getX(),e.getY()); endPoint.setDefaultColor(MyShape.controlColor); endPoint.setColor(startPoint.getDefaultColor()); if(!endPoint.nearTo(startPoint)) { if(line!=null){ drawedItemList.removeLast(); drawedItemList.removeLast(); } line=new MyLine(startPoint,endPoint); drawedItemList.add(endPoint); drawedItemList.add(line); } } return true; } public boolean mouseReleased(MouseEvent e,Object o){ // System.out.print("lkdflskfd"); if(startPoint!=null ){ /* if(endPoint==null){ drawedItemList.removeLast(); } else if(endPoint.nearTo(centerPoint)){ drawedItemList.removeLast(); }*/ if(canDragged){ startPoint=null; endPoint=null; } line=null; // isSecondPoint=false; } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -