Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Error Objects Swing

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error Objects Swing

    hello I have a problem with a JFrame I can not access objects JButtom to use their attributes, will not let me enable or disable the objects I have declared as public and not anything I can use only within the class constructor

    Este es el error que me sale

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at logica.frmRegistro.onVariables(frmRegistro.java:20 8)
    at logica.frmRegistro.access$0(frmRegistro.java:199)
    at logica.frmRegistro$2.actionPerformed(frmRegistro.j ava:139)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)

    package logica;
     
    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.Font;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JTextField;
     
    import datos.connDb;
    import javax.swing.border.TitledBorder;
    import javax.swing.border.LineBorder;
    import java.awt.Color;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.JLabel;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
     
    public class frmRegistro extends JFrame {
     
    	private JPanel contentPane;
     
    	connDb objDb;
    	private JTextField txtId;
    	private JTextField txtNombres;
    	private JTextField txtDni;
    	private JTextField txtDireccion;
    	private JTextField txtCargo;
    	private JTextField txtTelefono;
     
    	private JButton btnNuevo;
    	private JButton btnInsertar;
    	private JButton btnBuscar;
    	private JButton btnActualizar;
    	private JTable table;
     
     
    	/**
    	 * Launch the application.
    	 */
     
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					frmRegistro frame = new frmRegistro();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
     
    	/**
    	 * Create the frame.
    	 */
    	public frmRegistro() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 732, 411);
    		setFont(new Font("Droid Sans", Font.BOLD, 11));
    		setTitle("Registro de Usuarios");
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
     
    		JPanel panel = new JPanel();
    		panel.setBorder(new TitledBorder(new LineBorder(new Color(99, 130, 191)), "Registro de datos", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(128, 0, 0)));
    		panel.setLayout(null);
    		panel.setBounds(12, 12, 706, 141);
     
    		txtId = new JTextField();
    		txtId.setBounds(126, 39, 114, 19);
    		txtId.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		panel.add(txtId);
    		txtId.setColumns(10);
     
    		table = new JTable();
    		GroupLayout gl_contentPane = new GroupLayout(contentPane);
    		gl_contentPane.setHorizontalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addGap(7)
    					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 706, GroupLayout.PREFERRED_SIZE)
    					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
    					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    					.addComponent(table, GroupLayout.PREFERRED_SIZE, 701, GroupLayout.PREFERRED_SIZE)
    					.addContainerGap())
    		);
    		gl_contentPane.setVerticalGroup(
    			gl_contentPane.createParallelGroup(Alignment.TRAILING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 148, GroupLayout.PREFERRED_SIZE)
    					.addPreferredGap(ComponentPlacement.UNRELATED)
    					.addComponent(table, GroupLayout.PREFERRED_SIZE, 205, GroupLayout.PREFERRED_SIZE)
    					.addContainerGap())
    		);
     
    		txtNombres = new JTextField();
    		txtNombres.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		txtNombres.setBounds(453, 39, 240, 19);
    		panel.add(txtNombres);
    		txtNombres.setColumns(10);
     
    		txtDni = new JTextField();
    		txtDni.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		txtDni.setBounds(126, 59, 114, 19);
    		panel.add(txtDni);
    		txtDni.setColumns(10);
     
    		txtDireccion = new JTextField();
    		txtDireccion.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		txtDireccion.setBounds(126, 79, 230, 19);
    		panel.add(txtDireccion);
    		txtDireccion.setColumns(10);
     
    		txtCargo = new JTextField();
    		txtCargo.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		txtCargo.setBounds(453, 59, 114, 19);
    		panel.add(txtCargo);
    		txtCargo.setColumns(10);
     
    		txtTelefono = new JTextField();
    		txtTelefono.setFont(new Font("Droid Sans", Font.PLAIN, 11));
    		txtTelefono.setBounds(453, 79, 114, 19);
    		panel.add(txtTelefono);
    		txtTelefono.setColumns(10);
     
    		JButton btnNuevo = new JButton("Nuevo");
    		btnNuevo.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				onVariables();
    			}
    		});
    		btnNuevo.setBounds(100, 110, 117, 25);
    		panel.add(btnNuevo);
    		contentPane.setLayout(gl_contentPane);
     
    		JButton btnInsertar = new JButton("Insertar");
    		btnInsertar.setBounds(239, 110, 117, 25);
    		panel.add(btnInsertar);
     
    		JButton btnBuscar = new JButton("Buscar");
    		btnBuscar.setBounds(378, 110, 117, 25);
    		panel.add(btnBuscar);
     
    		JButton btnActualizar = new JButton("Actualizar");
    		btnActualizar.setBounds(517, 110, 117, 25);
    		panel.add(btnActualizar);
     
    		JLabel lblNewLabel = new JLabel("Id Usuario :");
    		lblNewLabel.setBounds(48, 39, 74, 19);
    		lblNewLabel.setFont(new Font("Droid Sans", Font.BOLD, 11));
    		panel.add(lblNewLabel);
    		contentPane.setLayout(gl_contentPane);
     
    		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);
    		panel.add(lblNewLabel_1);
    		contentPane.setLayout(gl_contentPane);
     
    		JLabel lblNewLabel_2 = new JLabel("Doc. Identidad :");
    		lblNewLabel_2.setFont(new Font("Droid Sans", Font.BOLD, 11));
    		lblNewLabel_2.setBounds(24, 59, 97, 19);
    		panel.add(lblNewLabel_2);
    		contentPane.setLayout(gl_contentPane);
     
    		JLabel lblNewLabel_3 = new JLabel("Dirección :");
    		lblNewLabel_3.setFont(new Font("Droid Sans", Font.BOLD, 11));
    		lblNewLabel_3.setBounds(52, 79, 70, 19);
    		panel.add(lblNewLabel_3);
    		contentPane.setLayout(gl_contentPane);
     
    		JLabel lblNewLabel_4 = new JLabel("Cargo :");
    		lblNewLabel_4.setFont(new Font("Droid Sans", Font.BOLD, 11));
    		lblNewLabel_4.setBounds(399, 59, 48, 19);
    		panel.add(lblNewLabel_4);
    		contentPane.setLayout(gl_contentPane);
     
    		JLabel lblNewLabel_5 = new JLabel("Telefono :");
    		lblNewLabel_5.setFont(new Font("Droid Sans", Font.BOLD, 11));
    		lblNewLabel_5.setBounds(383, 79, 63, 19);
    		panel.add(lblNewLabel_5);
    		contentPane.setLayout(gl_contentPane);	
    		offVariables();
    		btnInsertar.setEnabled(false);
    		btnBuscar.setEnabled(false);
    		btnActualizar.setEnabled(false);
    	}
     
    	private void onVariables()
    	{
    		txtId.setEnabled(true);
    		txtNombres.setEnabled(true);
    		txtDni.setEnabled(true);
    		txtCargo.setEnabled(true);
    		txtDireccion.setEnabled(true);
    		txtTelefono.setEnabled(true);
     
    		btnNuevo.setEnabled(true);
    		btnActualizar.setEnabled(true);
    		btnBuscar.setEnabled(true);
     
    	}
     
    	private void offVariables()
    	{
    		txtId.setEnabled(false);
    		txtNombres.setEnabled(false);
    		txtDni.setEnabled(false);
    		txtCargo.setEnabled(false);
    		txtDireccion.setEnabled(false);
    		txtTelefono.setEnabled(false);
    		//btnInsertar.setEnabled(false);
    		//btnBuscar.setEnabled(false);
    		//btnActualizar.setEnabled(false);
    	}
    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Error Objects Swing

    What line is 208, and can you find where you declared all the variables on that line?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. [Question] Objects instantiated within objects.
    By Xerosigma in forum Object Oriented Programming
    Replies: 6
    Last Post: April 25th, 2012, 10:53 AM
  2. Error: The import java.swing cannot be resolved [in drJava]
    By ArcticOokami in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 24th, 2012, 06:39 PM
  3. New to Objects...
    By Java Neil in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 24th, 2011, 07:00 AM
  4. error when comparing 2 string objects
    By amr in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 07:36 PM
  5. Objects
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 20th, 2010, 12:50 PM

Tags for this Thread