Hi Leute,
ich hab da ein Problem mit setLocation. In meinem Code:
wenn ich das compiliere kommt keine Fehlermeldung! Aber sobald ich das ausführe und auf den Menüeintrag Anordnen klick, dann bekomm ich das:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at RobotControl.actionPerformed(RobotControl.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Hat jemand eine Idee was falsch daran ist? Was muss ich das verändern?
Gruß Michi
ich hab da ein Problem mit setLocation. In meinem Code:
Code:
/*
* Steuert die ganzen Fenster
* Autor: Michael Bergmann
* Version: 1.0
* Stand: läuft nicht
*/
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URL;
import javax.swing.*;
public class RobotControl extends JFrame implements ActionListener {
private JDesktopPane desk;
private JMenuBar menu;
private Image bild;
private Console console;
private Steuerung steuer;
RobotControl() {
URL url = getClass().getResource("logo.png");
bild = getToolkit().getImage(url);
desk = new JDesktopPane();
setContentPane(desk);
setTitle("Roboter Steuersoftware");
setSize(800,600);
setIconImage(bild);
menu = new JMenuBar();
setJMenuBar(menu);
JMenu programm = new JMenu("Programm");
menu.add(programm);
JMenuItem programmexit = new JMenuItem("Beenden");
programmexit.addActionListener(this);
programm.add(programmexit);
JMenu fenster = new JMenu("Fenster");
menu.add(fenster);
JMenuItem anordnen = new JMenuItem("Anordnen");
anordnen.addActionListener(this);
fenster.add(anordnen);
Console console = new Console();
console.setVisible(true);
desk.add(console);
Steuerung steuer = new Steuerung(console);
steuer.setVisible(true);
desk.add(steuer);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
RobotControl RC = new RobotControl();
RC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RC.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
JMenuItem item = (JMenuItem)ae.getSource();
String text = item.getText();
if(text == "Beenden") {
setVisible(false);
System.exit(0);
}
if(text == "Anordnen") {
steuer.setLocation(10,10);
console.setLocation(320,10);
}
}
}
wenn ich das compiliere kommt keine Fehlermeldung! Aber sobald ich das ausführe und auf den Menüeintrag Anordnen klick, dann bekomm ich das:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at RobotControl.actionPerformed(RobotControl.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Hat jemand eine Idee was falsch daran ist? Was muss ich das verändern?
Gruß Michi