The method add

Résolu
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 19 juil. 2010 à 12:19
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 25 juil. 2010 à 08:45
bonjour
j'ai essayé ce programme en compilant j'ai erreur
suivantes veuillez m'aider s'il vous plaît
package Textprg;
public class Brighten 
{
final static int ROWS=80;
final static int COLUMNS=80;
final static int SQUARE_SIZE=5;

static int currentRow;
static int currentColumn;

public static void main(String[]args)
{
Mosaic.open(ROWS,COLUMNS,SQUARE_SIZE,SQUARE_SIZE);
currentRow=ROWS/2;
currentColumn=COLUMNS/2;
while(Mosaic.isOpen())
{
brightenSquare(currentRow,currentColumn);
randomMove();
Mosaic.delay(20);

}
}
static void brightenSquare(int row,int col)
{
int r=Mosaic.getRed(row,col);
r+=25;
Mosaic.setColor(row,col,r,0,0);
}
static void randomMove()
{
int directionNum;
directionNum=(int)(4*Math.random());
switch(directionNum)
{
case 0:
currentRow--;
if (currentRow<0)
currentRow=ROWS-1;
break;
case 1:
currentColumn++;
if (currentColumn>=COLUMNS)
currentColumn=0;
break;
case 2:
currentRow++;
if (currentRow>=ROWS)
currentRow=0;
break;
case 3:
currentColumn--;
if (currentColumn<0)
currentColumn=COLUMNS-1;
break;
}
}
}


package Textprg;
import java.awt.*;
import java.awt.event.*;
public class Mosaic 
{
   private static Frame window;         // A mosaic window, null if no window is open.
   private static MosaicCanvas canvas;  // A component that actually manages and displays the rectangles
      
   public static void open() {
         // Open a mosaic window with a 20-by-20 grid of squares, where each
         // square is 15 pixels on a side.
      open(20,20,15,15);
   }
   
   public static void open(int rows, int columns) {
         // Open a mosaic window with the specified numbers or rows and columns
         // of squares, where each square is 15 pixels on a side.
      open(rows,columns,15,15);
   }
   
   synchronized public static void open(int rows, int columns, int blockWidth, int blockHeight) {
         // Open a window that shows a mosaic with the specified number of rows and
         // columns of rectangles.  blockWidth and blockHeight specify the
         // desired width and height of rectangles in the grid.  If a mosaic window
         // is already open, it will be closed before the new window is open.
      if (window != null)
         window.dispose();
      canvas = new MosaicCanvas(rows,columns,blockWidth,blockHeight);
      window = new Frame("Mosaic Window");
      window.add("Center",canvas);
      window.addWindowListener(
            new WindowAdapter() {  // close the window when the user clicks its close box
               public void windowClosing(WindowEvent evt) {
                  close();
               }
            });
      window.pack();
      window.show();
   }
   
   synchronized public static void close() {
          // If there is a mosiac window, close it.
      if (window != null) {
         window.dispose();
         window = null;
         canvas = null;
      }
   }

   synchronized public static boolean isOpen() {
          // This method returns a boolean value that can be used to
          // test whether the window is still open.
      return (window != null);
   }
   
   public static void delay(int milliseconds) {
         // Calling this routine causes a delay of the specified number
         // of milliseconds in the program that calls the routine.  It is
         // provided here as a convenience.
      if (milliseconds > 0) {
        try { Thread.sleep(milliseconds); }
        catch (InterruptedException e) { }
      }
   }

   public static Color getColor(int row, int col) {
         // Returns the object of type Color that represents the color
         // of the grid in the specified row and column.
      if (canvas == null)
         return Color.black;
      return canvas.getColor(row, col);
   }

   public static int getRed(int row, int col) {
         // Returns the red component, in the range 0 to 255, of the
         // rectangle in the specified row and column.
      if (canvas == null)
         return 0;
      return canvas.getRed(row, col);
   }

   public static int getGreen(int row, int col) {
         // Returns the green component, in the range 0 to 255, of the
         // rectangle in the specified row and column.
      if (canvas == null)
         return 0;
      return canvas.getGreen(row, col);
   }

   public static int getBlue(int row, int col) {
         // Returns the blue component, in the range 0 to 255, of the
         // rectangle in the specified row and column.
      if (canvas == null)
         return 0;
      return canvas.getBlue(row, col);
   }

   public static void setColor(int row, int col, Color c) {
          // Set the rectangle in the specified row and column to have
          // the specified color.
      if (canvas == null)
         return;
      canvas.setColor(row,col,c);
   }

   public static void setColor(int row, int col, int red, int green, int blue) {
          // Set the rectangle in the specified row and column to have
          // the color with the specifed red, green, and blue components.
      if (canvas == null)
         return;
      canvas.setColor(row,col,red,green,blue);
   }

   public static void fill(Color c) {
          // Set all the rectangels in the grid to the color c.
      if (canvas == null)
         return;
      canvas.fill(c);
   }

   public static void fill(int red, int green, int blue) {
          // Set all the rectangles in the grid to the color with
          // the specified red, green, and blue components.
      if (canvas == null)
         return;
      canvas.fill(red,green,blue);
   }

   public static void fillRandomly() {
          // Sets each rectangle in the grid to a different randomly
          // chosen color.
      if (canvas == null)
         return;
      canvas.fillRandomly();
   }
   
}  // end of class Mosaic

2 réponses

cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
25 juil. 2010 à 08:45
j'ai resolu ce problem merci beaucoup
3
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
19 juil. 2010 à 12:40
excusez moi erreur est:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method add(String, Component) in the type Container is not applicable for the arguments (String, MosaicCanvas)

at Textprg.Mosaic.open(Mosaic.java:30)
at Textprg.Brighten.main(Brighten.java:13)
0
Rejoignez-nous