Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/10/2015, 08:21
skirlappa
 
Fecha de Ingreso: junio-2005
Mensajes: 107
Antigüedad: 18 años, 10 meses
Puntos: 0
JButton aparece al pasar el puntero del raton

Hola,

Estoy haciendo un pequeño programa en java, pero no se porque el JButton solo aparece al pasar el puntero del ratón donde se encuentra, una vez que pasas el puntero el ratón aparece y ya no se va, gracias por la ayuda de antemano.


Código Java:
Ver original
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package dni;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.Color;
  10. import java.awt.Container;
  11. import java.awt.FlowLayout;
  12. import java.awt.Font;
  13. import java.awt.GridBagConstraints;
  14. import java.awt.GridBagLayout;
  15. import java.awt.Point;
  16. import static java.awt.SystemColor.menu;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.KeyEvent;
  20. import javax.swing.Icon;
  21. import javax.swing.ImageIcon;
  22. import javax.swing.JButton;
  23. import javax.swing.JFrame;
  24. import javax.swing.JMenu;
  25. import javax.swing.JMenuBar;
  26. import javax.swing.JMenuItem;
  27. import javax.swing.JLabel;
  28. import javax.swing.JOptionPane;
  29. import javax.swing.JPanel;
  30. import javax.swing.JTextField;
  31. import javax.swing.SwingConstants;
  32.  
  33. /**
  34.  *
  35.  * @author Funcionario
  36.  */
  37. public class DNI extends JFrame
  38. {
  39.     private JLabel logos, titulo, campoNombre, campoApellidos, campoDNI, campoFecha;
  40.     private JLabel barraEstado;
  41.     private JTextField textNombre, textApellidos, textDNI, textFecha;
  42.     private JMenu gestiones, buscador, informacion;
  43.     private JMenuItem altas, gestionesItem, bajas, DNI, nombre, autor, ayuda, aviso, modificar;
  44.     private BorderLayout esquema;
  45.     private JButton alta;
  46.    
  47.     public DNI()
  48.     {
  49.        
  50.         //Creamos el texto
  51.         super("DNI OVER");
  52.         esquema = new BorderLayout(5,5);
  53.         setLayout(null);
  54.        
  55.         //Cremoas la barra del menu
  56.         JMenuBar menu = new JMenuBar();
  57.        
  58.         //Creamos cada opción simple en el menu
  59.         gestiones = new JMenu("Gestiones");
  60.         altas = new JMenuItem ("Altas");
  61.         gestionesItem = new JMenuItem ("Gestiones realizadas");
  62.         modificar = new JMenuItem("Modificar un registro");
  63.         bajas = new JMenuItem ("Dar de baja");
  64.        
  65.        
  66.         buscador = new JMenu("Buscador");
  67.         DNI = new JMenuItem ("Por DNI");
  68.         nombre = new JMenuItem ("Por nombre");
  69.        
  70.         informacion = new JMenu("Ayuda");
  71.         autor = new JMenuItem ("Autor");
  72.         ayuda = new JMenuItem ("Ayuda");
  73.         aviso = new JMenuItem ("Aviso legal");
  74.        
  75.         //Añadimos el logo en el centro.
  76.         Icon logo = new ImageIcon(getClass().getResource("../img/log.png"));
  77.         logos = new JLabel("", logo, SwingConstants.CENTER);
  78.         logos.setBounds(225, 140, 350, 75);
  79.         add(logos);
  80.  
  81.        
  82.         //añadimos la barra
  83.         setJMenuBar(menu);
  84.         //Añadimos cada opcion del menu
  85.  
  86.        
  87.         manejadorCampo manejador = new manejadorCampo();
  88.         //altas.addActionListener(manejador);
  89.         menu.add(gestiones);
  90.         gestiones.add(altas);
  91.         altas.addActionListener(manejador);
  92.        
  93.         gestiones.add(modificar);
  94.         gestiones.add(gestionesItem);
  95.         gestiones.add(bajas);
  96.        
  97.         menu.add(buscador);
  98.         buscador.add(DNI);
  99.         buscador.add(nombre);
  100.        
  101.         menu.add(informacion);
  102.         informacion.add(autor);
  103.         informacion.add(ayuda);
  104.         informacion.add(aviso);
  105.        
  106.  
  107.        }
  108.     //Aqui va el evento.
  109.         public void altas()
  110.         {          
  111.                     //JLabel titulo de la pagina//
  112.                    titulo = new JLabel("ALTAS");
  113.                    //Creo el tamaño y la fuenta del texto
  114.                    Font auxFont = titulo.getFont();
  115.                    titulo.setFont(new Font(auxFont.getFontName(),auxFont.getStyle(),30));
  116.                    // Lo pongo en la posición deseada
  117.                    titulo.setBounds(325, 25, 100, 25);
  118.                    //Agrego
  119.                    add(titulo);
  120.                    titulo.setVisible(false);
  121.                    //////////////////////////
  122.                    //Cremos el camo nombre
  123.                    campoNombre = new JLabel("Nombre:");
  124.                    campoNombre.setBounds(200, 50, 75, 75);
  125.                    add(campoNombre);
  126.                    campoNombre.setVisible(false);
  127.                    ////////////
  128.                    //Campo Apellidos//
  129.                    campoApellidos = new JLabel("Apellidos:");
  130.                    campoApellidos.setBounds(200, 70, 75, 75);
  131.                    add(campoApellidos);
  132.                    campoApellidos.setVisible(false);
  133.                    ////////////////////
  134.                    //Campo DNI ////
  135.                    campoDNI = new JLabel("DNI:");
  136.                    campoDNI.setBounds(200, 90, 75, 75);
  137.                    add(campoDNI);
  138.                    campoDNI.setVisible(false);
  139.                    /////fecha/////
  140.                    campoFecha = new JLabel("Fecha caducidad:");
  141.                    campoFecha.setBounds(200, 110, 100, 75);
  142.                    add(campoFecha);
  143.                    campoFecha.setVisible(false);
  144.                    ///////////
  145.                   //Creamos el campo textFiel nombre//
  146.                    textNombre = new JTextField("");
  147.                    textNombre.setBounds(325, 80, 200, 20);
  148.                    add(textNombre);
  149.                    /////////////
  150.                    textApellidos = new JTextField("");
  151.                    textApellidos.setBounds(325, 100, 200, 20);
  152.                    add(textApellidos);
  153.                    /////////////
  154.                    textDNI = new JTextField("");
  155.                    textDNI.setBounds(325, 120, 200, 20);
  156.                    add(textDNI);
  157.                    //////////////
  158.                    textFecha = new JTextField("");
  159.                    textFecha.setBounds(325, 140, 200, 20);
  160.                    add(textFecha);
  161.                    ///Creamos el boton para registrar el DNI
  162.                    alta = new JButton("Registrar DNI");
  163.                    alta.setBounds(325, 180, 200, 20);
  164.                    add(alta);
  165.         }
  166.         private class manejadorCampo implements ActionListener
  167.         {
  168.             public void actionPerformed(ActionEvent evento)
  169.             {
  170.  
  171.                 if(evento.getSource()== altas)
  172.                 {
  173.                     //getContentPane().setBackground(Color.BLACK);
  174.                     //ventanas alta = new ventanas();
  175.                     //alta.altas();
  176.  
  177.                             altas();
  178.                             titulo.setVisible(true);
  179.                             campoNombre.setVisible(true);
  180.                             campoApellidos.setVisible(true);
  181.                             campoDNI.setVisible(true);
  182.                             campoFecha.setVisible(true);
  183.                 }
  184.             }
  185.         }
  186.    
  187. }