• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Basic question about creating graphical object in java

Carlis

Senior member
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
 
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.
 
Back
Top