Java - Clase Oyente que no escucha

 
Vista:
sin imagen de perfil

Clase Oyente que no escucha

Publicado por Krystneidis (4 intervenciones) el 20/06/2015 18:35:09
PANTALLA MAIN DESPUES DEL LOGIN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package inventariosuplires;
 
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
 
public class FormMainMenu extends JFrame implements ActionListener{
 
    private final JMenuBar Barra1;
    private final JMenu Menu1, Menu2, Menu3, Menu4;
    private final JMenuItem Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8;
 
    public FormMainMenu(){
 
        super("Main Menu");
        setSize (500,400);
        setLayout(null);
        Barra1 = new JMenuBar();
        setJMenuBar(Barra1);
        Menu1 = new JMenu("Clientes");
        Barra1.add(Menu1);
        Menu2 = new JMenu("Articulo");
        Barra1.add(Menu2);
        Menu3 = new JMenu("Factura");
        Barra1.add(Menu3);
        Menu4 = new JMenu("Salir");
        Barra1.add(Menu4);
 
 
        Item1 = new JMenuItem("Registro");
        Item1.addActionListener(this);
        Menu1.add(Item1);
        Item2 = new JMenuItem("Consulta");
        Item2.addActionListener(this);
        Menu1.add(Item2);
        Item3 = new JMenuItem("Eliminar");
        Item3.addActionListener(this);
        Menu1.add(Item3);
 
 
 
        Item4 = new JMenuItem("Registro");
        Menu2.add(Item4);
        Item5 = new JMenuItem("Consulta");
        Menu2.add(Item5);
        Item6 = new JMenuItem("Eliminar");
        Menu2.add(Item6);
 
        Item7 = new JMenuItem("Nueva");
        Menu3.add(Item7);
        Item8 = new JMenuItem("Consultar");
        Menu3.add(Item8);
    }
 
    @Override
        public void actionPerformed(ActionEvent e){
 
//
            Container f = this.getContentPane();
 
            FormClientesIng FCM = new FormClientesIng();
            FCM.setVisible(true);
            dispose();
 
// Este es el código que quiero me muestre o escuche la clase oyente y lo que sucede es que cuando le doy click al Item 1 == Registro en el menú Clientes me detiene la ejecución
 
            if(e.getSource()==Item1){
            getContentPane().add(FCM);
                }
 
 
  }
 }

PANTALLA REGISTRO DE CLIENTES

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package inventariosuplires;
 
import javax.swing.*;
import java.awt.*;
import java.text.ParseException;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;
 
enum tipo {V, E, RIF};
 
public class FormClientesIng extends JPanel{
 
    public JComboBox TipoID;
    public JTextField ID;
    public JTextField Nombre;
    public JTextField Apellido;
    public JTextField Direccion;
    public JFormattedTextField CodTelefono;
    public JTextField Telefono;
    public JButton Boton1, Boton2, Boton3;
 
 
    public FormClientesIng(){
 
        setLayout(new GridLayout(8,3, 10,12));
        setVisible(true);
        TitledBorder titulo;
        titulo = BorderFactory.createTitledBorder("Datos del Cliente");
        setBorder(titulo);
 
        JLabel TipoId = new JLabel("Tipo",JLabel.RIGHT);
        TipoID = new JComboBox(tipo.values());
        add(TipoId);
        add(TipoID);
 
        JLabel Id = new JLabel("Cedula o RIF", JLabel.RIGHT);
        ID = new JTextField();
        add(Id);
        add(ID);
 
        JLabel Nombres = new JLabel("Nombre", JLabel.RIGHT);
        Nombre = new JTextField();
        add(Nombres);
        add(Nombre);
 
        JLabel Apellidos = new JLabel("Apellido", JLabel.RIGHT);
        Apellido = new JTextField();
        add(Apellidos);
        add(Apellido);
 
        JLabel Direcciones = new JLabel("Dirección", JLabel.RIGHT);
        Direccion = new JTextField();
        add(Direcciones);
        add(Direccion);
 
        JLabel Codtelefono = new JLabel("COD", JLabel.RIGHT);
        MaskFormatter format =null;
        try {
            format = new MaskFormatter("###");
        }
        catch(ParseException e){
            System.out.println("Solo Digitos 3 digitos sin el cero ");
        }
        CodTelefono = new JFormattedTextField(format);
        add(Codtelefono);
        add(CodTelefono);
 
        JLabel Telefonos = new JLabel("Telefonos", JLabel.RIGHT);
        Telefono = new JTextField();
        add(Telefonos);
        add(Telefono);
 
        Boton1 = new JButton ("Registrar");
        add(Boton1);
 
        Boton2 = new JButton ("Actualizar");
        add(Boton2);
 
        Boton3 = new JButton ("Salir");
        add(Boton3);
    }
}

Igual anexo el código completo del proyecto
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Clase Oyente que no escucha

Publicado por Oscar (1 intervención) el 20/06/2015 22:31:14
Hola.
Esta bien que identifiques que JMenuItem esta llamando al escucha.
Pero lo esta mal como lllamas a tu formulario.
Ejemplo:

1
2
3
4
5
if(e.getSource()==Item1){
//llama aqui a tu formulario que quieres que se muestre
FormClientesIng FCM = new FormClientesIng();
FCM.setVisible(true);
}
Lo que no entendi que estas tratando de hacer aquí?
1
Container f = this.getContentPane();

Saludos!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Clase Oyente que no escucha

Publicado por Krystneidis (4 intervenciones) el 21/06/2015 02:56:00
public void actionPerformed(ActionEvent e){

if(e.getSource()==Item1){
FormClientesIng FCM = new FormClientesIng();
FCM.setVisible(true);
dispose();
}


}
}

// Coloque el código y me sigue dando el mismo problema no me pasa a la siguiente pantalla
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Clase Oyente que no escucha

Publicado por Oscar (5 intervenciones) el 21/06/2015 06:54:15
Hola.
Estuve checando tu codigo.
Y ya funciona.
//Tu clase conexion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package falta;
 
import static java.util.logging.Level.*;
import static java.util.logging.Logger.*;
import static java.sql.DriverManager.*;
import static java.lang.System.*;
 
import java.sql.Connection;
import java.sql.SQLException;
 
public class DBConexion {
 
	/**
	 *
	 * @return conexion a base mysql
	 * @Método estatico de conexion
	 **/
	public static Connection getConexion() {
		try {
			// Conexión a la base de datos mysql
			Connection cont = getConnection(URL_DB, dbUsuario, dbClave);
			out.println("Conexion exitosa");
			return cont;// Regresamos la conexión de la base
		} catch (SQLException ex) {
			getLogger(DBConexion.class.getName()).log(SEVERE, null, ex);
			// Capturas la excepción si la hay, para saber que ocurrio
			err.println("Error en conexión: " + ex.getMessage());
			return null;// Regresamos un valor null si falla la conexión
		}
	}
 
	// Constantes de clase
	private final static String URL_DB = "jdbc:mysql://localhost:5432/BD_Inv_SUPLIRES";
	private final static String dbUsuario = "root", dbClave = "laClave";
}


//Tu clase Panel FormClientesIng


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package falta;
 
import javax.swing.*;
import java.awt.*;
import java.text.ParseException;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;
 
enum tipo {
	V, E, RIF
};
 
public class FormClientesIng extends JPanel {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = -1604018178138709998L;
	public JComboBox TipoID;
	public JTextField ID;
	public JTextField Nombre;
	public JTextField Apellido;
	public JTextField Direccion;
	public JFormattedTextField CodTelefono;
	public JTextField Telefono;
	public JButton Boton1, Boton2, Boton3;
 
	public FormClientesIng() {
 
		setLayout(new GridLayout(8, 3, 10, 12));
 
		TitledBorder titulo;
		titulo = BorderFactory.createTitledBorder("Datos del Cliente");
		setBorder(titulo);
 
		JLabel TipoId = new JLabel("Tipo", JLabel.RIGHT);
		TipoID = new JComboBox(tipo.values());
		add(TipoId);
		add(TipoID);
 
		JLabel Id = new JLabel("Cedula o RIF", JLabel.RIGHT);
		ID = new JTextField();
		add(Id);
		add(ID);
 
		JLabel Nombres = new JLabel("Nombre", JLabel.RIGHT);
		Nombre = new JTextField();
		add(Nombres);
		add(Nombre);
 
		JLabel Apellidos = new JLabel("Apellido", JLabel.RIGHT);
		Apellido = new JTextField();
		add(Apellidos);
		add(Apellido);
 
		JLabel Direcciones = new JLabel("Dirección", JLabel.RIGHT);
		Direccion = new JTextField();
		add(Direcciones);
		add(Direccion);
 
		JLabel Codtelefono = new JLabel("COD", JLabel.RIGHT);
		MaskFormatter format = null;
		try {
			format = new MaskFormatter("###");
		} catch (ParseException e) {
			System.out.println("Solo Digitos 3 digitos sin el cero ");
		}
		CodTelefono = new JFormattedTextField(format);
		add(Codtelefono);
		add(CodTelefono);
 
		JLabel Telefonos = new JLabel("Telefonos", JLabel.RIGHT);
		Telefono = new JTextField();
		add(Telefonos);
		add(Telefono);
 
		Boton1 = new JButton("Registrar");
		add(Boton1);
 
		Boton2 = new JButton("Actualizar");
		add(Boton2);
 
		Boton3 = new JButton("Salir");
		add(Boton3);
		this.repaint();
		this.validate();
		setVisible(true);
	}
}

//Tu formulario principal FormMainMenu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package falta;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.FormatterClosedException;
 
import javax.swing.*;
 
@SuppressWarnings("serial")
public class FormMainMenu extends JFrame implements ActionListener {
 
	private final JMenuBar Barra1;
	private final JMenu Menu1, Menu2, Menu3, Menu4;
	private final JMenuItem Item1, Item2, Item3, Item4, Item5, Item6, Item7,
			Item8;
 
	public FormMainMenu() {
 
		super("Main Menu");
		setLayout(null);
		Barra1 = new JMenuBar();
		setJMenuBar(Barra1);
		Menu1 = new JMenu("Clientes");
		Barra1.add(Menu1);
		Menu2 = new JMenu("Articulo");
		Barra1.add(Menu2);
		Menu3 = new JMenu("Factura");
		Barra1.add(Menu3);
		Menu4 = new JMenu("Salir");
		Barra1.add(Menu4);
 
		Item1 = new JMenuItem("Registro");
		Item1.addActionListener(this);
		Menu1.add(Item1);
		Item2 = new JMenuItem("Consulta");
		Item2.addActionListener(this);
		Menu1.add(Item2);
		Item3 = new JMenuItem("Eliminar");
		Item3.addActionListener(this);
		Menu1.add(Item3);
 
		Item4 = new JMenuItem("Registro");
		Menu2.add(Item4);
		Item5 = new JMenuItem("Consulta");
		Menu2.add(Item5);
		Item6 = new JMenuItem("Eliminar");
		Menu2.add(Item6);
 
		Item7 = new JMenuItem("Nueva");
		Menu3.add(Item7);
		Item8 = new JMenuItem("Consultar");
		Menu3.add(Item8);
		setSize(900, 400);
		this.repaint();
	}
 
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == Item1) {
			Container f =this.getContentPane();
			f.setLayout(new BorderLayout());
			FormClientesIng FCM = new FormClientesIng();
			FCM.setVisible(true);
			add(FCM, BorderLayout.CENTER);
                       //Metodos esticos para que se dibuje tu panel en el principal
			this.repaint();
			this.validate();
			f.repaint();
			f.validate();
			FCM.repaint();
			FCM.validate();
		}
 
	}
}

//Tu clase Main InventarioSUPLIRES

1
2
3
4
5
6
7
8
9
10
11
package falta;
 
import javax.swing.*;
 
public class InventarioSUPLIRES {
	public static void main(String[] args) {
		FormMainMenu FMM = new FormMainMenu();
		FMM.setVisible(true);
		FMM.setLocationRelativeTo(null);
	}
}

Verificalo por favor y si tienes una duda lo vemos!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Clase Oyente que no escucha

Publicado por Krystneidis (4 intervenciones) el 21/06/2015 16:40:50
No se porque por tanto tiempo me rehusé a usar foros, me doy cuenta que fue una total tontería y estupidez, de verdad muchas gracias, solventado esto debo hacer la conexión a base de datos de al menos los datos de Login, si me surge alguna pregunta se los haré saber, gracias, muchisimas gracias por sus aportes
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar