A tardy reply...full agenda...sorry
Quote:
can you explain more on my code
|
..this I can try...that...
...is up to you, I'm afraid.
Java can run in several "modes", one being console mode. Text only. Using the System class to read data means: console. What you need to get a grasp of is understanding how to make an interface (unis Swing code, that is best- grab a
tutorial). Furthermore, a Java "program" can run as program (as all the rest) or as applet (in a browser), the difference is that an applet is shielded of, or better: the system is shielded from the actions of an applet. No system modifications are done by an applet. It is by far the safest way...
Okay, so, the goal is to learn:
- how a Swing applet is structured
- how to lay out the components (input box, drawing surface and so) in an interface
- how to set up a page to display the applet
- how to draw the shape itself, e.g. generate output
Not impossible, believe me
Okay, now, this:
Quote:
System.out.println("Enter the radius");
double r = S.nextDouble();
c.set_radius(r);
|
is pure console code...
This, on the other hand:
Quote:
import java.awt.*;
import java.applet.*;
public class Checkerboard extends Applet {
public void paint(Graphics g) {
int row; // Row number, from 0 to 7
int col; // Column number, from 0 to 7
int x,y; // Top-left corner of square
for ( row = 0; row < 8; row++ ) {
for ( col = 0; col < 8; col++) {
x = col * 20;
y = row * 20;
if ( (row % 2) == (col % 2) )
g.setColor(Color.red);
else
g.setColor(Color.black);
g.fillRect(x, y, 20, 20);
}
}
}
}
|
is code of an APPLET (no Swing, it is not compulary, just nicer to work with)
I suggest you start from the beginning:
- classes
- extending them
- Swing (or AWT)
How long have you been at it?
Thor