471,090 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,090 software developers and data experts.

Need some assistance please

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 )

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



------ </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!


Jul 17 '05 #1
1 2001

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,
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by CHRIS ALOZIE | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
46 posts views Thread by Bruce W. Darby | last post: by
2 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.