* Visite o ALJUG - http://aljug.blogspot.com - Noticias sobre a comunidade java alagoana e do mundo * Visite o blog Mundo Gamificado www.mundogamificado.com.br - E vamos mudar o mundo! *

segunda-feira, 9 de maio de 2011

Assigning a color to integer

Hi everyone,
today I'll give an example of color assign a colorto a number when you are developing a program that has the need to present positive or negative numbers just think how to makethese numbers have something visual to identify them and I had thisproblem when he was developing a data management system, forexample in a month was July and the following month he was 8 thenwent up a point and wanted this one point is shown in green andsome data presented if negative data that shows up in red. go towork. First let's make a method that returns the desired value.

public String Comparação(){} //comparing number data

Let's go inside the body of logic, as I said it is a method of strings, I'll have to do the conversion with parseInt. I'll put something visual, such as JOptionPane.

String Numero = JOptionPane.showInputDialog("Digite um número");
int numero = Interger.parseInt(Numero);

And I keep doing logic with the if.

if(numero < 0)
{
Numero = "< html >< font color=\"red\" >" + Numero + "< / font >< / html>";
}else{
Numero = "< html>< font color=\"green\">" + Numero + "< / font>< / html>";
}


See that I needed to put the html tag to help. And in the end I put the return Number;

Ready now can test.

Until the next post.

Nenhum comentário: