Using static void (name here) when drawing.
Error is:
11: illegal start of expression
static void drawCircle() {
^
1 error
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
publicclass Spiralextends JPanel{
publicvoid paintComponent(Graphics g){
super.paintComponent( g );
staticvoid drawCircle(){
int x = frame.getWidth() / 2;
int y = frame.getHeight() / 2;
Graphics g = frame.getGraphics();
double radius = 0.1;
for (int i = 0; i < (360 * 5); i += 10){
int tX = (int)(Math.cos(Math.toRadians(i)) * radius) + x;
int tY = (int)(Math.sin(Math.toRadians(i)) * radius) + y;
g.drawLine(x, y, tX, tY);
x = tX;
y = tY;
radius += 0.1;
}
}
staticvoid drawMaze(){
int x = frame.getWidth() / 2;
int y = frame.getHeight() / 2;
int width = 15;
int height = 15;
Graphics g = frame.getGraphics();
int step = 0;
for (int i = 1; i < 15; i++){
switch (step){
case 0://down
g.drawLine(x, y, x, y + (i * height));
y += i * height;
break;
case 1://left
g.drawLine(x, y, x - (i * width), y);
x -= i * width;
break;
case 2://up
g.drawLine(x, y, x, y - (i * height));
y -= i * height;
break;
case 3://right
g.drawLine(x, y, x + (i * width), y);
x += i * width;
break;
}
step = ((step + 1) % 4);
}
}
}
import javax.swing.JFrame;
publicclass SpiralTest
{
publicstaticvoid main( String args[] )
{
Spiral panel =new Spiral();
JFrame application =new JFrame();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.add( panel );
application.setSize( 230, 250 );
application.setVisible(true );
}
}
[3993 byte] By [
emerala] at [2007-11-27 2:57:33]

# 1
You have a spurious method declaration inside your paintComponent method.
protected void paintComponent(Graphics g){
super.paintComponent( g );
static void drawCircle() {
int x = frame.getWidth() / 2;
int y = frame.getHeight() / 2;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class SpiralTest
{
public static void main( String args[] )
{
Spiral panel = new Spiral();
JFrame application = new JFrame();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.add( panel );
application.setSize( 230, 250 );
application.setVisible( true );
}
}
class Spiral extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent( g );
// This method declaration doesn't belong here.
//static void drawCircle() {
// Use the size of this component. If you use the frames
// size you will have to deal with the frame insets. To
// access the frame you may need to call getParent one or
// more times, something like this:
//contentPane = this.getParent()
//rootPane = contentPane.getParent()
//frame = rootPane.getParent()
// or pass in a reference to the frame.
int x = //frame.getWidth() / 2;
getWidth()/2;
int y = //frame.getHeight() / 2;
getHeight()/2;
// This method supplies the graphics context.
//Graphics g = frame.getGraphics();
// Draw your maze with this graphics context.
drawMaze(g);
double radius = 0.1;
for (int i = 0; i < (360 * 5); i += 10) {
int tX = (int)(Math.cos(Math.toRadians(i)) * radius) + x;
int tY = (int)(Math.sin(Math.toRadians(i)) * radius) + y;
g.drawLine(x, y, tX, tY);
x = tX;
y = tY;
radius += 0.1;
}
}
// The static modifier may not be helpful here.
private void drawMaze(Graphics g) {
int x = //frame.getWidth() / 2;
getWidth()/2;
int y = //frame.getHeight() / 2;
getHeight()/2;
int width = 15;
int height = 15;
// Use the one supplied by paintComponent.
//Graphics g = frame.getGraphics();
int step = 0;
for (int i = 1; i < 15; i++) {
switch (step) {
case 0: //down
g.drawLine(x, y, x, y + (i * height));
y += i * height;
break;
case 1: //left
g.drawLine(x, y, x - (i * width), y);
x -= i * width;
break;
case 2: //up
g.drawLine(x, y, x, y - (i * height));
y -= i * height;
break;
case 3: //right
g.drawLine(x, y, x + (i * width), y);
x += i * width;
break;
}
step = ((step + 1) % 4);
}
}
}