jueves, 1 de marzo de 2012

Mouse draggin y aaction performed...


package VentanasYEventos;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class Ventana implements MouseListener,MouseMotionListener,ActionListener{
private Frame f;
private TextField tf;
private Label label;
private Button boton;

public Ventana()
{
f=new Frame("Ventana Test");
tf=new TextField(30);
}

public void launchFrame()
{
f.setSize(300,200);
f.setBackground(Color.CYAN);
label=new Label("Ventana Test");

f.add(label,BorderLayout.NORTH);
f.add(tf, BorderLayout.SOUTH);
boton=new Button("ok");
f.add(boton,BorderLayout.EAST);
boton.addActionListener(this);
f.addMouseListener(this);
f.addMouseMotionListener(this);
f.addWindowListener(new Manejador());
f.setVisible(true);

}
public static void main(String[] args) {
Ventana v=new Ventana();
v.launchFrame();
}

@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 arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void mouseDragged(MouseEvent e) {
String s="Movimiento del raton : X "+e.getX()+" Y "+e.getY();
label.setText(s);


}

@Override
public void mouseMoved(MouseEvent e) {


}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==boton)
{
label.setText(tf.getText());
}

}


}

No hay comentarios:

Publicar un comentario