hi all ,
I have used switch case to check whether a particular character is present in another array of characters. i want the code to do if the particular character is found then paint function is called and the character is given a colour. but what happens is that the if loop in paint method is not getting executed. also the else codition in the paint method paints for the number of characters present in the array. (but the check is proper (i suppose) based on the print statement in the switch case)
here is my code:
I have used switch case to check whether a particular character is present in another array of characters. i want the code to do if the particular character is found then paint function is called and the character is given a colour. but what happens is that the if loop in paint method is not getting executed. also the else codition in the paint method paints for the number of characters present in the array. (but the check is proper (i suppose) based on the print statement in the switch case)
here is my code:
Code:
public void assigning()// function
{
for (int i=0;i<seqlength;i++)//a for loop to get a letter
{
switch(seq[i])// main array to which the cases are compared
{
case 'A':
case 'G':
case 'I':
case 'L':
case 'M':
case 'F':
case 'P':
case 'W':
case 'V':
{
res=1;
repaint();
System.out.println("reach");
break;
}
case 'R':
case 'N':
case 'D':
case 'C':
case 'E':
case 'H':
case 'K':
case 'S':
case 'T':
case 'Y':
{
res=0;
repaint();
System.out.println("reach");
break;
}
default:
repaint();
}
//return res;
}
}
public void paint(Graphics gc)
{
String s = "reach";
gc.drawOval(centre1, centre2, 2* radius, 2*radius);
gc.setFont(new Font("Courier",Font.BOLD,14));
gc.drawString(title,700,380);
gc.drawString(sequen,700,400);
gc.drawString(sequences,900,400);
gc.drawString(hydropho,700, 420);
gc.drawString(hydrophl, 700,440);
if(res==1)
{
gc.drawString(s, 700,700) ;// not executing the loop
for (int i =0;i<seqlength;i++)
{
for (int j=0; j<hydroblen;j++)
{
x[i]= x0 + radius*Math.sin(theta*(i));
y[i]= y0 - radius*Math.cos(theta*(i));
X[i] = (int) x[i];
Y[i]= (int) y[i];
gc.fillOval(X[j]-7,Y[j]-7,14,14);
seq1 = seq[i] + "";
//hydrop1 = hydrop[j]+"";
gc.drawString(seq1, X[i], Y[i]-8);
gc.drawString("",X[j], Y[j]-8);
gc.drawLine(X[j],Y[j],X[j+1],Y[j+1]);
gc.setColor(Color.yellow);
}
}
}
else if (res ==0)
{
{ // executes here.
for (int i=0; i<seqlength;i++)
{
for (int j= 0; j<hydroplen;j++)
{
gc.drawString(s,250,250);//here too
x[i]= x0 + radius*Math.sin(theta*(i));
y[i]= y0 - radius*Math.cos(theta*(i));
X[i] = (int) x[i];
Y[i]= (int) y[i];
gc.fillOval(X[j]-7,Y[j]-7,14,14);// results in filling the oval equal to the hydroplen and not accor to charac.
seq1 = seq[i] + "";
//hydrop1 =hydrop[j]+"";
gc.drawString(seq1,X[i],Y[i]-8);
gc.drawString("", X[j], Y[j]-8);
gc.drawLine(X[j],Y[j],X[j+1],Y[j+1]);
gc.setColor(Color.blue);
}
}
}
}
Comment