Glad you solved the problem... and yes, static methods can be pretty nice
peter_budo commented: Thanx for reminder on statics ;) +14
BestJewSinceJC 700 Posting Maven
jasimp commented: Nice job helping him out +9
Glad you solved the problem... and yes, static methods can be pretty nice
I'm not sure I understand your class structure, so take this with a grain of salt. You could pass the MainFrame as an argument to AddClientPanel's constructor and then store the MainFrame in a static variable in the AddClientPanel class. AddClientPanel could have a get method that, using the static MainFrame variable, returns whatever info you need. (AddClientPanel is a class, right?)
MainFrame
AddClientPanel ... constructor takes MainFrame variable, then stores it in a static variable. Also has getter.
Other classes ... get Mainframe's info by using AddClientPanel's getter.
Make a boolean allNums = true;
1. Create an array of size 20.
2. Loop: Read the numbers in, and put them into the array
3. Loop: Check the array at each index. If the number isn't there for any index, set allNums to false.
4. If allNums is true, then print true, otherwise, print false.
Just want to comment that you're using this. correctly now. Except in your no argument constructor, "this." isn't necessary at all (although it doesn't hurt, either).
And it looks fine to me. Also, remember to mark solved when you're done asking qns
eww, still can't read it w/ the code tags. code = JAVA perhaps?
How can I access variable in the frame from a component 2-3 levels bellow?
The class that contains the user ID and password should have a get method. Just call it and return the relevant info to caller. No need to pass it to things that don't need it.
try this
File file = new File("C:/theFile.txt");
file.delete();
If its possible to do so then the Javadoc for RandomAccessFile will tell you how.
edit: It looks like it should do it by default from what I just read. Post your code in code tags.
I don't know what Garwick's algorithm is. Logically, if one section of the shelf needs more room, you will then have to re-divide the other sections so that the whole thing takes up the same amount of room as it did previously. Obviously, your project description is suggesting a method called Garwick's algorithm to do this.
Alright, thank you everyone.
Sorry, I should have elaborated further. I actually re-installed Windows Vista, thinking that I had all of my Java projects uploaded to my school's server as a backup. I was correct, except that my MOST important project wasn't a school project, so its not on their server, and it is a project I need. Will I still be able to recover deleted files using any of the tools given in this thread? And, if not, I don't really mind decompiling... as long as it is guaranteed to do the same thing. My project is practically finished and only minor updates will be necessary from this point on, so I'm not too worried about different loop structures, variable names, etc.
You have to tell us what a multiple stack is. I don't think very many people have heard that term before. Then we can help you. If a multiple stack is just more than one stack, which would seem likely, then just use a Vector of Vectors. So a Vector where each index in the Vector is, itself, a Vector. Same as a list of lists.
Its only called a no-argument constructor if it is a constructor with no arguments. What you posted is a no-argument method. And the purpose of a no-argument method can be almost anything. For example, lets say you wanted to print out a menu to the user.
public void printMenu(){
System.out.println("Type 1 for Whatever");
System.out.println("Type 2 for Whatever Else");
}
Obviously, no-argument methods aren't only for printing menus, they can be used for lots of different things, but that's one example.
I usually do, but this is, in my opinion, a case where the person knows the concepts and just made an accidental error that they couldn't find. (In other words, by pointing out his mistake to him, he will understand why he made it).
I'm not sure what you're asking, so here's two examples.
Animal myAnimal = new Animal(2);
Animal otherAnimal = new Animal(2);
If we call myAnimal.getDifference(otherAnimal), if you recall, the method parameter was simply called 'other'. So every time it says 'other' in the method's code, it will refer to otherAnimal. We could also say
Animal myAnimal = new Animal(2);
Animal other = new Animal(2);
myAnimal.getDifference(other), and it would not make a difference. The only important thing to remember is that whatever is between the () is going to be referred to in the method by 'other'.
It's probably above what you're studying at this point, but once you fully understand that, you might want to look into how Java passes-by-value.
Ahh, stephen beat me to it.
Oh, I found the problem. Change
JButton button = new JButton ("Click ME!!");
to
button = new JButton("Click ME!!");
You can't use "==" as a comparator on Objects. On Objects, "==" will only tell you if the two Objects are at the same memory location, I believe. In any case, it will not compare the two things for equality like it would if you said "does int 1 == int 2?"
edit: I'm looking into this a little more, but I tried it with '==' and it does work, because of how getSource works. I'll run your code and get back to you.
What is the point of a no argument?
public getDifference(Animal other){ int difference = this.height - other.height; return difference;. }
Where is "Animal other" from?
How would you compare the heights of two Animals if you didn't have two Animal Objects?
and for the "this" how would it know which of the 2 it refers too, as it was not stated.
'this' always refers to the calling Object (if the method isn't a constructor. If the method is a constructor, then this refers to the Object you are in the process of creating/modifying). So if you had two Animals called myAnimal and other, and you said other.getDifference(myAnimal), then inside the getDifference method, 'this.height' would refer to other's height.I don't think I should use the this. anyways, since our teacher doesn't like us going ahead and using unlearned code
That's fine. I mentioned it because I'm positive that you will see it over and over again in Java. I doubt your teacher would have a problem with you using it, but it's up to you.
Yeah I understand the topic mainly now, just need to work around the small details that confuse Java.
fghgfdfgh
I managed to delete the only up to date saved copy of an important Java project I had (I know, I know). I have the compiled .class files and I know it's possible to decompile them. Can anyone direct me to any references or anything to help me do this properly? FYI what I'm trying to decompile is the GUI project that Ezzaral and stultske helped me with a while back on these forums. I have an 'intermediate' saved version that is uploaded online, but it would take hours of work to get back to the current version, and more than that I don't want to risk corrupting current data by using different versions.
thanks for any help.
Mark solved threads as solved
Oh, and I have read, but do not understand what, how, or the purpose of a no argument constructor.
What exactly is it? a method containing no body?
No, it is a constructor that had no arguments/parameters. The method can contain whatever body/code you want it to. A no argument constructor is just, for example, if we had a constructor with the method header: public Animal()
yeah, I'll begin writing and practicing these using what I know, but I still need to further understand private, no-argument.
So doing calculations would be something like:
public getDifference (int height){ heightDifference = myAnimal2.height - myAnimal1.height; return heightDifference; }
would that be correct?
You have the right idea. But keep in mind that if you actually wrote that exact code, Java would not know what 'myAnimal2' and 'myAnimal1' are. See my example of how to do it below.
Rewriting your code above so that it would work:
public getDifference(Animal a, Animal b){
int difference = a.height - b.height;
return difference;
}
And rewriting it again, so that it is even better
public getDifference(Animal other){
int difference = this.height - other.height;
return difference;
}
^ Note the 'this' again. 'this' refers to the Animal Object that called the method. If that doesn't make sense, consider the way that you actually would call the getDifference method. You would have some code like this:
Animal myAnimal = new Animal(2);
Animal otherAnimal = new Animal(1);
int theDifference = myAnimal.getDifference(otherAnimal);
System.out.println(theDifference); // Prints "1"
Also, this.whatever is usually not necessary. It is just a way to clarify what you are referring to. For example, consider the confusion that the following code might produce:
public class Animal{
[U][I]int height = 0;[/I][/U]
public int doSomethingPointless(int height){
int temp = [B]height [/B]- 5;
return temp;
}
}
Which height does 'height' (where I bolded) refer to? The parameter (int height), or the instance variable? Obviously, this is confusing. So 'this.' refers to the instance variable (underlined & in italics)
Your first code box, if you put
...new Animal(2); and
...new Animal(2, 4);the second one would automatically acess the one that also contains the int w, as there are 2 values, and skip over the first method right? while as the first one would skip the second method?
Or does the first one just have a w value of 0 as it is default?
Considering the class,
public class Animal{
int height = 0;
int weight = 0;
// ... our methods down here
}
Think of it like this. Every time you construct a new Animal, that Animal initially has a height = 0 and a weight = 0. Then, if you say Animal myAnimal = new Animal(2), what Java does is it looks for the method that matches. So it will look for a method called "Animal" that has one integer as its parameter. It will find this method:
public Animal(int h){
height = h;
}
Then, it will call that method. It will set height to 2, but it will not change weight, since there is no code there to change weight. So now we will have height = 2 and weight = 0.
I would imagine that Puneetkay is correct since this is what I know from experience. But if you want to explicitly delete the file, use the File class.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html
File myFile = new File("fileName.txt");
myFile.delete();
Yes, it seems like you are starting to understand everything. If you had an Animal called myAnimal, myAnimal.height would let you access the height. So if you had the following class
public class Animal{
int height = 0;
int weight = 0;
public Animal(int h){
height = h;
}
public Animal(int h, int w){
height = h;
weight = w;
}
}
And you did the following:
Animal myAnimal1 = new Animal(2);
Animal myAnimal2 = new Animal(2, 4);
myAnimal1 and myAnimal2 would have the same height. However, they would not have the same weight, since myAnimal1 uses a constructor which does not change the Animal's weight, whereas myAnimal2 uses a constructor which does change the weight.
Here are some things you can do w/ the height and weight of the Animals I just created.
//If you run this code, it prints "We have equal heights"
if (myAnimal1.height == myAnimal2.height)
System.out.println("We have equal heights");
//Print myAnimal1's height
System.out.println("Animal's height is " + myAnimal1.height);
As a side note, the two constructors I am writing below do the same exact thing:
public Animal(int h, int w){
height = h;
weight = w;
}
public Animal(int height, int weight){
this.height = height;
this.weight = weight;
}
You should practice writing some simple classes where you make the instance variables private and use setters and getters to access and change the values. An example of an instance variable, in the class we've been talking about, is …
Not really. I could be wrong, but I remember this girl making earlier threads similar to this one. Not that she deserves to be harassed, just ignored.
IE, Animal is now, like an int, or a float, but as what the method Animal states it is?
You were correct in your connection between Animal and int/float/etc. Yes, they are similar in some ways. But note that there are also very important differences. Animal, and all other types (anything that is declared with the word class) are Objects whereas int/float/etc are not Objects and do not have a class declaration. There are more differences than these, but I'm straying from your question. The other statements you made in the same post as this one, i.e. about it being an array, were not correct.
public class Animal{
int height;
[B]public Animal(int h){
height = h;
}[/B]
}
In this example, I created a class called 'Animal'. That means that when I say Animal myAnimal = new Animal(2), I am invoking the method that I bolded in my code. You'll notice that the method I'm invoking, Animal, has one parameter: "int h". So when I say new Animal(2), the Animal method is invoked, and 2 is passed in. This means that what will end up happening is height = 2. So after I say Animal myAnimal = new Animal(2), I have created an Animal Object with a height of 2. If I wanted to create an array of Animals, I would have to use the following code:
Animal[] arrayOfAnimals = new Animal[[B]10[/B]];
There are a couple of other ways to make an array in Java, but that is …
A constructor is a name for a method that 'constructs' an Object, or creates an instance of its class type. The name of a constructor has to be the same of the name as the class it is in (although it can have any parameters). For example, if my class is as follows
public class Animal{
int height = 0;
public Animal(int h){
height = h;
}
}
The method "Animal(int h)" is a constructor. If you say Animal myAnimal = new Animal(2); you are creating an Animal object, also referred to with various other terminology...
I just gave you the most basic description of what a constructor is. If you want to know more specific details then google Java Sun constructor or ask more specific questions here.
Yes, we're definitely agreed that understanding the basics is the most important thing. Otherwise, one wouldn't understand the information the IDE spits out at all, which is why I only half agree with what you said about people who can "only use the IDE". Also, forgive the freepost, just making my previous statement clear - we're agreed on the first and half agreed on the second.
(feel free to erase and apologies if this is clouding the thread)
Have you managed to send the site a request to look up the weather (based on the zip you send it) yet? If not, plain text isn't going to do you any good. So let us know which part you are stuck at.
I think you could also save yourself a lot of the if statements if you used a counter to index the correct part of the array along with modulus and/or division.
> whenever you access a method, it gives you a summary of what the
> method does, as given in the API...so do the online java docs. But in most of the cases we end up with a bunch of CTRL + SPACE programmers who find it too troublesome to even remember the method signatures of the most commonly used methods out there.
As someone who earns from programming, I find such tools to be really useful in boosting ones' productivity and getting the job at hand done faster, it can't be denied that knowing the basics of the language you develop in of prime importance. I am pretty sure none of us would want to hire someone who is completely lost without an IDE; after all, it's a Java developer we are looking for and not just a Eclipse/Netbeans/IntelliJ user.
I don't think that anyone in academics would agree with such a broad statement. Of course, it is important to be knowledgeable without the use of resources - otherwise, you're useless - but knowing how to properly use your resources is probably just as important.
You didn't mention what you want to do with the data once you retrieve it. But you can retrieve any of the digits using theString.charAt(index). You can also use Integer.parseInt(String) once you get that digit, to see if its a 0, a 1, or neither. There might be a performance gain over that with what S.o.S said; if so, I don't know what it is.
George, I think I understood everything you were saying up to here. "I also want to register/unregister message sender/receivers dynamically." What does that mean? Because up until then, it sounded like you simply wanted a generic priority queue, which is not hard to implement yourself, since Java already provides a PriorityQueue class.
I just did a quick google search on your problem and I found the following information that seems like what you're looking for:
"The trick is to pass an array of message that contains both the message and the input components in the call to JOptionPane.showOptionDialog."
Does it have to be a JOptionPane? JOptionPane's are usually supposed to be used to display messages, not get them, I think. They can also display a list of choices and get the user's choice. Here's the Sun tutorial for JOptionPane: http://www.j2ee.me/docs/books/tutorial/uiswing/components/dialog.html
If you're open to using different types of GUIs I can help you make a custom GUI that has multiple text fields where the user can enter text. Or, if you have to use JOptionPane, you'll have to wait and see if this is possible - maybe someone else here knows how to do it. Let me know.
^ Huh?
What S.o.S said is correct, and also, if I'm not mistaken, is what Eclipse and a lot of other IDE's and editors use to 'check' whether or not there is a syntax error (w/ parens and brackets).
In my code? It's not my code. But I did miss that, I thought he didn't post his class for some reason. The Ramen could be to blame :p
And you don't have to use recursion to test whether something is a palindrome or not.
Unless I've gone crazy, the first program you posted was a Bank program, and the second was a Temperature program. So you'll have to clarify which one you want help with and show any progress you've made as well as listing what errors you're getting and what concepts you need help with.
Yes, but that still doesn't guarantee that value will == 0, unless you explicitly set it to be so.
I don't see how giving suggestions is an unfair advantage, as long as nobody is doing his work for him. I can understand if you're unwilling to help him because he hasn't shown any effort (as I am) but if it's an unfair advantage, then any help given on Daniweb is.
First of all you need a class to represent each 'game'. The class would contain the following data:
int correctNumber;
int guessesAllowed;
int guessesLeft;
You might need a few more things. You also need to split each task into methods. For example, prompting the user for their guesses could be one method; generating the random number that you want them to guess could be another method; etc
You can't create Objects of an abstract class. So its impossible to add them to an ArrayList. An abstract class defines methods/data so that any classes which extend it have to implement those methods/data. Read this.
http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html
In addition to what JavaAddict said, you missed my point -
if you create an array of Objects, but do not give it any values, then it will be full of nothing. The way Java and other languages handle this is by initially making each element of the array 'null'. So if you said
BankAccount[] accounts = new BankAccount[10];
BankAccount mine = accounts[9];
It would still be a logical error because mine is now null.
Google 'Timer Java'. If I remember correctly, a similar question to this one was asked a few weeks ago, and the solution is to use the Timer class because it is invoked on the Event Dispatch Thread (and thus won't cause problems w/ your GUI stuff)
Ok, great. That's all I was looking for, hence posing such a specific question. Thanks.
Couldn't you also convert the char to an integer, then compare the two chars? Being careful, of course, for case considerations?