J
Johannes Z
Gast
Ich soll für Informatik in der Schule ein Programm Fenster erstellen mit 3 Textfeldern und einem Butten. Wenn man den Butten drückt sollen die Zahlen (nur ganzzahlig und positiv) aus Textfeld 1 und 2 addiert werden und ins Dritte geschrieben werden. Ich hab das bis jetzt so weit:
Wenn ich es dann ausfüre kommt diese Meldung:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at arbeit.Oberfläche$1.actionPerformed(Oberfläche.java:103)
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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.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)
Ich weiß auch nicht ob es schon einen Beitrag zu dem Problem gibt weil ich keine Ahnung hab was das Problem(e) ist.
MfG Johannes
Java:
package arbeit;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextPane;
public class Oberfläche extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextField Eingabe1 = null;
private JTextField Eingabe2 = null;
private JTextField Ausgabe = null;
private JButton Plus = null;
/**
* This is the default constructor
*/
public Oberfläche() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(388, 231);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getEingabe1(), null);
jContentPane.add(getEingabe2(), null);
jContentPane.add(getAusgabe(), null);
jContentPane.add(getPlus(), null);
}
return jContentPane;
}
/**
* This method initializes Eingabe1
*
* @return javax.swing.JTextField
*/
private JTextField getEingabe1() {
if (Eingabe1 == null) {
Eingabe1 = new JTextField();
Eingabe1.setBounds(new Rectangle(30, 30, 211, 31));
}
return Eingabe1;
}
/**
* This method initializes Eingabe2
*
* @return javax.swing.JTextField
*/
private JTextField getEingabe2() {
if (Eingabe2 == null) {
Eingabe2 = new JTextField();
Eingabe2.setBounds(new Rectangle(30, 90, 211, 31));
}
return Eingabe2;
}
/**
* This method initializes Ausgabe
*
* @return javax.swing.JTextField
*/
private JTextField getAusgabe() {
if (Ausgabe == null) {
Ausgabe = new JTextField();
Ausgabe.setBounds(new Rectangle(30, 150, 331, 31));
}
return Ausgabe;
}
/**
* This method initializes Plus
*
* @return javax.swing.JButton
*/
private JButton getPlus() {
if (Plus == null) {
Plus = new JButton();
Plus.setBounds(new Rectangle(300, 75, 46, 46));
Plus.setText("+");
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String meinWert1 = Eingabe1.getText();
int Zahl1 = Integer.parseInt(meinWert1);
String meinWert2 = Eingabe2.getText();
int Zahl2 = Integer.parseInt(meinWert2);
int Ausgabe1 = Zahl1+Zahl2 ;
String asdf = (Integer(Ausgabe1)).toString();
Ausgabe.setText(asdf);
}
private Object Integer(int ausgabe1) {
// TODO Auto-generated method stub
return null;
}
};
Plus.addActionListener(al);
}
return Plus;
}
} // @jve:decl-index=0:visual-constraint="10,10"
Wenn ich es dann ausfüre kommt diese Meldung:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at arbeit.Oberfläche$1.actionPerformed(Oberfläche.java:103)
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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.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)
Ich weiß auch nicht ob es schon einen Beitrag zu dem Problem gibt weil ich keine Ahnung hab was das Problem(e) ist.
MfG Johannes
Zuletzt bearbeitet von einem Moderator: