Problem with Thickness

Heres my problem I am making this paint program and I have been stuck on getting my method to thicken the lines, circles, ect. but everytime i click the button i get a different random thickness it seems. For instance, I will click it the first time to set thickness from 1 to 2 but i will go from 1 to 3 and then click again and go to 2. I am pretty sure my coding sould work correctly for this point but its not any suggestions how to rewrite it or improve on it.

I will explane what each variable is

publicvoid howmanytime()

{

if(clicked ==true)// boolean value that is made true when thickness button is clicked

if(Tc == 1)// sees if Tc is equal to 1

Tc = 2;// If it is equal to 1 sets Tc as 2

elseif(Tc == 2)// and so on

Tc = 3;

elseif(Tc == 3)

Tc = 1;

thickness();// Calls next methos to add values to arrays and change thickness

}

publicvoid thickness()

{

clicked =false;// boolean that is used in method before to give Tc the value

switch(Tc)// Tc chosses thicknesses

{

case 1:// sees is Tc is equal to 1

thick = 1.0f;// Sets thick float value to 1.0

if(rect ==true)// Checks to see if boolean rect (making a rectangle draw) is true

tr[trc] = 1.0f;// Setting tr's, a float array, trc, a int value to specific what float value to change, to 1.0

elseif(circle ==true)// and so on and so on

to[toc] = 1.0f;

elseif(line ==true)

tl[tlc] = 1.0f;

elseif(pix ==true)

tp[tpc] = 1.0f;

break;

case 2:

thick = 2.0f;

if(rect ==true)

tr[trc] = 2.0f;

elseif(circle ==true)

to[toc] = 2.0f;

elseif(line ==true)

tl[tlc] = 2.0f;

elseif(pix ==true)

tp[tpc] = 2.0f;

break;

case 3:

thick = 3.0f;

if(rect ==true)

tr[trc] = 3.0f;

elseif(circle ==true)

to[toc] = 3.0f;

elseif(line ==true)

tl[tlc] = 3.0f;

elseif(pix ==true)

tp[tpc] = 3.0f;

break;

}

}

[4324 byte] By [Wolfx128a] at [2007-10-3 9:11:55]
# 1
I don't see anything in that code that would effect line thickness.
paulcwa at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 2

Its not placed here but the clode that deals with is goes like

public void -NAME-(int[] t*, int t*c)

{

Graphics2D g2 = (Graphics2D)g;

g2.setColor(Color.black);

g2.setStroke(new BasicStroke(thick));

g2.drawOval(sx,sy,ex-sx,ey-sy);

}

not the exact code but works on the same principles

Wolfx128a at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 3
Are you afraid someone will steal your code?
floundera at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 4
No its just to put it in would take forever to make notes for all of it because i am lazy and used alot of abbrevation i Understand. So Im tring to make it easier by giving base info and not giving you the Ultimate Wheres Waldo
Wolfx128a at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 5
Given your reticence to show your code, the only appropriate answer is the generic one:You have a bug somewhere. Add debugging code, or use a debugger, to find it.
paulcwa at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 6

OP, what abt optimizing ur code a little bit

1. You can avoid that nested if-else

if(clicked) {

if(Tc == 3) Tc = 1;

else Tc++;

}

2. Instead of switch case with duplicate statements, you can use a function

static foo(float thick){

if(rect == true)

tr[trc] = thick;

else if(circle == true)

to[toc] = thick;

else if(line == true)

tl[tlc] = thick;

else if(pix == true)

tp[tpc] = thick;

break;

}

Cheers

null

astelaveestaa at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...
# 7
:) thx works GREAT
Wolfx128a at 2007-7-15 4:24:08 > top of Java-index,Java Essentials,Java Programming...