Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i need help

 
asa dos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every one
how are you all?
i need to do this click the image to see large




i have write a code the draw only one i dont know how to do all
this the code i wrote


import java.applet.* ;
import java.awt.* ;
public class hw01_Lines extends Applet {
int SEGMENTS ;
public void init() {
SEGMENTS = getDefParam("Segments",10) ;
}
public void paint(Graphics g) {
int w = getSize().width - 10 ;
int h = getSize().height - 10 ;
g.drawRect(0,0,w,h) ;
double dx = (double) w / SEGMENTS ;
double dy = (double) h / SEGMENTS ;
double x = 0 ;
double y = 0 ;
for (int i = 0 ; i <=SEGMENTS ; i++) {
g.drawLine(0,0,(int) x,h) ;
g.drawLine(0,0,w, (int) y) ;
g.drawLine(w,h,(int) x,0) ;
g.drawLine(w,h,0, (int) y) ;
x += dx ;
y += dy ;
}
}
int getDefParam(String ParamName, int dv) {
String s = getParameter(ParamName) ;
return (s == null) ? dv : Integer.valueOf(s).intValue() ;
}
}

any one help me ??
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

That looks pretty good to me; what's the problem you're having with it? Please don't expect somebody to cut and paste and run your code; you're much more likely to get answers if you don't require us to do that.
 
asa dos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change in the code
import java.applet.* ;
import java.awt.* ;
public class hw4_Lines extends Applet {

public void paint(Graphics g) {
int w = getSize().width - 10 ;
int h = getSize().height - 10 ;
int n=3;

for (int j=0;j<n;j++)
{ w=w/n;
h=h/n;
for(int k=0;k<n;k ++){

int min=Math.min(w,h);
int wr=w-min+10;
int hr=h-min+10;

g.drawRect(wr/2+k*w,hr/2+k*h,min,min) ;

}//for k
}//for j
}

}//class paint


the output is the squars are diagnal ??!i dont know why
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you divide one integer by another, the answer is also an integer; that's going to lead to a lot of things here being truncated to zero, which is most likely not what you want.
 
asa dos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
helllo
i do the squars but i cannt draw the lines right
this is the code
import java.applet.* ;
import java.awt.* ;
public class hw_Lines extends Applet {
int SEGMENTS ;
public void init() {
SEGMENTS = getDefParam("Segments",10) ;
}
public void paint(Graphics g) {
int w = getSize().width - 10 ;
int h = getSize().height - 10 ;
int n=3;
w=w/n;
h=h/n;
int dh=0;
int min=Math.min(w,h);
min=min-10;

int dd=(w-min)/2;
int ff=(h-min)/2;



for (int i = 0 ; i <n ; i++) {

int dw=0;

for (int j = 0 ; j <n ; j++) {
g.drawRect(dw+dd+j,dh+ff+j,min,min) ;
dw=dw+w;
double dx = (double) w / SEGMENTS ;
double dy = (double) h / SEGMENTS ;
double x = 0 ;
double y = 0 ;
for (int k = 0 ; k <=SEGMENTS ; k++) {
g.drawLine((int) x,h,min,min) ;
g.drawLine(w, (int) y,0,0) ;
g.drawLine((int)x,0,w,h ) ;
g.drawLine(0, (int) y,w,h) ;
x += dx ;
y += dy ;
}
}
dh=dh+h;
}

}
int getDefParam(String ParamName, int dv) {
String s = getParameter(ParamName) ;
return (s == null) ? dv : Integer.valueOf(s).intValue() ;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic