Botones de figuras circulo,rectangulo,rombo(java)
import java.awt.geom.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Botones
{
/**
* @param args*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
BotonMarco frame =new BotonMarco();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);
}
}
class BotonMarco extends JFrame
{
public BotonMarco()
{
setTitle("Botones");
setSize(1100,700);
//dibujarComponente comp = new dibujarComponente();//add(comp);
//crear botones de figuras
JButton rectButton = new JButton("Rect");
JButton circuloButton = new JButton("Circulo");
JButton rectRoundButton = new JButton("RoundRect");//crear botones de colores
JButton rojoButton = new JButton("ROJO");
JButton azulButton = new JButton("AZUL");
JButton verdeButton = new JButton("VERDE");
buttonPanel = newdibujarComponente();
//agregar los botones figuras al panel
buttonPanel.add(rectButton);
buttonPanel.add(circuloButton);
buttonPanel.add(rectRoundButton);
//agregar los botones decolores
buttonPanel.add(rojoButton);
buttonPanel.add(azulButton);
buttonPanel.add(verdeButton);
add(buttonPanel);
//Creamos las acciones de los botones de figuras
ListenerrectAction = new Listener(1);
Listener circuloAction = new Listener(2);
Listener rectRoundAction = new Listener(3);
//Asociamos las acciones con los botones de figurasrectButton.addActionListener(rectAction);
circuloButton.addActionListener(circuloAction);
rectRoundButton.addActionListener(rectRoundAction);
}
//Agregamos el Action Listener
private class Listenerimplements ActionListener
{
public Listener(int f)
{
figura = f;
}
public Listener (Color c)
{
color=c;
}
public void actionPerformed(ActionEvent event)
{...
Regístrate para leer el documento completo.