Click here to Skip to main content
16,005,467 members
Home / Discussions / Java
   

Java

 
AnswerRe: My code won't complile right in JCreator Pin
David Skelly17-Sep-09 22:37
David Skelly17-Sep-09 22:37 
QuestionLooking for reading Material on Concurrent Programming in Java Pin
that_dude_tj17-Sep-09 8:43
that_dude_tj17-Sep-09 8:43 
AnswerRe: Looking for reading Material on Concurrent Programming in Java Pin
427748017-Sep-09 15:45
427748017-Sep-09 15:45 
GeneralRe: Looking for reading Material on Concurrent Programming in Java Pin
that_dude_tj18-Sep-09 13:59
that_dude_tj18-Sep-09 13:59 
Questionhow to implement text to speech converter in java Pin
gharekiran16-Sep-09 23:13
gharekiran16-Sep-09 23:13 
AnswerRe: how to implement text to speech converter in java Pin
TorstenH.17-Sep-09 0:05
TorstenH.17-Sep-09 0:05 
AnswerRe: how to implement text to speech converter in java Pin
427748017-Sep-09 15:44
427748017-Sep-09 15:44 
QuestionImplementing a "Paint Can"-type tool Pin
max2929716-Sep-09 14:21
max2929716-Sep-09 14:21 
Hey guys! So I've been trying to get this utility method to work for a while and can't seem to stop overloading the stack. The method should be able to emulate the Paint Can Tool in MS Paint. It takes a BufferedImage, the x- and y-coordinates of the point to apply the method to, and the color with which to paint the area. My implementation is a recursive one, and I know this is the reason for the overflow, but I haven't done any complex recursive method writing as of yet and don't know how I can fix my problem. Here is the code I've written:


static void paintCan(BufferedImage image, int x, int y, Color color) {
	int[][] array = new int[image.getWidth()][image.getHeight()];
	
	for (int r = 0; r < image.getHeight(); r++)
		for (int c = 0; c < image.getWidth(); c++)
			array[c][r] = image.getRGB(c, r);
			
	changeColor(array, x, y, array[x][y], color.getRGB());
	
	for (int r = 0; r < image.getHeight(); r++)
		for (int c = 0; c < image.getWidth(); c++)
			image.setRGB(c, r, array[c][r]);
}

static void changeColor(int[][] image, int x, int y, int from, int to) {
	if (image[x][y] == from) {
		image[x][y] = to;
		
		int left = x - 1;
		int right = x + 1;
		int up = y - 1;
		int down= y + 1;
		
		if (left >= 0)
			changeColor(image, left, y, from, to);
		if (right < image.length)
			changeColor(image, right, y, from, to);
		if (up >= 0)
			changeColor(image, x, up, from, to);
		if (down < image[0].length)
			changeColor(image, x, down, from, to);
	}
}


This method works perfectly for smaller areas, but when the area selected at the (x, y) point requires too much recursion, a runtime error is thrown. Does anyone know how I can get the method to use less memory and not overload the stack? Help is very appreciated Smile | :) Thank you!

-max
AnswerRe: Implementing a "Paint Can"-type tool Pin
427748016-Sep-09 16:34
427748016-Sep-09 16:34 
GeneralRe: Implementing a "Paint Can"-type tool Pin
max2929716-Sep-09 16:40
max2929716-Sep-09 16:40 
AnswerRe: Implementing a "Paint Can"-type tool Pin
max2929716-Sep-09 16:57
max2929716-Sep-09 16:57 
GeneralRe: Implementing a "Paint Can"-type tool Pin
427748016-Sep-09 17:57
427748016-Sep-09 17:57 
GeneralRe: Implementing a "Paint Can"-type tool Pin
sharkbc17-Sep-09 0:11
sharkbc17-Sep-09 0:11 
Questiontapi in java Pin
kareemmahammed11-Sep-09 17:59
kareemmahammed11-Sep-09 17:59 
AnswerRe: tapi in java Pin
427748011-Sep-09 20:44
427748011-Sep-09 20:44 
Questionjava.security.InvalidKeyException, Can somebody Help Me!! Pin
ChiSmile10-Sep-09 3:57
ChiSmile10-Sep-09 3:57 
AnswerRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
427748010-Sep-09 11:35
427748010-Sep-09 11:35 
GeneralRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
ChiSmile10-Sep-09 19:22
ChiSmile10-Sep-09 19:22 
GeneralRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
427748010-Sep-09 20:11
427748010-Sep-09 20:11 
GeneralRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
ChiSmile11-Sep-09 0:13
ChiSmile11-Sep-09 0:13 
GeneralRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
ChiSmile11-Sep-09 20:34
ChiSmile11-Sep-09 20:34 
GeneralRe: java.security.InvalidKeyException, Can somebody Help Me!! Pin
427748011-Sep-09 20:45
427748011-Sep-09 20:45 
QuestionBeautiful tooltip for TrayIcon Pin
sharkbc9-Sep-09 22:49
sharkbc9-Sep-09 22:49 
AnswerRe: Beautiful tooltip for TrayIcon Pin
427748010-Sep-09 3:39
427748010-Sep-09 3:39 
GeneralRe: Beautiful tooltip for TrayIcon Pin
sharkbc10-Sep-09 17:07
sharkbc10-Sep-09 17:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.