Documentos de Académico
Documentos de Profesional
Documentos de Cultura
PRACTICA 2 Luis Pacheco Sanchez
PRACTICA 2 Luis Pacheco Sanchez
ACTIVIDAD 2
LA GESTIÓN DE EVENTOS
UNIDAD 1
PRESENTADO POR:
NOMBRE(S): FABIAN SANCHEZ HERNANDEZ 19640234
LA GESTIÓN DE EVENTOS.
Desarrollo:
MiApplet
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public MiApplet() {
super("AppletViewer: MiApplet");
setLayout(new FlowLayout());
miBoton = new JButton("Boton 1");
etiqueta = new JLabel();
add(miBoton);
add(etiqueta);
miBoton.addActionListener(this);
@Override
public void actionPerformed(ActionEvent evento) {
nVeces++;
cadena = ("Usted ha presionado el boton " + nVeces + " veces");
etiqueta.setText(cadena);
}
BotonesMouseListener
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public BotonesMouseListener() {
super("Home prueba");
//botón 1
setLayout(new FlowLayout());
miBoton = new JButton("SI");
add(miBoton);
miBoton.addActionListener(this);
System.out.println("");
//boton 2
miBoton2 = new JButton("NO");
add(miBoton2);
miBoton2.addActionListener(this);
System.out.println("");
//boton 3
miBoton3 = new JButton("OTRO");
add(miBoton3);
miBoton3.addActionListener(this);
System.out.println(" ");
//Etiqueta
etiqueta = new JLabel();
add(etiqueta);
@Override
public void actionPerformed(ActionEvent evento) {
if (evento.getSource() == miBoton) {
if (evento.getSource() == miBoton2) {
if (evento.getSource() == miBoton3) {
cadena = ("Ha pulsado el boton: OTRO");
etiqueta.setText(cadena);
}
BotonesMouseListenerV1
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
JLabel texto;
JCheckBox negritas, italica, rojo, arial15;
public BotonesMouseListenerV1() {
super("Prueba de JCheckBox");
setLayout(new FlowLayout());
texto = new JLabel("Estos son los CheckBox");
texto.setFont(new Font("Serif", Font.PLAIN, 14));
add(texto);
negritas.addItemListener(this);
arial15.addItemListener(this);
italica.addItemListener(this);
rojo.addItemListener(this);
arial15.addItemListener(this);
@Override
public void itemStateChanged(ItemEvent event) {
Font f = null;
Color c = null;
} else if (negritas.isSelected()) {
f = new Font("Serif", Font.BOLD, 14);
} else if (italica.isSelected()) {
f = new Font("Serif", Font.ITALIC, 14);
} else if (rojo.isSelected()) {
c = Color.RED;
} else if (arial15.isSelected()) {
f = new Font("Arial15", Font.ITALIC, 15);
texto.setFont(f);
texto.setForeground(c);
}
}
Test:
import javax.swing.JFrame;
Capturas
Conclusiones:
En conclusión este programa utilizamos todos los conocimientos antes vistos en clase
pero mejor implementados