package edu.bsu.cs121.mamurphy;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.*;
import java.awt.event.*;
public class InClass1Main extends JFrame {
JButton button1;
JTextField textField1;
JTextArea textArea1;
int buttonClicked;
public static void main(String[] args) {
new InClass1Main();
}
public InClass1Main() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
this.setSize((dim.width / 2), (dim.height / 2));
int xPos = (dim.width / 2) - (this.getWidth() / 2);
int yPos = (dim.height / 2) - (this.getHeight() / 2);
JPanel panel = new JPanel();
JLabel label1 = new JLabel("Translation Panel");
JButton button1 = new JButton("Transfer");
ListenForButton button = new ListenForButton();
button1.addActionListener(button);
JTextField textField1 = new JTextField();
JTextArea textArea1 = new JTextArea(10, 50);
JScrollPane scrollBar1 = new JScrollPane(textArea1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textField1.setColumns(50);
textArea1.setLineWrap(true);
textArea1.setWrapStyleWord(true);
panel.add(label1);
panel.add(button1);
panel.add(textField1);
panel.add(scrollBar1);
this.add(panel);
this.setLocation(xPos, yPos);
this.setResizable(false);
this.setTitle("Translation Frame");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
textField1.requestFocus();
}
private class ListenForButton implements ActionListener {
@Override
public void actionPerformed(ActionEvent ae) {
textArea1.setText(textField1.getText());
}
}
}
I am now getting an error whenever I try to actually type in text to the text field and then put it in the text area. I can't make any sense what so ever of the error.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at edu.bsu.cs121.mamurphy.InClass1Main$ListenForButton.actionPerformed(InClass1Main.java:66)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I truly have no idea what caused this error. A lot of the reasons it is giving me (as you can see above) is (Unknown Source). So any help as to why this is happening would be greatly appreciated.