Basic question about creating graphical object in java

Carlis

Senior member
May 19, 2006
237
0
76
Basic question about creating graphical object in java

My school is making me take a course in java. I dont have any previous experiance with it so;

Im elaborating a little with creating classes with graphic content. I came upp with the following code;

-----------------------------


import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class som15 extends JApplet {



public void init() {
vision stuff1=new vision();
stuff1.paint();
}

}

class vision extends Canvas {
int a=40;
int b=40;
int c=80;
int d=80;
public void paint (Graphics g) {
g.drawLine(a, b, c, d);
}
}


---------------------------

Now this doesnt compile. What did I miss?

peace /Carlis
 

flashbacck

Golden Member
Aug 3, 2001
1,921
0
76
looks fine, but you'll have to add the vision component to your JApplet.
I think

this.add(stuff1);

under init() should work. You may also need setVisible(true) for both the Canvas and JApplet.

This is nitpicky, but class names should be capitalized.