Til mit program der skal tegne en streg på et panel ud fra 4 kordinater, har jeg lavet en class der skal fungere som det panel der skal tegnes på.
classen ser således ud
- import java.awt.Color;
- import java.awt.Graphics;
- import javax.swing.*;
-
- public class grafPanel extends JPanel {
-
- kordinater k;
-
-
- // henter det kordinat objekt kordinaterne ligger i
- public void setKordinater(kordinater kt){
-
- k = kt;
-
- }
-
- public void paintComponent(Graphics g) {
-
- super.paintComponent(g);
-
- g.drawLine(k.X1, k.Y1, k.X2, k.Y2);
-
- }
-
- }
problemet er at efter jeg har overskrevet paintComponent er der en masse funktioner der burde blive udført der ikke bliver det, her er hvad eclipse siger:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at grafPanel.paintComponent(grafPanel.java:22)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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)
har ikke så mange UP til bage, så der er kun 10 på den her. Håber ikke det gør noget.