Thread View: es.comp.lenguajes.java
1 messages
1 total messages
Started by kingdsand
Sat, 28 Jul 2012 04:00
Problema con JFrame
Author: kingdsand
Date: Sat, 28 Jul 2012 04:00
Date: Sat, 28 Jul 2012 04:00
266 lines
10456 bytes
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}));
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads