se puede ver, la ventana
frame gestiona eventos MouseListener, visualizando mensajes.
package masterdavidjavabasico;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
/*
<APPLET
CODE=frame.class
WIDTH=300
HEIGHT=200 >
</APPLET>
*/
public class frame extends Applet implements ActionListener {
Button b1, b2;
labelFrame window;
public void init()
{
b1 = new Button("Visualizar la ventana");
add(b1);
b1.addActionListener(this);
b2 = new Button("Ocultar la ventana");
add(b2);
b2.addActionListener(this);
window = new labelFrame("Ventana Java");
window.setSize(350, 250);
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == b1){
window.setVisible(true);
}
if(event.getSource() == b2){
window.setVisible(false);
}
}
}
class labelFrame extends Frame implements MouseListener {
Label label;
labelFrame(String title){
super(title);
setLayout(new FlowLayout());
label = new Label("Hola desde Java! Esta es una ventana frame.");
add(label);
addMouseListener(this);
addWindowListener(new WindowAdapter() {public void
windowClosing(WindowEvent e) {setVisible(false);}});
}
public void mousePressed(MouseEvent e)
{
if((e.getModifiers() & InputEvent.BUTTON1_MASK) ==
InputEvent.BUTTON1_MASK){
label.setText("Boton izquierdo del raton pulsado en " + e.getX() + "," + e.getY());
}
else{
label.setText("Boton derecho del raton pulsado en " + e.getX() + "," + e.getY());
}
}
public void mouseClicked(MouseEvent e)
{
label.setText("Pulso el raton en " + e.getX() + "," + e.getY());
}
public void mouseReleased(MouseEvent e)
{
label.setText("Se solto el boton del raton.");
}
public void mouseEntered(MouseEvent e)
{
label.setText("Raton para introducir.");
}
public void mouseExited(MouseEvent e)
{
label.setText("Raton para salir.");
}
}
No hay comentarios.:
Publicar un comentario