๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #246

Problema con JFrame

#246
From: kingdsand
Date: Sat, 28 Jul 2012 04:00
266 lines
10456 bytes
Holas tengo un problema para acceder a las funciones de los botones en mi formulario un JFrame cuando ejecuto en evento click de un boton deberia de activar los demas botones btInsertar.setEnabled(true); y me sale un error.


Copio el error asi como el programa del formularo que estoy creando para que loo puedan evaluar, estoy usando eclipse indigo.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at logica.FrmRegistro.onVariables(FrmRegistro.java:92)
	at logica.FrmRegistro.access$6(FrmRegistro.java:84)
	at logica.FrmRegistro$8.mouseClicked(FrmRegistro.java:175)
	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
	at java.awt.Component.processMouseEvent(Component.java:6293)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6055)
	at java.awt.Container.processEvent(Container.java:2039)
	at java.awt.Component.dispatchEventImpl(Component.java:4653)

programa #####################################

package logica;

import java.awt.*;
import javax.swing.*;
import datos.connDb;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import javax.swing.border.TitledBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.LineBorder;
import javax.swing.text.AbstractDocument.Content;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class FrmRegistro extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentJPanel;
	/**
	 * 
	 */
	//private static final long serialVersionUID = 1L;
	private JTextField txtId, txtDni, txtDireccion, txtNombres, txtCargo, txtTelefono;
	public  JButton btNuevo;
	public  JButton btInsertar;
	private JButton btBuscar;
	private JButton btActualizar;
	private JLabel lblTitulo, lblNewLabel, lblNewLabel_1, lblNewLabel_2, lblNewLabel_3, lblNewLabel_4, lblNewLabel_6;
	private JTable tabla;
	private JFrame frmRegistros;
	connDb objDb;
	
	// Declaracion de variables publicas 
	public String xid, xnombre, xdni, xdireccion, xcargo;
	public Integer xtelefono;

	/**
	 * Create the panel.
	 */
	public FrmRegistro() {
		initialize();
		frmRegistros.setLocationRelativeTo(null);
		objDb = new connDb();
		// Inicializa variables
		offVariables();
	}
	
	public static void main (String [] args)
	{
		EventQueue.invokeLater(new Runnable() 
		{
			@Override
			public void run() 
			{
				try
				{
					FrmRegistro window = new FrmRegistro();
					window.frmRegistros.setVisible(true);
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
				}
			}
		});
	}
	
	private void offVariables()
	{
		txtId.setEnabled(false);
		txtNombres.setEnabled(false);
		txtDni.setEnabled(false);
		txtCargo.setEnabled(false);
		txtDireccion.setEnabled(false);
		txtTelefono.setEnabled(false);
	}
	
	private void onVariables()
	{
		txtId.setEnabled(true);
		txtNombres.setEnabled(true);
		txtDni.setEnabled(true);
		txtCargo.setEnabled(true);
		txtDireccion.setEnabled(true);
		txtTelefono.setEnabled(true);
		btInsertar.setEnabled(true);
		btBuscar.setEnabled(true);
		btActualizar.setEnabled(true);
	}
	
	public void initialize() {
		frmRegistros = new JFrame();
		frmRegistros.setFont(new Font("Droid Sans", Font.BOLD, 11));
		frmRegistros.setResizable(false);
		frmRegistros.setTitle("Registro de Usuarios");
		frmRegistros.setBounds(100, 100, 732, 411);
		frmRegistros.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmRegistros.getContentPane().setLayout(null);
		
		txtId = new JTextField();
		txtId.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtId.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtNombres.grabFocus();
			}
		});
		txtId.setBounds(126, 39, 114, 19);
		frmRegistros.getContentPane().add(txtId);
		txtId.setColumns(10);
		
		txtDni = new JTextField();
		txtDni.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtDni.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtCargo.grabFocus();
			}
		});
		txtDni.setBounds(126, 59, 114, 19);
		frmRegistros.getContentPane().add(txtDni);
		txtDni.setColumns(10);
		
		txtDireccion = new JTextField();
		txtDireccion.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtDireccion.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtTelefono.grabFocus();
			}
		});
		txtDireccion.setBounds(126, 79, 230, 19);
		frmRegistros.getContentPane().add(txtDireccion);
		txtDireccion.setColumns(10);
		
		txtNombres = new JTextField();
		txtNombres.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtNombres.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtDni.grabFocus();
			}
		});
		txtNombres.setBounds(453, 39, 240, 19);
		frmRegistros.getContentPane().add(txtNombres);
		txtNombres.setColumns(10);
		
		txtCargo = new JTextField();
		txtCargo.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtCargo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtDireccion.grabFocus();
			}
		});
		txtCargo.setBounds(453, 59, 114, 19);
		frmRegistros.getContentPane().add(txtCargo);
		txtCargo.setColumns(10);
		
		txtTelefono = new JTextField();
		txtTelefono.setFont(new Font("Droid Sans", Font.PLAIN, 11));
		txtTelefono.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btNuevo.grabFocus();
			}
		});
		txtTelefono.setBounds(453, 79, 114, 19);
		frmRegistros.getContentPane().add(txtTelefono);
		txtTelefono.setColumns(10);
		
		JButton btNuevo = new JButton("Nuevo");
		btNuevo.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				onVariables();
			}
		});
		btNuevo.setBounds(100, 110, 117, 25);
		frmRegistros.getContentPane().add(btNuevo);
		
		JButton btInsertar = new JButton("Insertar");
		btInsertar.setEnabled(false);
		btInsertar.setBounds(239, 110, 117, 25);
		frmRegistros.getContentPane().add(btInsertar);
	
		JButton btBuscar = new JButton("Buscar");
		btBuscar.setEnabled(false);
		btBuscar.setBounds(378, 110, 117, 25);
		frmRegistros.getContentPane().add(btBuscar);
		
		JButton btActualizar = new JButton("Actualizar");
		btActualizar.setEnabled(false);
		btActualizar.setBounds(517, 110, 117, 25);
		frmRegistros.getContentPane().add(btActualizar);
		
		JLabel lblNewLabel = new JLabel("Id Usuario :");
		lblNewLabel.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel.setBounds(48, 39, 74, 19);
		frmRegistros.getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Nombres y Apellidos :");
		lblNewLabel_1.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel_1.setBounds(321, 39, 127, 19);
		frmRegistros.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Doc. Identidad :");
		lblNewLabel_2.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel_2.setBounds(24, 59, 97, 19);
		frmRegistros.getContentPane().add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Direcciรณn :");
		lblNewLabel_3.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel_3.setBounds(52, 79, 70, 19);
		frmRegistros.getContentPane().add(lblNewLabel_3);
		
		JLabel lblNewLabel_4 = new JLabel("Cargo :");
		lblNewLabel_4.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel_4.setBounds(399, 59, 48, 19);
		frmRegistros.getContentPane().add(lblNewLabel_4);
		
		JLabel lblNewLabel_5 = new JLabel("Telefono :");
		lblNewLabel_5.setFont(new Font("Droid Sans", Font.BOLD, 11));
		lblNewLabel_5.setBounds(383, 79, 63, 19);
		frmRegistros.getContentPane().add(lblNewLabel_5);
		
		tabla = new JTable();
		tabla.setBounds(24, 164, 683, 205);
		frmRegistros.getContentPane().add(tabla);
		
		JPanel panel = new JPanel();
		panel.setForeground(UIManager.getColor("ScrollBar.foreground"));
		panel.setBorder(new TitledBorder(new LineBorder(new Color(99, 130, 191)), "Datos de Usuarios", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(128, 0, 0)));
		panel.setBounds(12, 12, 706, 141);
		frmRegistros.getContentPane().add(panel);
		frmRegistros.getContentPane().setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{txtId, txtNombres, txtDni, txtCargo, txtDireccion, txtTelefono, btNuevo, btInsertar, btBuscar, btActualizar, tabla, lblNewLabel, lblNewLabel_1, lblNewLabel_2, lblNewLabel_3, lblNewLabel_4, lblNewLabel_5}));
	}
}
Technical Details
Message-ID: <a7dcf437-9f86-44bf-b225-d826cf0ebba5@googlegroups.com>
Path: arc1-ca.pugleaf.net!a15ni14517852qag.0!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!novia!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nrc-news.nrc.ca!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: ecded77573,ab2241d16c80fe75,start
X-Google-Attributes: gidecded77573,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
Received: by 10.224.59.73 with SMTP id k9mr11618027qah.4.1343790195809;
        Tue, 31 Jul 2012 20:03:15 -0700 (PDT)
Path: arc1-ca.pugleaf.net!a15ni14517852qag.0!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!novia!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nrc-news.nrc.ca!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From: kingdsand <kingdsand@gmail.com>
Newsgroups: es.comp.lenguajes.java
Subject: Problema con JFrame
Date: Fri, 27 Jul 2012 21:00:10 -0700 (PDT)
Organization: http://groups.google.com
Lines: 266
Message-ID: <a7dcf437-9f86-44bf-b225-d826cf0ebba5@googlegroups.com>
NNTP-Posting-Host: 190.237.126.127
Mime-Version: 1.0
X-Trace: posting.google.com 1343448387 6445 127.0.0.1 (28 Jul 2012 04:06:27 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 28 Jul 2012 04:06:27 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=190.237.126.127;
 posting-account=M_WzEwoAAACUPiZlP4K3d9j8-lg2MVKO
User-Agent: G2/1.0
Bytes: 9974
X-Received-Bytes: 10056
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable