Buscar este blog

jueves, 4 de abril de 2013

Clase para color de fichas Dominz

A continuación comparto el código de la clase color de ficha, la cual me permite decidir sobre el color de las fichas con las cuales se va a jugar:



package dominz;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class Mico implements ActionListener{
    int a;
    JButton miboton=new JButton();
    JButton miboton1=new JButton();
    JButton miboton2=new JButton();
    JButton miboton3=new JButton();
    JLabel milabel =new JLabel();
     JFrame miven=new JFrame();
public void ven (){
 
    Font mi = new java.awt.Font("Tahoma", 1, 15);
    miven.setSize(300, 300);
    miven.setLocationRelativeTo(null);
    miven.setLayout(null);
    miven.setResizable(false);
   
    milabel.setBounds(60, 10, 250, 40);
    milabel.setText("seleccione color de fichas");
    milabel.setFont(mi);
    milabel.setForeground(Color.red);
    miven.add(milabel);
   
  miboton.setBounds(100, 50, 100, 30);
  miboton.addActionListener(this);
  miven.add(miboton);
  miboton.setText("blanco");
 
   miboton1.setBounds(100, 100, 100, 30);
  miboton1.addActionListener(this);
  miven.add(miboton1);
  miboton1.setText("azul");
 
   miboton2.setBounds(100, 150, 100, 30);
  miboton2.addActionListener(this);
  miven.add(miboton2);
  miboton2.setText("rojo");
 
   miboton3.setBounds(100, 200, 100, 30);
  miboton3.addActionListener(this);
  miven.add(miboton3);
  miboton3.setText("negro");
 
 
  miven.setVisible(true);
}
   
    @Override
    public void actionPerformed(ActionEvent e) {
       if(e.getSource()==miboton){
        a=1;
       }
        if(e.getSource()==miboton1){
        a=2;
       }
         if(e.getSource()==miboton2){
        a=3;
       }
          if(e.getSource()==miboton3){
        a=4;
       }
        miven.dispose();
    }
    public int color(){
       
        return a;
    }
   
   
}



No hay comentarios:

Publicar un comentario