How to open several MappedByteBuffer in parallel in Java?

Help me with Java Programming!!!?

  • I am using an ActionListener to a TextField so that when the enter key is pushed by the user the TextField is disabled and a button called "Activate Buttons" is enabled. The activateButton is contained in a separate class than the TextField because there are two active windows. When I try using: GameField.activateButton.setEnabled(tr… Multiple errors appear. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at project1.ScoreBoard$TextField1Listener.a… at javax.swing.JTextField.fireActionPerform… Source) at javax.swing.JTextField.postActionEvent(U… Source) at javax.swing.JTextField$NotifyAction.acti… Source) at javax.swing.SwingUtilities.notifyAction(… Source) at javax.swing.JComponent.processKeyBinding… Source) at javax.swing.JComponent.processKeyBinding… Source) at javax.swing.JComponent.processKeyEvent(U… Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unk… Source) at java.awt.Container.dispatchEventImpl(Unk… Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.KeyboardFocusManager.redispatch… Source) at java.awt.DefaultKeyboardFocusManager.dis… Source) at java.awt.DefaultKeyboardFocusManager.pre… Source) at java.awt.DefaultKeyboardFocusManager.typ… Source) at java.awt.DefaultKeyboardFocusManager.dis… Source) at java.awt.Component.dispatchEventImpl(Unk… Source) at java.awt.Container.dispatchEventImpl(Unk… Source) at java.awt.Window.dispatchEventImpl(Unknow… Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknow… Source) at java.awt.EventDispatchThread.pumpOneEven… Source) at java.awt.EventDispatchThread.pumpEventsF… Source) at java.awt.EventDispatchThread.pumpEventsF… Source) at java.awt.EventDispatchThread.pumpEvents(… Source) at java.awt.EventDispatchThread.pumpEvents(… Source) at java.awt.EventDispatchThread.run(Unknown Source)

  • Answer:

    not sure without seeing your code, but JTextfield was built for FocusListener. When the Enter key (default) is 'heard' the JTextfield goes out of focus and that is the event you want. If JButton is another class and not an instance var, then you would have needed another field in the constructor of that button to reference the method of the unrelated window class. Or, use an interface. Or, put everyting in one code listing, using inline classes -- which I don't really like to do, too much scrolling up and down through the listing while trying to remember the connectivity. Remember, an action bubbles up through the heirarchy until it is consumed.

J Long at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Looks like you forgot to initialize one or more of your controls. In Java, object variables must be declared and initialized. This will produce an error... a null reference exception to be exact. JButton a; a.setText("Hello"); You need to do this: JButton a = new JButton(); a.setText("Hello"); Make sure you're actually creating (with the keyword new) all your controls.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.