Hallo !
Ich wollte etwas ganz simples in AWT coden. 2 Buttons ein textfeld. Beide Button geben unterschiedliche Texte im Textfeld aus.
Mein Code:
==================================================================
Der Compiler sagt:
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at EasyCalculator.actionPerformed(EasyCalculator.java:66)
at java.awt.Button.processActionEvent(Button.java:382)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Was muss ich ändern ?? Danke sehr
Ich wollte etwas ganz simples in AWT coden. 2 Buttons ein textfeld. Beide Button geben unterschiedliche Texte im Textfeld aus.
Mein Code:
Code:
import java.awt.*;
import java.awt.event.*;
/*
* Created on 23.03.2005
* @author Thomas
*/
public class EasyCalculator extends Frame implements ActionListener
{
public static void main(String[] args)
{
Frame frame = new EasyCalculator("Easy Calculator 1.0");
}
private TextField tf = null;
public EasyCalculator(String title)
{
super(title);
setSize(400,400);
setLayout(new FlowLayout(FlowLayout.LEFT));
Button button = new Button("Press1");
Button button2 = new Button("Press2");
button2.addActionListener(this);
button.addActionListener(this);
add(button);
add(button2);
TextField tf = new TextField("textfeld");
add(tf);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e )
{
Button b = (Button)e.getSource();
String l = b.getLabel();
if (l.equals("Press1"))
tf.setText("Button 1 pressed");
if (l.equals("Press2"))
tf.setText("Button 2 presses");
}
}
Der Compiler sagt:
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at EasyCalculator.actionPerformed(EasyCalculator.java:66)
at java.awt.Button.processActionEvent(Button.java:382)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Was muss ich ändern ?? Danke sehr