|
hi there, i have to develop an application where have a method that modify heavily one class instance and it take a lot of resources. I think that a good idea to solve it create a new object with new data something like :
public class A extend abstractclass {
//// data .... bla bla bla
A() {
//constructor ... bla bla bla
}
public void famousmet(blablabla) {
// i would like to work anything like:
this = new A(blablabla);
}
But this don't work.
How can i do it? is it possible? thanks.
|
|
|
|
|
Can you learn to format your code, it makes it readable:
public class A extend abstractclass {
A() {
}
public void famousmet(blablabla) {
this = new A(blablabla);
}
}
You cannot assign anything to this , it represents the current instance of the class.
A similar approach would be to create a new copy of the class and return it to the caller. Would this work:
public A copyAndReturn(blahblah) {
A copy = new A();
copy.variable = this.variable;
...
return copy;
}
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hello,
in my app I am extensively using JTree and building nodes with DefaultMutableTreeNode . But I didn't found the setToolTipText method in DefaultMutableTreeNode to tooltip its content, except this[^] article to do the same.
Any shorter idea, or already similar existing object within standard packages?
Kujtim
|
|
|
|
|
I think that looks a pretty tidy and simple solution.
You have the class ToolTipTreeCellRenderer , so use it as the renderer for your trees. Decide on an interface for the tool tip text, make sure your nodes support and use it.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
How to round this 106.19999999999999 number like 106.20 by using java script?
|
|
|
|
|
udch wrote: java script
That's not Java
Anyway you could just do Math.round[^](106.19999999999999 * 100) / 100
|
|
|
|
|
Hi all,
I want to animate 2D images, specially face;
My scenario is i should draw contours of face around the image, on next key frame i should change the shapes of contour. When i animate i get the face in the image should animate accordingly.
It is something like morphing, but in morphing we have 2 images. In my scenario i have one image.
If i conclude i want some thing like this http://www.youtube.com/watch?v=ed_HAJGJfeQ[^]
I want to do it programatically, to create Talking Pictures.
I know you all guys are specialist into such kind of things. Please guide me how to full fill my scenario.
Thanks in advance.
Please do it as early as possible.
Nazar Hussain
|
|
|
|
|
Identical question on the C# forum, could the two be related?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I posted on two forums, so if any guru of Java or C# could help me.
|
|
|
|
|
Is the question Java or C#? If one or other, then in belongs in just the one.
Cross posts are very distracting, as you can see, a lot of pouple go to multiple forums and seeing the same post is just not accepted.
Please, only post a question in the one, most relevant, place. if you are not sure you are posting in the righ forum, say so up front and you will be directed, politely, to the correct forum.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Ok. Thanks for your guidance. I will never post same question on multiple forums.
Regards
Nazar
|
|
|
|
|
hi, im new to java.
regarding string array, is there a way to do string index.??
example:
String[] arr = null;
arr["name"]="myname";
arr["age"]="myage";
arr["gender"]="mygender";
The reason to my question is because im creating a class user. the variables will be private. i would need to get and set these variables, therefore creating a set of get() and set() function for each variable. If i can do the above method, i would simply need one set of get() and set() function.
hope thats not too confusing.
Thanks.
modified on Saturday, July 25, 2009 7:12 AM
|
|
|
|
|
Check this code, if convienent:
class Indexer{
static int returnIndex(String inp)
{
int ret_val=-1;
if(inp.equals("name")) ret_val=0;
if(inp.equals("age")) ret_val=1;
if(inp.equals("gender")) ret_val=2;
return ret_val;
}
public static void main(String [] args){
String[] arr = null;
arr[returnIndex("name")]="myname";
arr[returnIndex("age")]="myage";
arr[returnIndex("gender")]="mygender";
}
}
Kujtim
|
|
|
|
|
How will the keys be generic if he doesn't know the key strings to begin with?
Personaly I wold use a swicth , instead of multiple if statements, in returnIndex .
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
You will need to use Map[^]. Explanation[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Hello Pals,
I've written a program which declares an array of size 3, initializes its elements and prints the elements. The program is as follows:
package Demo;
import java.io*;
public class A{
public A(){}
public static void main(String args[])throws IOException{
int[] anArray=new int[3];
anArray[0]=10;
anArray[1]=20;
anArray[2]=30;
System.out.println("Array[0] index now contains: "+anArray[0]);
System.out.println("Array[1] index now contains: "+anArray[1]);
System.out.println("Array[2] index now contains: "+anArray[2]);
}
}
Now, suppose the array size is very long say 100! Then, will I have to keep on typing System.out.println(anArray[0]......anArray[99]);???
Wont that be huge? I C#.NET, we have the for-each loop construct to print all the elements in an array. Similarly, can I implement the for-each loop here? I did try, but I get Error as this: missing .class
Can anyone help me with an effecient way of printing elements in Java?
Help will be greatly appreciated,
Rajdeep
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
I take it that you still can't use google. Help[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
You really don't have a clue, do you?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
Is there a way to create and use a ruby object inside java code?
Thanks
|
|
|
|
|
|
Hello,
this is a simple question I think. I am trying to get the array of bytes as a reference from method, although in the method in creates the array, outside returns the original initialized with null. How to get it from routine, but as parameter since routine returns boolean. Maybe routine should return class containing the array and boolean variable.
This is the code:
public class PassingRefs{
static boolean varbyteobject(byte [] obj)
{
System.out.println("---inside routine---");
int rndlen=(int)(Math.round(Math.random()*50)+1);
obj=new byte[rndlen];
System.out.println(obj.length);
return true;
}
public static void main(String [] args){
byte [] inpobj=null;
varbyteobject(inpobj);
System.out.println("---out from routine---");
System.out.println(inpobj.length);
}
}
and this is what I get after execution:
---inside routine---
29
---out from routine---
Exception in thread "main" java.lang.NullPointerException
at PassingRefs.main(PassingRefs.java:18)
Kujtim
|
|
|
|
|
In Java, all method parameters are passed by value, not by reference.
In other words, when you call varbyteobject in your code, it does not pass the reference to the original byte array. It passes a copy of the reference to the byte array. So, this line of code:
obj=new byte[rndlen];
has no effect on the original reference to the byte array in the calling main method since you are updating the copy, not the original.
It is explained in more detail in this article:
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html[^]
You can just return the new byte array from your method. Why do you want to return a boolean?
|
|
|
|
|
SPIRANCA wrote:
static boolean varbyteobject(byte [] obj)
{
System.out.println("---inside routine---");
int rndlen=(int)(Math.round(Math.random()*50)+1);
obj=new byte[rndlen];
System.out.println(obj.length);
return true;
}
varbyteobject(inpobj);
Why do you need to return a boolean ? Why not just pass the byte[] back?
Personally I would return an intialised byte[] if it was true and null if it was false .
static byte[] varbyteobject(byte[] obj)
{
...
return obj;
}
if ((inpobj = varbyteobject(inpobj)) != null)
System.out.println(inpobj.length);
else
System.out.println("Array not initialised.");
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Possible solution would be to return a struct-class(since Java doesn't supports structs), so that it contains the byte array and the boolean variable(which tells about success or failure). Although we could check the success or failure from the byte array-some of the byte contain that info.
Thanks anyway,
Kujtim
|
|
|
|