Upload
diego-frans-noguera
View
129
Download
7
Embed Size (px)
Citation preview
UNIVERSIDAD CENTRAL DEL ECUADOR
FACULTAD DE CIENCIAS FÍSICAS Y MATEMÁTICAS
ESTRUCTURA DE DATOS
Nombre: Diego Noguera Vásconez
Tema: Ruleta de la fortuna
Fecha de envíode trabajo: Viernes 1 de junio del 2012
Paralelo/Carrera: Segundo/Ingeniería en informática
Docente: Ing. Boris Herrera
ENUNCIADO:
REALIZAR UNA RULETA DE PREMIOS DE N ELEMENTOS Y QUE EL
PUNTERO MARQUE EL RESULTADO OBTENIDO
Código de diseño en Jframe
package ruleta_premios;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
import ruleta_premios.Ruleta_Premios.Nodo;
public class VentanaRuleta extends javax.swing.JFrame {
public VentanaRuleta() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLayeredPane1 = new javax.swing.JLayeredPane();
Ruleta2 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
Ruleta1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON
_CLOSE);
setTitle("Rueda de la Fortuna");
setResizable(false);
jLayeredPane1.setBackground(new java.awt.Color(0, 0, 0));
jLayeredPane1.setForeground(new java.awt.Color(255, 255,
255));
Ruleta2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/Imagenes/ruleta2.
png"))); // NOI18N
Ruleta2.setBounds(0, 40, 290, 291);
jLayeredPane1.add(Ruleta2,
javax.swing.JLayeredPane.DEFAULT_LAYER);
jButton2.setText("Iniciar");
jButton2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton2ActionPerformed(evt);
}
});
jButton2.setBounds(300, 60, 90, 23);
jLayeredPane1.add(jButton2,
javax.swing.JLayeredPane.DEFAULT_LAYER);
Ruleta1.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/Imagenes/ruleta.gi
f"))); // NOI18N
Ruleta1.setBounds(0, 40, 290, 291);
jLayeredPane1.add(Ruleta1,
javax.swing.JLayeredPane.DEFAULT_LAYER);
jButton1.setText("Salir");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});
jButton1.setBounds(300, 300, 90, 23);
jLayeredPane1.add(jButton1,
javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); //
NOI18N
jLabel1.setText("Rueda de la Fortuna");
jLabel1.setBounds(10, 0, 320, 30);
jLayeredPane1.add(jLabel1,
javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLayeredPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 414,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLayeredPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 337,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
dispose();// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent
evt) {
BufferedReader buff= new BufferedReader(new
InputStreamReader(System.in));
int Elementos=Integer.parseInt(JOptionPane.showInputDialog
(null,"INGRESE EL NUMERO DE ELEMENTOS DE LA RULETA"));
int Multiplo=Integer.parseInt(JOptionPane.showInputDialog
(null,"INGRESE EL NUMERO MULTIPLO DE LOS VALORES DE
LA RUEDA"));
Nodo listac=new Nodo();
listac.dato=Multiplo;
listac.sig=listac;
//inserción horaria
Nodo anterior=listac;
Nodo temp;
System.out.println("");
System.out.println("");
System.out.println("///////////////VALORES DE LA RUEDA DE LA
FORTUNA////////////");
for(int i=2;i<=Elementos;i++)
{
temp=new Nodo();
temp.dato=i*Multiplo;
temp.sig=listac;
anterior.sig=temp;
anterior=temp;
}
temp = listac;
for (int i= 1; i <=Elementos; i++)
{
System.out.println(temp.dato);
temp =temp.sig;
}
JOptionPane.showMessageDialog (null,"RUEDA DE LA
FORTUNA");
int opcion;
VentanaRuleta abrir = new VentanaRuleta();
do{
opcion= JOptionPane.showConfirmDialog(null, "DESEA GIRAR
LA RULETA");
if (opcion==1) // no
JOptionPane.showMessageDialog (null,"GRACIAS POR
PARTICIPAR");
if (opcion==0){//si
Ruleta1.setVisible(true);
Ruleta2.setVisible(false);
int posicion_giro=0;
JOptionPane.showMessageDialog (null," LA RUEDA ESTA
GIRANDO..."+"\n¡¡¡¡¡DETENER!!!!!");
do{
posicion_giro=(int)(Math.random()*100);
System.out.println("NUMERO DE POSICIONES QUE
RECORRERA EL PUNTERO DE LA RULETA "+posicion_giro);
}while(posicion_giro<=Elementos);
//System.out.println("numero randomico generado=
"+posicion_giro);
int cont=0;
temp=listac;
anterior=listac;
for(int j=1;j<=posicion_giro;j++)
{
cont=cont+1;
if (cont>Elementos)cont=1;
System.out.println("puntero "+cont);
temp.sig=listac;
anterior.sig=temp;
anterior=temp;
temp.dato=cont*Multiplo;
System.out.println(temp.dato);
Ruleta1.setVisible(false);
Ruleta2.setVisible(true);
}
temp=listac;
JOptionPane.showMessageDialog (null,"EL VALOR QUE GANO
ES "+temp.dato+" DÓLARES"+
"\n y la posicion del puntero es " +cont+" en la lista circular");
}
}while(opcion==0);
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel
setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with
the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h
tml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaRuleta.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaRuleta.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaRuleta.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaRuleta.class.getName()).
log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VentanaRuleta().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel Ruleta1;
private javax.swing.JLabel Ruleta2;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLayeredPane jLayeredPane1;
// End of variables declaration
}
Ejecución del programa