Simple java.awt questions

M

morc

hey.
well im trying ot make graphs wiht this but im gona keep my question
very simple.

well first off im graphicaly retarded. so be easy. =)

anyways i wana start by just drawing a line. I know u do it in method
paint.
I'm using JBuilder and i don't know how to compile an run something so
that it displays the drawing i thought i made. for example i have a
class that extends canvas. It's only methods are the Constructor and
Paint(Graphics g).

How do i actualy paint it ont he canvas and display it?

i know it sounds too simple to be true... but like i said im graphicaly
an idiot.

thanks alot for any help
-morc
 
K

Knute Johnson

morc said:
hey.
well im trying ot make graphs wiht this but im gona keep my question
very simple.

well first off im graphicaly retarded. so be easy. =)

anyways i wana start by just drawing a line. I know u do it in method
paint.
I'm using JBuilder and i don't know how to compile an run something so
that it displays the drawing i thought i made. for example i have a
class that extends canvas. It's only methods are the Constructor and
Paint(Graphics g).

How do i actualy paint it ont he canvas and display it?

i know it sounds too simple to be true... but like i said im graphicaly
an idiot.

thanks alot for any help
-morc

Here is how you extend Canvas to draw a line on it. You might be better
served by using a text editor and creating all of your own code at this
stage of your experience.

import java.awt.*;
import java.awt.event.*;

public class Test extends Canvas {
public Test() {
setPreferredSize(new Dimension(400,300));
}

public void paint(Graphics g) {
g.drawLine(0,0,400,300);
}

public static void main(String[] args) {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
Test t = new Test();
f.add(t,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
 
M

morc

hey

i pasted ur code into a new java file called. Test.java and ran using
defaults in JBuilder and i got this:

java.lang.NoClassDefFoundError: Test

Exception in thread "main"


this is what i meant. i don't know how to compile/view/test anything i
do graphicaly. How do i see the line being drawn?

thanks alot for the help.
 
K

Knute Johnson

morc said:
hey

i pasted ur code into a new java file called. Test.java and ran using
defaults in JBuilder and i got this:

java.lang.NoClassDefFoundError: Test

Exception in thread "main"


this is what i meant. i don't know how to compile/view/test anything i
do graphicaly. How do i see the line being drawn?

thanks alot for the help.

Well I can't help you with JBuilder because I don't use those things.
If you have the JDK installed on your computer then compile the program
I gave you with;

javac Test.java

and run it with;

java Test

If you need help installing the compiler post again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top