Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Applet
- package disegnaLinea;
- import java.applet.Applet;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.*;
- import java.util.*;
- public class Disegna extends Applet implements MouseMotionListener, MouseListener {
- /**
- *
- */
- private static final long serialVersionUID = 4382358404236741121L;
- public void init(){
- addMouseMotionListener(this);
- addMouseListener(this);
- }
- //private int x1, y1, x2, y2;
- private Vector <Linea> coordinate = new Vector <Linea>();
- /*private Image OffScreenImage;
- public void start(){
- OffScreenImage = createImage(getSize().width, getSize().height);
- }*/
- public void paint(Graphics g){
- for(int i = 1; i < coordinate.size()-1; i++){
- if (coordinate.get(i).getConnected())
- {
- g.drawLine(coordinate.get(i-1).getX(), coordinate.get(i-1).getY(), coordinate.get(i).getX(), coordinate.get(i).getY());
- }
- }
- }
- /*public void update(Graphics g){
- if(OffScreenImage != null){
- Graphics offScreenGraphics = OffScreenImage.getGraphics();
- offScreenGraphics.setColor(getBackground());
- //offScreenGraphics.fillRect(0, 0, getSize().width, getSize().height);
- offScreenGraphics.setColor(g.getColor());
- paint(offScreenGraphics);
- g.drawImage(OffScreenImage, 0, 0, this);
- }
- }*/
- @Override
- public void mouseDragged(MouseEvent e) {
- /*if(x1 == 0 && y1 == 0){
- x1 = e.getX();
- y1 = e.getY();
- x2 = e.getX();
- y2 = e.getY();
- }else{
- x1 = x2;
- y1 = y2;
- x2 = e.getX();
- y2 = e.getY();
- }
- getGraphics().drawLine(x1, y1, x2, y2);*/
- coordinate.add(new Linea(e.getX(), e.getY(), true));
- repaint();
- }
- @Override
- public void mouseMoved(MouseEvent e) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mousePressed(MouseEvent e) {
- coordinate.add(new Linea(e.getX(), e.getY(), false));
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- /*x1 = 0;
- y1 = 0;*/
- }
- }
- //Classe da Vectorizzare
- package disegnaLinea;
- public class Linea {
- private int x, y;
- private boolean isConnected;
- public Linea(int _x, int _y, boolean isConnected){
- this.x = _x;
- this.y = _y;
- this.isConnected = isConnected;
- }
- public int getX(){
- return this.x;
- }
- public int getY(){
- return this.y;
- }
- public boolean getConnected()
- {
- return isConnected;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement