In Java, how do I create Graphics within a class and then get the Graphics for use in an Applet?
One attempt to create this class for the graphic is as follows.
import java.lang.*;
import java.util.*;
import java.awt.*;
public class Cords{
public static Graphics cords;
public static int w,h,n;
private static int xC,yC;
public static void Paint(Graphics g)
{
for(xC=0;xC<=w;xC+=n){
g.drawLine(xC,0,xC,h);
g.drawString(""+xC,xC,11);
}
for(yC=0;yC<=h;yC+=n){
g.drawLine(0,yC,w,yC);
g.drawString(""+yC,1,yC));
}
cords=g.create();
}
public static Graphics cords(int w, int h,int n){
return cords;
}
Which I then attempted to use in an applet...
import java.awt.*;
import java.applet.Applet;
import javax.swing.Timer;
public class CordsTest extends Applet
private int x,y,w,h,n;
private Cords a;
public void init()
{
//w=getWidth();
//h=getHeight();
//a.cords(w,h,50);
}
public void paint(Graphics g){
w=getWidth();
h=getHeight();
g.setColor(Color.black);
paint(a.cords(w,h,50));
}
}
As I am relatively new to asking questions on Stack Overflow, if there are any errors in question formatting, please have patience and if possible, let me know via comment so I can avoid these in the future. Thank you!