Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyMousePanel extends JPanel implements MouseListener{
- public static MyMousePanel inst;
- int x1,x2,y1,y2;
- int[] start = new int[2];
- int[] end = new int[2];
- MyMousePanel()
- {
- setBackground(Color.WHITE);
- addMouseListener(this);
- }
- public static MyMousePanel getInstance()
- {
- if(inst == null)
- inst = new MyMousePanel();
- return inst;
- }
- public void mouseExited(MouseEvent e)
- {
- }
- public void mouseEntered(MouseEvent e)
- {
- }
- public void mouseClicked(MouseEvent e)
- {
- }
- public void mousePressed(MouseEvent e)
- {
- x1 = e.getX();
- y1 = e.getY();
- System.out.println(x1+" "+y1);
- }
- public void mouseReleased(MouseEvent e)
- {
- x2 = e.getX();
- y2 = e.getY();
- System.out.println(x2+" "+y2);
- DrawingClass.getInstance();
- repaint();
- }
- public int[] setStart()
- {
- if(x2>=x1 && y2>=y1)
- {
- start[0] = x1;
- start[1] = y2;
- }
- if(x2>=x1 && y1>=y2)
- {
- start[0] = x1;
- start[1] = y1;
- }
- if(x1>x2 && y1>y2)
- {
- start[0] = x2;
- start[1] = y2;
- }
- if(x1>x2 && y2>y1)
- {
- start[0] = x2;
- start[1] = y1;
- }
- return start;
- }
- public int[] setEnd()
- {
- if(x2>=x1 && y2>=y1)
- {
- end[0] = x2;
- end[1] = y1;
- }
- if(x2>=x1 && y1>=y2)
- {
- end[0] = x1;
- end[1] = y1;
- }
- if(x1>x2 && y1>y2)
- {
- end[0] = x2;
- end[1] = y2;
- }
- if(x1>x2 && y2>y1)
- {
- end[0] = x2;
- end[1] = y1;
- }
- return end;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement