esperanto
français
 

Ultime meliorationes

Nos va meliorar le exhibition RGB in base dece addente le litteras R, G e B ante le cifras. Illo non es multo difficile, sed nos debe pro illo allongar le zona de texto T e accurtar le zona U, de maniera que illos pote apparer super le pannello :

import java.applet.*;
import java.awt.*;

public class applet23 extends Applet
{
int abscissa = 0;
int ordinata = 0;
int contator = 0;
int R = 0;
int G = 0;
int B = 0;
int i = 0;
Quadrato2 [] tabQuadrato = new Quadrato2[216];
boolean intra;
String t = new String("");
String u = new String("");
TextField T = new TextField(t, 14);
TextField U = new TextField(t, 7);
Panel MiPannello = new Panel();

public void init()
{
setBackground(Color.white);
setLayout(new BorderLayout());
MiPannello.add(T);
MiPannello.add(U);
MiPannello.setBackground(Color.white);
   for (int R=0;R<256;R+=51)
   {
   for (int G=0;G<256;G+=51)
      {
      for (int B=0;B<256;B+=51)
         {
         tabQuadrato [i] = new Quadrato2(abscissa,ordinata, R, G, B);
         abscissa+=12;
         contator +=1;
         i++;
         if (contator == 18)
            {
            contator = 0;
             abscissa = 0;
            ordinata += 12;
            }//if
         }//for B
      }//for G
   }//for R
add("South", MiPannello);
}//init

public void paint(Graphics g)
   {
   for (int j=0;j<216;j++)
      {
      tabQuadrato[j].paint(g);
      }//for j
   }//paint

   public boolean mouseDown(Event evt, int x, int y)
   {
   int k;
   for (k=0; k<216;k++)
      {
      intra =(tabQuadrato[k].inside(x,y)) ? true : false;
      if (intra)
         {
         t = "R: " +Integer.toString(tabQuadrato[k].R) + " G: " + Integer.toString(tabQuadrato[k].G) + " B: " + Integer.toString(tabQuadrato[k].B);
         T.setText(t);

         String zero = new String("0");
         String uR = new String();
         uR = Integer.toString(tabQuadrato[k].R, 16);
         if (uR.equals(zero)) {uR = zero + zero;}
         uR = "#" + uR;

         String uG = new String();
         uG = Integer.toString(tabQuadrato[k].G, 16);
         if (uG.equals(zero)) {uG = zero + zero;}

         String uB = new String();
         uB = Integer.toString(tabQuadrato[k].B, 16);
         if (uB.equals(zero)) {uB = zero + zero;}

         U.setText(uR + uG + uB);
         }
      }//for k
   return true;
   }

   public boolean mouseUp(Event evt, int x, int y)
   {
   intra=false;
   return true;
   }
}

 

Ecce le resultato :

Le codice del classe preste al uso
Le codice del applet preste al uso

Ecce ! Le presentation poterea ancora esser meliorate, e le conversiones in hexadecimal poterea esser includite in le classe Quadrato2, sed le scopo principal es attingite.