Skip to content

Instantly share code, notes, and snippets.

@jianleon
Created May 16, 2013 21:44
Show Gist options
  • Save jianleon/5595342 to your computer and use it in GitHub Desktop.
Save jianleon/5595342 to your computer and use it in GitHub Desktop.
import java.util.LinkedList;
import javax.swing.JOptionPane;
public class Simulador extends javax.swing.JFrame {
private static int TAM_MOCHILA;
private static int CANT_OBJETOS;
LinkedList<Objetos> objetos;
int[] valores_tam_objetos;
int[] desempeno;
double[] desempeño_normalizado;
public Simulador() {
initComponents();
//-------------------------
buttonGroup1.add(ruleta);
buttonGroup1.add(torneo);
buttonGroup1.add(elitista);
//-------------------------
pedirDatos();
tam.setText(Integer.toString(TAM_MOCHILA));
mensaje.setText("Mensajes...");
objetos = new LinkedList<Objetos>();
llenarObjetos();
mostrarObjetos();
txtobjetos.setEditable(false);
valores_tam_objetos = new int[5];
desempeno = new int[5];
desempeño_normalizado = new double[5];
}
private void calcularDesempenoNormalizado(){
for (int i = 0; i < 5; i++) {
desempeño_normalizado[i] = desempeno[i]/sumarVector(desempeno);
}
}
private int sumarVector(int[] vec){
int res=0;
for(int i =0; i < vec.length; i++){
res += vec[i];
}
return res;
}
private void generarPoblacion(int TAM){
String individuo = "";
double random;
for(int j=0; j < 5 ; j++){
individuo = "";
for(int i=0; i < TAM; i++){
random = Math.random()*0.5;
if(random < 0.25){individuo += "1";}
else{individuo += "0";}
}
if(verificarApto(individuo) <= TAM_MOCHILA){
valores_tam_objetos[j] = Integer.parseInt(individuo);
poblacion.setValueAt(individuo, j, 0);
}
else{generarPoblacion(TAM);}
}
}
private void evaluacionDesempeño(){
int resultado;
for(int j=0; j < 5 ; j++){
resultado=0;
for(int i=0;i<poblacion.getValueAt(j, 0).toString().length();i++){
if(poblacion.getValueAt(j, 0).toString().charAt(i) == '1'){
resultado += (objetos.get(i).VALOR);
}
}
desempeno[j]=resultado;
}
}
private int verificarApto(String individuo){
int resultado = 0;
for(int i=0;i<individuo.length();i++){
if(individuo.charAt(i) == '1'){
resultado += (objetos.get(i).TAM);
}
}
return resultado;
}
private void mostrarObjetos(){
txtobjetos.setText("Posibles Objetos\n\n ");
for(int i=0; i < CANT_OBJETOS; i++){txtobjetos.setText(txtobjetos.getText()+(i+1)+" ");}
txtobjetos.setText(txtobjetos.getText()+"\nt");
for(int i=0;i<CANT_OBJETOS;i++){txtobjetos.setText(txtobjetos.getText()+" "+objetos.get(i).TAM);}
txtobjetos.setText(txtobjetos.getText()+"\nv");
for(int i=0;i<CANT_OBJETOS;i++){txtobjetos.setText(txtobjetos.getText()+" "+objetos.get(i).VALOR);}
}
private void llenarObjetos(){
for(int i = 0; i < CANT_OBJETOS; i++){
objetos.add(new Objetos(Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese el Tamaño del objeto "+(i+1)+":",JOptionPane.INFORMATION_MESSAGE)),Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese el Valor del objeto "+(i+1)+":",JOptionPane.INFORMATION_MESSAGE))));
}
}
private void pedirDatos(){
TAM_MOCHILA = Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese el Tamaño del Morral:",JOptionPane.INFORMATION_MESSAGE));
CANT_OBJETOS = Integer.parseInt(JOptionPane.showInputDialog(null,"Ingrese la Cantidad de Objetos a trabajar:",JOptionPane.INFORMATION_MESSAGE));
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
ruleta = new javax.swing.JRadioButton();
elitista = new javax.swing.JRadioButton();
torneo = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
jPanel6 = new javax.swing.JPanel();
jSeparator1 = new javax.swing.JSeparator();
jScrollPane1 = new javax.swing.JScrollPane();
poblacion = new javax.swing.JTable();
jSeparator2 = new javax.swing.JSeparator();
mensaje = new javax.swing.JLabel();
jSeparator3 = new javax.swing.JSeparator();
in11 = new javax.swing.JLabel();
in12 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
in21 = new javax.swing.JLabel();
in22 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jSeparator4 = new javax.swing.JSeparator();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jSeparator5 = new javax.swing.JSeparator();
jLabel14 = new javax.swing.JLabel();
tam = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
txtobjetos = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("1. Población Inicial"));
jButton2.setText("Crear Población Inicial");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("2. Selección"));
ruleta.setText("Por Ruleta");
elitista.setText("Elitista - Ruleta");
torneo.setText("Por Torneo");
jButton1.setText("Comenzar Selección");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ruleta)
.addComponent(torneo)
.addComponent(elitista)
.addComponent(jButton1))
.addContainerGap(20, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(ruleta)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(torneo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(elitista)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("3. Cruzamiento"));
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 157, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 40, Short.MAX_VALUE)
);
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("4. Mutación"));
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 157, Short.MAX_VALUE)
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 42, Short.MAX_VALUE)
);
jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
poblacion.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
poblacion.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null},
{null},
{null},
{null},
{null}
},
new String [] {
"Población Inicial"
}
) {
Class[] types = new Class [] {
java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(poblacion);
poblacion.getColumnModel().getColumn(0).setResizable(false);
mensaje.setFont(new java.awt.Font("Arial", 1, 18));
mensaje.setText("jLabel1");
in11.setFont(new java.awt.Font("Consolas", 1, 48)); // NOI18N
in11.setText("0000");
in12.setFont(new java.awt.Font("Consolas", 1, 48)); // NOI18N
in12.setText("0000");
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel4.setText("Individuo 1:");
in21.setFont(new java.awt.Font("Consolas", 1, 48));
in21.setText("0000");
in22.setFont(new java.awt.Font("Consolas", 1, 48));
in22.setText("0000");
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel7.setText("Individuo 2:");
jLabel8.setFont(new java.awt.Font("Consolas", 1, 48));
jLabel8.setText("0000");
jLabel9.setFont(new java.awt.Font("Consolas", 1, 48));
jLabel9.setText("0000");
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel10.setText("Nuevo Individuo 1:");
jLabel11.setFont(new java.awt.Font("Consolas", 1, 48));
jLabel11.setText("0000");
jLabel12.setFont(new java.awt.Font("Consolas", 1, 48));
jLabel12.setText("0000");
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel13.setText("Nuevo Individuo 2:");
jLabel14.setText("Tamaño del Morral:");
tam.setFont(new java.awt.Font("Tahoma", 1, 36));
tam.setText("jLabel15");
txtobjetos.setColumns(20);
txtobjetos.setFont(new java.awt.Font("Consolas", 0, 18));
txtobjetos.setRows(5);
jScrollPane2.setViewportView(txtobjetos);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jSeparator3)
.addComponent(jSeparator2)
.addComponent(jSeparator4)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(in11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(in12))
.addGroup(layout.createSequentialGroup()
.addComponent(in21)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(in22)))
.addGap(40, 40, 40))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(23, 23, 23)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel13)
.addGap(23, 23, 23)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel12)))
.addGap(15, 15, 15))
.addGroup(layout.createSequentialGroup()
.addComponent(mensaje, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tam, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
.addComponent(jLabel14))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel14)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tam, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(jScrollPane2))
.addGap(18, 18, 18)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(in11, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(in12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(in21, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(in22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
.addComponent(jLabel7)
.addGap(35, 35, 35)))
.addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(27, 27, 27)))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
generarPoblacion(CANT_OBJETOS);
mensaje.setText("Población Inicial creada.");
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if(ruleta.isSelected()){}
if(torneo.isSelected()){
String i1="", i2="";
int rand = (int) Math.random()*5+1;
System.out.println(rand);
int rand2 = (int) Math.random()*4;
System.out.println(rand2);
switch(rand){
case 0:i1=poblacion.getValueAt(rand, 0).toString();
mensaje.setText("Competiran los jugadores "+(rand+1));
break;
case 1:i1=poblacion.getValueAt(rand, 0).toString();
mensaje.setText("Competiran los jugadores "+(rand+1));
break;
case 2:i1=poblacion.getValueAt(rand, 0).toString();
mensaje.setText("Competiran los jugadores"+(rand+1));
break;
case 3:i1=poblacion.getValueAt(rand, 0).toString();
mensaje.setText("Competiran los jugadores "+(rand+1));
break;
case 4:i1=poblacion.getValueAt(rand, 0).toString();
mensaje.setText("Competiran los jugadores "+(rand+1));
break;
}
rand2 = (int) Math.random()*5;
while(rand2==rand){
rand2 = (int) Math.random()*5;
}
switch(rand2){
case 0:i2=poblacion.getValueAt(rand2, 0).toString();
mensaje.setText(mensaje.getText()+" y "+(rand2+1));
break;
case 1:i2=poblacion.getValueAt(rand2, 0).toString();
mensaje.setText(mensaje.getText()+" y "+(rand2+1));
break;
case 2:i2=poblacion.getValueAt(rand2, 0).toString();
mensaje.setText(mensaje.getText()+" y "+(rand2+1));
break;
case 3:i2=poblacion.getValueAt(rand2, 0).toString();
mensaje.setText(mensaje.getText()+" y "+(rand2+1));
break;
case 4:i2=poblacion.getValueAt(rand2, 0).toString();
mensaje.setText(mensaje.getText()+" y "+(rand2+1));
break;
}
in11.setText(i1);
in21.setText(i2);
in12.setText("");
in22.setText("");
}
if(elitista.isSelected()){}
}//GEN-LAST:event_jButton1ActionPerformed
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Simulador().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JRadioButton elitista;
private javax.swing.JLabel in11;
private javax.swing.JLabel in12;
private javax.swing.JLabel in21;
private javax.swing.JLabel in22;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JSeparator jSeparator4;
private javax.swing.JSeparator jSeparator5;
private javax.swing.JLabel mensaje;
private javax.swing.JTable poblacion;
private javax.swing.JRadioButton ruleta;
private javax.swing.JLabel tam;
private javax.swing.JRadioButton torneo;
private javax.swing.JTextArea txtobjetos;
// End of variables declaration//GEN-END:variables
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment