"\n" em jLabel <NETBEANS>

3 respostas
Adesbh

E ai galera!

Sou noob ainda nisso… to precisando de uma força.

seguinte, preciso settar um texto em uma label, mas esse texto tem quebra de linha:

CursoMDC = CursoMDC + “\n” + n1 + " = " + n2 + " * " + a / b + " + " + a % b;

o “+ “\n”” não funciona na jLabel. Se printo ele em uma jOptionPane, sai bunitinho, com a quebra de linha, mas na label não sai a quebra de linha de jeito nenhum!

qual recurso posso usar para dar certo?

That’s all!!

Valew galera!!! :smiley:

3 Respostas

marciofermino

Amigo use String

String x
String y

resultato = x+y

Adesbh

O codigo um pouco mais completo…

no painel eu setto o calculo da classe. segue o set:

jLabel15.setText(cl.combLinear2(String.valueOf(n1), String.valueOf(n2))); //Combinação linear

segue a classe:

package mddesktop;

public class CombinacaoLinear

{

public boolean prim = true;

public long aNativo, bNativo; //valores iniciais de A e B;

public long xNativo, yNativo; //valores cumulativos de X e Y;

public String combLinearV = “”;

public long resto;

public long x;

public long x0;

public long auxX;

public long y;

public long y0;

public long auxY;

public long cont = 0;

public String combLinear2 (String n1, String n2)

{

long a = Integer.parseInt(n1);

long b = Integer.parseInt(n2);

if(prim == true)

{

aNativo = Integer.parseInt(n1);

bNativo = Integer.parseInt(n2);

yNativo = a / b * (-1);

xNativo = 1;

prim = false;

}

resto = a % b;

if (resto != 0)

{

if (cont == 1)

{

y0 = a / b * (-1);

x0 = 1;

combLinearV = combLinearV + “\n + resto + " = " + a + " (" + x0 + ) + " + " + b + " (" + y0 + );

cont++;

}

if (cont == 0)

{

y = a / b * (-1);

x = 1;

combLinearV = combLinearV + “\n + resto + " = " + a + " (" + x + ) + " + " + b + " (" + y + );

cont++;

}

if (cont == 2)

{

if(a == bNativo)

{

x = y0 * x;

y = y0 * y + x0;

combLinearV = combLinearV + “\n + resto + " = " + aNativo + " (" + x + ) + " + " + bNativo + " (" + y + );

}

else

{

auxX = xNativo;

auxY = yNativo;

xNativo = x;

yNativo = y;

y = y0 * y + auxY;

x = y0 * x + auxX;

combLinearV = combLinearV + “\n + resto + " = " + aNativo + " (" + x + ) + " + " + bNativo + " (" + y + );

}

cont = 1;

}

combLinear2 (String.valueOf(b), String.valueOf(resto));

}

return combLinearV;

}

}
Adesbh

galera, consegui! ta ai se alguem tiver a mesma duvida

package mddesktop;

public class CombinacaoLinear

{

public boolean prim = true;

public long aNativo, bNativo; //valores iniciais de A e B;

public long xNativo, yNativo; //valores cumulativos de X e Y;

public String combLinearV = “”;

public long resto;

public long x;

public long x0;

public long auxX;

public long y;

public long y0;

public long auxY;

public long cont = 0;

public String combLinear2 (String n1, String n2)

{

long a = Integer.parseInt(n1);

long b = Integer.parseInt(n2);

if(prim == true)

{

aNativo = Integer.parseInt(n1);

bNativo = Integer.parseInt(n2);

yNativo = a / b * (-1);

xNativo = 1;

prim = false;

}

resto = a % b;

if (resto != 0)

{

if (cont == 1)

{

y0 = a / b * (-1);

x0 = 1;

combLinearV = “” + combLinearV + 
 + resto + " = " + a + " (" + x0 + ) + " + " + b + " (" + y0 + );

cont++;

}

if (cont == 0)

{

y = a / b * (-1);

x = 1;

combLinearV = “” + combLinearV + 
 + resto + " = " + a + " (" + x + ) + " + " + b + " (" + y + );

cont++;

}

if (cont == 2)

{

if(a == bNativo)

{

x = y0 * x;

y = y0 * y + x0;

combLinearV = “” + combLinearV + 
 + resto + " = " + aNativo + " (" + x + ) + " + " + bNativo + " (" + y + );

}

else

{

auxX = xNativo;

auxY = yNativo;

xNativo = x;

yNativo = y;

y = y0 * y + auxY;

x = y0 * x + auxX;

combLinearV =  “” + combLinearV + 
 + resto + " = " + aNativo + " (" + x + ) + " + " + bNativo + " (" + y + );

}

cont = 1;

}

combLinear2 (String.valueOf(b), String.valueOf(resto));

}

combLinearV = combLinearV + “”;
return combLinearV;
}

}

Criado 24 de novembro de 2008
Ultima resposta 24 de nov. de 2008
Respostas 3
Participantes 2