- Primer punto, (Jairo Vélez y Alejandro Rúiz):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class uno extends JFrame implements ActionListener
{
private JTextField cajaCol;
private JButton miColor1, miColor2;
private String c;
public uno()
{
super("Colores");
Container c = getContentPane();
c.setLayout(new GridLayout(3, 2));
c.add(new JLabel("Color 1"));
miColor1 = new JButton ("Azul");
c.add(miColor1);
miColor1.addActionListener(this);
c.add(new JLabel("Color 2"));
miColor2 = new JButton ("Negro");
c.add(miColor2);
miColor2.addActionListener(this);
c.add(new JLabel("Seleccion"));
cajaCol = new JTextField();
c.add(cajaCol);
setSize(475, 100);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String argumento = e.getActionCommand();
if (argumento == "Azul")
{
c = "Azul";
cajaCol.setText(String.valueOf(c));
}
else
{
c = "Negro";
cajaCol.setText(String.valueOf(c));
}
}
public static void main(String[] args)
{
uno ME = new uno();
ME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
- Primer punto, (Juan Esteban Morales y José Manuel Rendón):
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Botones extends JFrame
implements ActionListener
{
private JTextField micolor;
public Botones()
{
super("Escoger Colores");
Container contenedor = getContentPane();
contenedor.setLayout(new GridLayout(3,3));
contenedor.add(new JLabel("Boton 1"));
JButton miboton = new JButton("Rojo");
contenedor.add(miboton);
miboton.addActionListener(this);
contenedor.add(new JLabel("Boton 2"));
JButton miboton1 = new JButton("Negro");
contenedor.add(miboton1);
miboton1.addActionListener(this);
contenedor.add(new JLabel("Seleccion"));
micolor = new JTextField();
contenedor.add(micolor);
setSize(200,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String argumento = e.getActionCommand();
if (argumento.equals("Rojo"))
micolor.setText(String.valueOf("Rojo"));
else //(argumento.equals("Negro"))
micolor.setText(String.valueOf("Negro"));
}
public static void main (String [] args)
{
Botones aplicacion = new Botones();
aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
- Segundo punto, (Jairo Vélez y Alejandro Rúiz):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class dos
{
public static void main(String[] args) {
JFrame frame = new JFrame();
Container cp = frame.getContentPane();
cp.setLayout (new FlowLayout());
ActionListener escuchador = new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
if (e.getActionCommand() == "Verde")
{
JOptionPane.showMessageDialog(null, "Rey de copas");
}
else
{
JOptionPane.showMessageDialog(null, "El poderoso");
}
};
};
ButtonGroup group = new ButtonGroup();
String[] sa = {"Verde","Rojo"};
for (int i=0; i<=sa.length-1;++i)
{
JRadioButton b= new JRadioButton (sa [i]);
group.add(b);
cp.add(b);
b.addActionListener(escuchador);
}
frame.pack ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
- Segundo punto, (Juan Esteban Morales y José Manuel Rendón):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class RadioBoton
{
public static void main(String [] args)
{
JFrame frame = new JFrame();
Container contenedor = frame.getContentPane();
contenedor.setLayout(new FlowLayout());
ActionListener listener = new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
String a = e.getActionCommand();
if (a.equals("Nacional"))
JOptionPane.showMessageDialog(null,"Rey de Copas");
else
JOptionPane.showMessageDialog(null,"El Poderoso");
}
};
ButtonGroup grupo = new ButtonGroup();
String[] sa = {"Nacional","Medellin"};
for(int i=0; i<=sa.length-1; i++)
{
JRadioButton b = new JRadioButton(sa[i]);
grupo.add(b);
contenedor.add(b);
b.addActionListener(listener);
}
frame.setSize(300,60);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
No hay comentarios:
Publicar un comentario