By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Need some assistance please

P: n/a
Hello everyone! I am trying to learn java and have run into kind of a
snag. Here is the code that I have so far:

------ <begin_code> ----------

import javax.swing.*;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.Graphics;

public class Rectangles {

public static void main ( String args[] ) {

// Variables to hold the users input
String number1;
String number2;
String number3;
String number4;
int x;
int y;
int width;
int height;

nextRect: // Continue point for drawing another Rectangle

// Gather input and parse into integers
number1 = JOptionPane.showInputDialog(null, "Please input the x value: ");

number2 = JOptionPane.showInputDialog(null, "Please input the y value: ");
number3 = JOptionPane.showInputDialog(null, "Please input the width
value: ");
number4 = JOptionPane.showInputDialog(null, "Please input the height
value: ");

x = Integer.parseInt(number1);
y = Integer.parseInt(number2);
width = Integer.parseInt(number3);
height = Integer.parseInt(number4);

public void paint( Graphics g )
{
super.paint(g);

g.drawRect(x, y, width, height);

String answer;

answer = JOptionPane.showInputDialog(null, "Would you like to draw
another rectangle? ");

if ( answer == "yes | y")
continue nextRec; // go to nextRec and start over
else
System.exit(0);
}

}

}

------ </end_code> --------

Now, the problem I am having, is I am getting an error between the 't' and
the '(' in "public void paint( Graphics g )" Please be kind in your
comments and keep in mind that I am just learning. If I am trying to do
something that I shouldn't please let me know. I would really like to
know why this won't work.

Thank you in advance!

Regards,

jlk
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
jlk-

You are attempting to define your paint(Graphics) method within your main
method. This will not work. Define the paint method outside of the
main method and you'll have much more luck,
-c
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.