bonjour
j'ai essayé ce programme en compilant j'ai erreur
suivantes veuillez m'aider s'il vous plaît

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)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
 
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