📄 mousea.java
字号:
package DrawPlat;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class mouseA extends MouseAdapter {
private DrawPlat mdp;
private JLabel statusBar; //显示鼠标状态的提示条
private drawings[] itemList; //用来存放基本图形的数组
private int currentChoice ; //设置默认画图状态为随笔画
private int index ; //当前已经绘制的图形的数目
private int records = 0;
public mouseA(DrawPlat mdp) {
this.mdp = mdp;
index = mdp.index;
itemList = mdp.itemList;
statusBar = mdp.statusBar;
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
//设置状态提示
int x , y ;
x = e.getX();
y = e.getY();
itemList[index].x1 = itemList[index].x2 = x;
itemList[index].y1 = itemList[index].y2 = y;
//如果当前选择的图形是随笔画或橡皮擦,则进行下面的操作
if(currentChoice == 3 || currentChoice == 13) {
itemList[index].x1 = itemList[index].x2 = x;
itemList[index].y1 = itemList[index].y2 = y;
}
//如果当前选择图形式文字输入,则进行如下操作
if(currentChoice == 14) {
itemList[index].x1 = x;
itemList[index].y1 = y;
String input;
input = JOptionPane.showInputDialog(
"Please input the text you want!");
itemList[index].s1 = input;
index++;
currentChoice = 14;
mdp.createNewItem();
mdp.drawingArea.repaint();
}
}
public void mouseReleased(MouseEvent e) {
int x , y ;
x = e.getX();
y = e.getY();
if(currentChoice == 3 || currentChoice == 13 ) {
itemList[index].x1 = x;
itemList[index].y1 = y;
}
itemList[index].x2 = x;
itemList[index].y2 = y;
try{
mdp.repaint();
} catch(NullPointerException npe) {
}
mdp.records[records++]=index;
}
}//mouseA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -