import java.awt.*;
import java.applet.*;
public class main extends Applet{
private alt testAlt;
private static final Point altPoint = new Point(20,30);
public void init(){
alt testAlt = new alt(altPoint);
}
public void paint(Graphics graphics){
testAlt.draw(g);
}
}
import java.awt.*;
public class alt {
private Point testPoint;
public alt(Point aPoint){
Point testPoint = new Point(aPoint);
}
public void draw(Graphics g){
g.drawRect(testPoint.x,testPoint.y,20,20);
}
}
The following error is produced
java.lang.Error: Unresolved compilation problem:
g cannot be resolved
at main.paint(main.java:23)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(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.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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 think this means that for some reason the classes cannot see the methods inside of each other, however when i move the constructor into the main paint method everything works fine, however my assignment requests that i put the constructor in this init(); method.
If anyone knows how to accomplish this please help me!
Question
Asmo86
import java.awt.*; import java.applet.*; public class main extends Applet{ private alt testAlt; private static final Point altPoint = new Point(20,30); public void init(){ alt testAlt = new alt(altPoint); } public void paint(Graphics graphics){ testAlt.draw(g); } } import java.awt.*; public class alt { private Point testPoint; public alt(Point aPoint){ Point testPoint = new Point(aPoint); } public void draw(Graphics g){ g.drawRect(testPoint.x,testPoint.y,20,20); } }The following error is produced
java.lang.Error: Unresolved compilation problem:
g cannot be resolved
at main.paint(main.java:23)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(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.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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 think this means that for some reason the classes cannot see the methods inside of each other, however when i move the constructor into the main paint method everything works fine, however my assignment requests that i put the constructor in this init(); method.
If anyone knows how to accomplish this please help me!
Thanks
-Asmo
Link to comment
Share on other sites
6 answers to this question
Recommended Posts