473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how can i draw more rectangle?

8 New Member
hello

how can i draw more rectangle in JApplet 10 time with different size

this my program

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

public class draw extends JApplet {

public void init() {

repaint();
}
public void paint(Graphics g) {
int a=0;
int X=0;
int Y=0;
g.drawRect(X,Y, 30, 10);
for(a=0;a<=10;a++)

g.drawRect(X+10,Y+10,30,15);
a=a+1;
{

}
}
}
Jun 6 '10 #1

✓ answered by ThatThatGuy

@dl3kla
for(a=0;a<=10;a++)

g.drawRect(X+10,Y+10,30,15);
a=a+1;
that loop of yours is totally incorrect..
you shouldn't increment the counter of a for loop when you're already incrementing it in the for loop definition.

And

It seems that you're drawing the rectangle in the same location everytime..

you must change the location of the image by some counter
a more better for loop is listed below
Expand|Select|Wrap|Line Numbers
  1. int x=0;
  2. int y=0;
  3. for(a=0;a<=20;a++)
  4. {
  5. g.drawRect(x,y,30,15);
  6. x+=0;
  7. y+=10;
  8. }
  9.  

hope it works

2 2756
ThatThatGuy
449 Recognized Expert Contributor
@dl3kla
for(a=0;a<=10;a++)

g.drawRect(X+10,Y+10,30,15);
a=a+1;
that loop of yours is totally incorrect..
you shouldn't increment the counter of a for loop when you're already incrementing it in the for loop definition.

And

It seems that you're drawing the rectangle in the same location everytime..

you must change the location of the image by some counter
a more better for loop is listed below
Expand|Select|Wrap|Line Numbers
  1. int x=0;
  2. int y=0;
  3. for(a=0;a<=20;a++)
  4. {
  5. g.drawRect(x,y,30,15);
  6. x+=0;
  7. y+=10;
  8. }
  9.  

hope it works
Jun 7 '10 #2
dl3kla
8 New Member
thank you very much
Jun 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: AsuWoo | last post by:
you are given two rectangles, each defined by an upper left(UL) corner and a low right(LR)corner,Both rectangles' edges will always be parrallel to the x or y axis ,Write a window program with c#...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
0
by: B-Dog | last post by:
I'm using this class here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/printwinforms.asp to build a tabular print report and it works fine but when I try and add...
1
by: tejesht | last post by:
Hello everybody, I want to notify the user about a particular area on a image by drawing a rectangle around that area. Can any one suggest me for the same. Please specify the code too. ...
1
by: Jeff Waskiewicz | last post by:
Hello All, I'm trying to solve a nagging problem. The goal is to draw a rectangle over the top of all the other controls on a form. Specifically, over a ChartFX control. The user would draw...
0
by: Adam Clauss | last post by:
I have a ListView in which I am attempting to get it to not draw the 'dotted' rectangle around items which are selected. All other drawing should be normal. I am using the listbox in SmallIcon...
10
by: kimiraikkonen | last post by:
Hi, If previous post was missing, here's the complete one: I'm trying to draw a rectange on a picturebox image using mouse move event but the problem is that the rectangle selection / drawing...
0
by: Red Head | last post by:
Hello I've written some code to draw a rectangle on a picture box when the user moves the mouse. (the previous rectangle is cleared) This works fine but the very first rectangle is not removed...
0
by: joshguru | last post by:
i have a button in my form in vb.net.i have to click the button and i have to draw a rectangle by mouse....ie using button click event i have to draw as my desired size....
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.