Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/10/2011, 17:12
link01
 
Fecha de Ingreso: octubre-2011
Mensajes: 58
Antigüedad: 12 años, 7 meses
Puntos: 0
Respuesta: Pasar de código estructurado a Orientado a Objetos

Estoy todo enredado, esto es lo que tengo:

Código Java:
Ver original
  1. //Clase para el Menu
  2. package Ahorcaito;
  3.  
  4. import javax.swing.JMenu;
  5.  
  6. import javax.swing.JMenuBar;
  7.  
  8. import javax.swing.JMenuItem;
  9.  
  10.  
  11.  
  12.  
  13.  
  14. public class Menu extends JMenuBar{
  15.  
  16.     private JMenuBar mb = new JMenuBar();
  17.  
  18.     private JMenu menu = new JMenu();
  19.  
  20.     static JMenuItem reiniciar = new JMenuItem();
  21.  
  22.     static JMenuItem salir = new JMenuItem();
  23.  
  24.    
  25.  
  26.     public Menu(){
  27.  
  28.         mb = this;
  29.  
  30.         menu.setText("Menú");
  31.  
  32.         reiniciar.setText("Reiniciar");
  33.  
  34.         menu.add(reiniciar);
  35.  
  36.         menu.addSeparator();
  37.  
  38.         salir.setText("Salir");
  39.  
  40.         menu.add(salir);
  41.  
  42.         this.add(menu);
  43.  
  44.     }
  45.  
  46.  
  47.  
  48. }

Código Java:
Ver original
  1. //Clase para el panel que muestra los guiones bajos o rayitas
  2. package Ahorcaito;
  3.  
  4.  
  5.  
  6. import java.awt.Color;
  7.  
  8. import java.awt.FlowLayout;
  9.  
  10. import java.awt.Font;
  11.  
  12.  
  13.  
  14. import javax.swing.BorderFactory;
  15.  
  16. import javax.swing.JLabel;
  17.  
  18. import javax.swing.JPanel;
  19.  
  20. import javax.swing.border.TitledBorder;
  21.  
  22.  
  23.  
  24.  
  25.  
  26. public class PanelPalabras extends JPanel{
  27.  
  28.     private JPanel panelPalabras = null;
  29.  
  30.     private TitledBorder titulo;
  31.  
  32.     private String palabraElegida = "", guionesBajosExternos = "", string = "", solucion = "", letraEscogida = "", guionesBajos = "";
  33.  
  34.     private Font tamanoG;
  35.  
  36.     private boolean chequearif;
  37.  
  38.     private char[] letra;
  39.  
  40.     private char[] arrayGuiones;
  41.  
  42.    
  43.  
  44.     public PanelPalabras(){
  45.  
  46.         panelPalabras = this;
  47.  
  48.         this.setLayout(new FlowLayout());
  49.  
  50.         this.setSize(275,100);
  51.  
  52.         this.setBackground(Color.lightGray);
  53.  
  54.         titulo = BorderFactory.createTitledBorder("Palabras");
  55.  
  56.         this.setBorder(titulo);
  57.  
  58.     }
  59.  
  60. }

Código Java:
Ver original
  1. //se muestra las letras utilizadas
  2. package Ahorcaito;
  3.  
  4. import java.awt.Color;
  5.  
  6. import java.awt.FlowLayout;
  7.  
  8. import javax.swing.BorderFactory;
  9.  
  10. import javax.swing.JLabel;
  11.  
  12. import javax.swing.JPanel;
  13.  
  14. import javax.swing.border.TitledBorder;
  15.  
  16.  
  17.  
  18.  
  19.  
  20. public class PanelIntentos extends JPanel {
  21.  
  22.     private JPanel panelIntentos;
  23.  
  24.     private TitledBorder titulo;
  25.  
  26.     Textos texto = new Textos();
  27.  
  28.    
  29.  
  30.     public PanelIntentos(){
  31.  
  32.         panelIntentos = this;
  33.  
  34.         this.setLayout(new FlowLayout());
  35.  
  36.         this.setSize(275,100);
  37.  
  38.         this.setBackground(Color.lightGray);
  39.  
  40.         titulo = BorderFactory.createTitledBorder("Palabras");
  41.  
  42.         this.setBorder(titulo);
  43.  
  44.         this.add(texto.lbl_img);
  45.  
  46.        
  47.  
  48.     }
  49.  
  50. }

Código Java:
Ver original
  1. //Clase para el panel donde se escoge la letra
  2. package Ahorcaito;
  3.  
  4. import java.awt.Color;
  5.  
  6. import java.awt.FlowLayout;
  7.  
  8. import javax.swing.JButton;
  9.  
  10. import javax.swing.BorderFactory;
  11.  
  12. import javax.swing.JComboBox;
  13.  
  14. import javax.swing.JPanel;
  15.  
  16. import javax.swing.border.TitledBorder;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. public class PanelLetras extends JPanel{
  23.  
  24.     private JPanel panelLetras;
  25.  
  26.     private TitledBorder titulo;
  27.  
  28.     static String[] abcdario = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  29.  
  30.     static JComboBox jcb = new JComboBox(abcdario);
  31.  
  32.     static JButton boton = new JButton();
  33.  
  34.    
  35.  
  36.    
  37.  
  38.     public PanelLetras(){
  39.  
  40.         panelLetras = this;
  41.  
  42.         this.setLayout(new FlowLayout());
  43.  
  44.         this.setSize(275,100);
  45.  
  46.         this.setBackground(Color.lightGray);
  47.  
  48.         titulo = BorderFactory.createTitledBorder("Letras");
  49.  
  50.         this.setBorder(titulo);
  51.  
  52.         boton.setText("Aceptar");
  53.  
  54.         this.add(jcb);
  55.  
  56.         this.add(boton);
  57.  
  58.     }
  59.  
  60.  
  61.  
  62. }

Código Java:
Ver original
  1. //muestra los intentos que faltan para perder, si gano o perdio
  2. package Ahorcaito;
  3.  
  4. import java.awt.Color;
  5.  
  6. import java.awt.FlowLayout;
  7.  
  8.  
  9.  
  10. import javax.swing.BorderFactory;
  11.  
  12. import javax.swing.JLabel;
  13.  
  14. import javax.swing.JPanel;
  15.  
  16. import javax.swing.border.TitledBorder;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. public class PanelMensajes extends JPanel{
  23.  
  24.     private JPanel panelMensajes = new JPanel();
  25.  
  26.     private TitledBorder titulo;
  27.  
  28.     private JLabel lbl_msj = new JLabel("Le quedan 6 intentos");
  29.  
  30.    
  31.  
  32.     public PanelMensajes(){
  33.  
  34.         panelMensajes = this;
  35.  
  36.         this.setLayout(new FlowLayout());
  37.  
  38.         this.setSize(175,100);
  39.  
  40.         this.setBackground(Color.lightGray);
  41.  
  42.         titulo = BorderFactory.createTitledBorder("Mensajes");
  43.  
  44.         this.setBorder(titulo);
  45.  
  46.         this.add(lbl_msj);
  47.  
  48.     }
  49.  
  50. }

Código Java:
Ver original
  1. //cambia las imagenes
  2. package Ahorcaito;
  3.  
  4. import java.awt.Color;
  5.  
  6. import java.awt.FlowLayout;
  7.  
  8.  
  9.  
  10. import javax.swing.Icon;
  11.  
  12. import javax.swing.ImageIcon;
  13.  
  14. import javax.swing.JLabel;
  15.  
  16. import javax.swing.JPanel;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. public class PanelImg extends JPanel{
  23.  
  24.     private JPanel panelImg;
  25.  
  26.     Icon[] imagen = {new ImageIcon(getClass().getResource("1.gif")), new ImageIcon(getClass().getResource("2.gif")),
  27.  
  28.                             new ImageIcon(getClass().getResource("3.gif")), new ImageIcon(getClass().getResource("4.gif")),
  29.  
  30.                             new ImageIcon(getClass().getResource("5.gif")), new ImageIcon(getClass().getResource("6.gif")),
  31.  
  32.                             new ImageIcon(getClass().getResource("7.gif"))};
  33.  
  34.    
  35.  
  36.     public PanelImg(){
  37.  
  38.         panelImg = this;
  39.  
  40.         this.setLayout(new FlowLayout());
  41.  
  42.         this.setSize(175,100);
  43.  
  44.         this.setBackground(Color.lightGray);
  45.  
  46.        
  47.  
  48.     }
  49.  
  50. }

Código Java:
Ver original
  1. //junto todas las clases que tienen paneles en una ventana
  2. package Ahorcaito;
  3.  
  4. import java.awt.GridLayout;
  5.  
  6.  
  7.  
  8. import javax.swing.ImageIcon;
  9.  
  10. import javax.swing.JFrame;
  11.  
  12. import javax.swing.JPanel;
  13.  
  14.  
  15.  
  16.  
  17.  
  18. public class Ventana extends JFrame{
  19.  
  20.     private JPanel panelIzq = new JPanel();
  21.  
  22.     private JPanel panelDer = new JPanel();
  23.  
  24.    
  25.  
  26.     public Ventana(){
  27.  
  28.         Menu menu = new Menu();
  29.  
  30.         PanelPalabras panelPalabras = new PanelPalabras();
  31.  
  32.         PanelIntentos panelIntentos = new PanelIntentos();
  33.  
  34.         PanelLetras panelLetras = new PanelLetras();
  35.  
  36.         PanelMensajes panelMensajes = new PanelMensajes();
  37.  
  38.         PanelImg panelImg = new PanelImg();
  39.  
  40.         Funciones funciones = new Funciones();
  41.  
  42.         Textos texto = new Textos();
  43.  
  44.        
  45.  
  46.        
  47.  
  48.         texto.lbl_img.setIcon(imagen[0]);
  49.  
  50.         PanelImg.add(texto.lbl_img);
  51.  
  52.        
  53.  
  54.         this.setTitle("Ahorcaito");
  55.  
  56.         this.setSize(570,470);
  57.  
  58.         this.setLayout(new GridLayout(1,2));
  59.  
  60.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  61.  
  62.         this.setIconImage(new ImageIcon("icono.gif").getImage());
  63.  
  64.         this.setJMenuBar(menu);
  65.  
  66.        
  67.  
  68.         panelIzq.setSize(280,4210);
  69.  
  70.         panelIzq.setLayout(new GridLayout(4,1));
  71.  
  72.         panelDer.setSize(280,410);
  73.  
  74.         panelDer.setLayout(new GridLayout(1,1));
  75.  
  76.        
  77.  
  78.         panelIzq.add(panelPalabras);
  79.  
  80.         panelIzq.add(panelIntentos);
  81.  
  82.         panelIzq.add(panelLetras);
  83.  
  84.         panelIzq.add(panelMensajes);
  85.  
  86.        
  87.  
  88.         panelDer.add(panelImg);
  89.  
  90.        
  91.  
  92.         this.add(panelIzq);
  93.  
  94.         this.add(panelDer);
  95.  
  96.     }
  97.  
  98.  
  99.  
  100. }
__________________
La libertad más difícil de conservar es la de equivocarse. - Morris Wes

Lo que faltaba en internet: http://binar10s.blogspot.com/