Sistemas Oprativos

Páginas: 3 (554 palabras) Publicado: 5 de noviembre de 2012
Codigo del Applet de las Torres de Hanoi
Clase Principal
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;public class Principla extends JApplet {JTextField ndiscos;
JButton VerSolucion;
JLabel l;

public void init(){
JPanel p=new JPanel();
l=new JLabel("Numero de Discos");
ndiscos=new JTextField(6);
VerSolucion=new JButton("VerSolucion");
VerSolucion.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
TorresFrame tf=newTorresFrame(Integer.parseInt(ndiscos.getText()));
tf.setVisible(true);
tf.setBounds(0,0,510,550);
tf.setLocationRelativeTo(null);
tf.setTitle("Solucion Torres de Hanoi");
}
});
p.add(l);
p.add(ndiscos);p.add(VerSolucion);
add(p);
}} |
Clase TorresFrame
import java.awt.*;

public class TorresFrame extends Frame{
private Hanoi h;
private boolean resolver;

public TorresFrame(int ndiscos) {setLayout(new FlowLayout());
h = new Hanoi(ndiscos);
resolver = true;
}

public void paint(Graphics g) {h.dibuja(g);
if(resolver) {
h.resuelve(g);
}
}

} |
Clase Hanoi
import java.awt.*;public class Hanoi {private int n;
private Poste izq, cen, der;public Hanoi(int n) {
this.n = n;
izq = new Poste(n, 80);
cen = new Poste(0, 250);
der = new Poste(0, 420);
}public voidresuelve(Graphics g) {solucion(n, izq, der, cen, g);
}public void dibuja(Graphics g) {izq.dibuja(g);
cen.dibuja(g);
der.dibuja(g);
}

public void reinicia() {izq.ponDiscos(n);
der.ponDiscos(0);cen.ponDiscos(0);
}public void solucion(int n, Poste f, Poste d, Poste a,Graphics g) {if(n==0){
return;
}else{
solucion(n-1,f,a,d,g);
mover(f,a,g);
solucion(n-1,d,f,a,g);
} }

public voidmover(Poste a, Poste b, Graphics g) {try {
Thread.sleep(1000);
} catch(InterruptedException e) {
g.drawString("Error en sleep", 100, 100);
}Disco d=a.quitaDisco();
b.agregaDisco(d);
a.dibuja(g);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • sistemas oprativos
  • SISTEMAS OPRATIVOS
  • Trabajo De Los Sistemas Oprativos
  • Sistema oprativos
  • Sistemas Oprativos
  • Sistemas oprativos
  • Resumen Del Sistema Oprativo Internetwork Ios
  • Practica 9 Configuración Básica De Un Switch Y Adninistra El Sistema Oprativo (Ios

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS