BestJewSinceJC 700 Posting Maven

Delete that method altogether. Your mistake is here:

MyClass mc = MyClass();

Should be

MyClass mc = new MyClass();
BestJewSinceJC 700 Posting Maven

Is that a serious question? People take college courses, high school courses, certification programs, ask work related questions, have their own projects, etc

BestJewSinceJC 700 Posting Maven

For your first answer the printValues method is wrong. You printed out the words "integer1, float1", but what they want you to do is print the values of those variables.

//This is wrong, it prints the words integer1 and float1, not the values.
public void printValues() {
System.out.println("integer1, float1");
}

Your answer to question 2 is correct. Your answer to question 3 is incorrect because you never created a new class called UseQ4. Read this to learn how to create objects.

//You need this
public class UseQ4{
//your code here. You need a main method. You also need to instantiate a new Q4 Object inside of your main method. The way you instantiated the Q4 Object was incorrect.
}
BestJewSinceJC 700 Posting Maven

Change the code in your action performed method to the following:

JOptionPane.showMessageDialog(null, "Adding JPanel");
        ColectionBean cb=new ColectionBean();
        cb.setSize(500,500);
        cb.add(new JLabel("THIS IS THE NEW PANEL YO"));
        cb.setVisible(true);
        this.inColecaoPanel.add(cb);
        cb.revalidate();
        System.out.println("É Visivel? "+cb.isVisible());
        this.inColecaoPanel.setVisible(true);
        this.inColecaoPanel.revalidate();

And when you click the button you will see that your panel shows up, not like you'd want it to, (i.e. parts of it are cut off and it doesn't look pretty) but it does show up. You can fix this by playing with the setPreferredSize methods and you need to read the java sun tutorial on how to use GroupLayout. . it has a lot of helpful ways to design components so that dynamic updates are possible.

jpavao commented: Very good and quick answer +1
BestJewSinceJC 700 Posting Maven

I think you didn't create the executable properly, I get an error when I run it that says "cannot find main class". Something wrong with your manifest file probably. I'll take a look at your source code though.

BestJewSinceJC 700 Posting Maven
public static void main(String[] args)

is different than what you have.

BestJewSinceJC 700 Posting Maven

So you can see inColecaoPanel but you can't see the panel inside of it? Did you try calling inColecaoPanel.revalidate() after you called setVisible on it? Oh, and if you attach your project as a zip file, I'll run it on my machine and try to figure out what is going on.

BestJewSinceJC 700 Posting Maven

The point of the forum is to help people learn. Giving them code can sometimes add to that. Giving them suggestions and guidance and letting them research and find the answers on their own is usually more helpful. Besides, my original post towards you was not complaining about you giving the OP code, it was in response to a post you made that was basically a freepost.

BestJewSinceJC 700 Posting Maven

I see no useful information in your post, only a lame attempt at a mini lecture. It must be very important for you to get that "solved" gold star, right?

My post, was to show that there is indeed output happening with his code with only a single modification. You of all people, should have been smart enough to pick up on that.

Do you read before you post? I told the OP everything he needed to know to solve his problem in post #2 and my other post in this thread. Anyone reading this thread (other than you, apparently) can attest to that. Your response to my post is overboard and childish. And you added nothing to this thread other than insults. I'll leave it at that.

BestJewSinceJC 700 Posting Maven

Why would you read in the user's choice into a variable called "app" but then check to see if a variable called "application" is greater than 20. There is your first mistake right there. Besides, you already know that application = 0 since you just declared it and never changed it.

BestJewSinceJC 700 Posting Maven

I explained to you what I think the problem is. You have two different Objects, a Progression Object and a KeyCards Object. Your code that you gave me had a showKeys method in KeyCards, and another showKeys method inside Progression. When you call the showKeys method in Progression, it does not modify anything on your GUI because your GUI contains a KeyCards Object. You can solve this problem by looking at the modified code I posted for you. I'm not going to fix the whole project for you, that would not be helping you learn. But if you look at my previous post, you will be able to figure out the problem with your code, which as I said, deals with the Progression Object and KeyCards Object being separate and not affecting one another. So import the project I provided you with into Eclipse and take a look.

BestJewSinceJC 700 Posting Maven

^ What? I already told him why his file wasn't printing. Your reply makes no sense. Did you read the previous replies to this thread?

BestJewSinceJC 700 Posting Maven

But in the Integer class in the Java API, the method compareTo() accepts an Integer, not an Object. So isn't that like accepting a Parrot instead of a Bird? Even though the comparable interface specifies compareTo() as accepting type Object, the Integer class uses "public int compareTo(Integer anotherInteger)".

You're right. Except that when the author of your book wrote his piece of code, I'm guessing at that time, the compareTo method was listed as the one found here, which takes an Object. . not an Integer. So your book's author is not really wrong, just out of date. What you're saying is correct.

BestJewSinceJC 700 Posting Maven

edit:

Like I told you in my previous advice, you should exit your while loop at the end of the file, not at a newline. Had you listened to that advice, your program would be working right now. (Hint: there is probably no newline in your file, thus, your while loop never exits).

Btw, your pop is perfectly fine.

BestJewSinceJC 700 Posting Maven

Ok, sorry for so many posts, but I'm only allowed to edit for 30 minutes, which I've exceeded. I fixed your classes so that when you click on the combo box, it updates the text fields with the default text that you had there. So now that works. I'm going to let you struggle with it a little bit more though. Keep in mind my suggestions, particularly the second suggestion in my previous post:

Your Progression Object that you created and your KeyCards Object that you created do not have the same JTextFields. So when you were updating the Progressions' JTextFields, which were not on the GUI, the GUI's JTextFields (which were from the KeyCards Object) were not being updated.

Here is your code with the changes I made to it. The changes I made to it are primary passing the KeyCards Object to your Progression class's showKey method, so look for the method

showKeys(KeyCards kc) //in Progression class
BestJewSinceJC 700 Posting Maven

Ok, I'm noticing a couple of issues.

You only need to instantiate your JTextFields once. In your showKey() method, you are instantiating them over and over again. (i.e. you are saying textField = new JTextField() every time showKey() is called). To remedy this situation, I am moving all the instantiations of your JTextField Objects to a method called initKeys(), and I'm going to make sure that you only call initKeys() once in your code.

Why does your Progression class extend KeyCards? I see that you're calling showKey() from within the Progression class, however, any Progression Object that you created has a different set of text fields (and other variables) than your KeyCards Object does. So the showKey() call from within your Progression class has no affect on your KeyCards Object that you created from within your createAndShowGUI() method in your XMLReaderComboBox class.

BestJewSinceJC 700 Posting Maven

So does the public static void printBirdCall(Parrot p) with bird passed work? Or is it that the integer comparison does not work? Unless there is a clear distinction between the 2 cases, it seems to me that Barron's contradicts itself in saying that the printBirdCall thing will result in an error but that the integer comparison will work.

There is a clear distinction. Whether or not the line of code works depends on whether or not the corresponding method exists and it also depends on the inheritance hierarchy. In the case of passing a Bird Object to a method declared as accepting a Parrot, it will not work, because a Bird does not necessarily have all of the characteristics that a Parrot has (see my earlier example). However, if the same method was declared as accepting a Bird Object, and you said Parrot parrot = new Parrot(), you would still be able to pass it "parrot" and it would work.

The Integer compareTo method follows the same rules. The author's example only worked because the method he was calling was declared as accepting an Object as its argument. Since an Integer is an Object, it should be allowed to be passed in.

BestJewSinceJC 700 Posting Maven

So are you still having problems? If not, mark this as solved. If so, please explain your current problems further.

BestJewSinceJC 700 Posting Maven

I just opened your project and it seems to be more of a "JDOM mess" than a "GUI mess". I have little experience with JDOM, although I do have some. I'll look at your code as promised but if it turns out to be a problem within your JDOM code, I doubt I can help. If it is a problem within any Swing code I'll probably be able to help. Looking into it now..

BestJewSinceJC 700 Posting Maven

You know Java has a premade Stack class already, right? If your teacher is forcing you to make your own, that makes sense (you'll learn a lot more), but otherwise, you might want to use the existing one. Anyway, where you said

System.in.read()

you should be calling one of BufferedReader's methods to read in from the file. Something like

while ((ch = (char)br.read()) != '\n')

Also, you might want to change your code so that instead of quitting when it sees a newline, it quits when it reaches the end of the file.

BestJewSinceJC 700 Posting Maven
for (int i = 0; i < 200; i++) {
patient = (Patient) in.readObject();
}

Why do you need a for loop there? And why a hard-coded for loop at that? And why do you need to test to see if the patient's name is Luke anyway? If you're storing in a file system, all you should be doing is reading all of your data in or writing it all out (unless you only care about Patients named Luke, I guess).

BestJewSinceJC 700 Posting Maven

I tried this and get the following error:
The method compareTo(Integer) in the type Integer is not applicable for the arguments (Object)

Perhaps I am using a different version of java than you (which I really don't think matters in this case). Maybe I am just missing something obvious.

Actually, my apologies, that doesn't work for me either. Which means that the method which I listed earlier does not actually exist in the Integer class.

BestJewSinceJC 700 Posting Maven

The Object class has a compareTo method on it. That is why it works. However I am guessing your Bird class does not have a printBirdCall in it like it should. It is only located in your Parrot class.

All of that is wrong. The Object class has no such method. The compareTo method is from the Comparable interface. And even if his Bird class did have a printBirdCall method, it wouldn't matter. If you notice, he posted the following:

public class BirdStuff
{

    public static void printBirdCall(Parrot p)
    { /* Implementation Not Shown */}

    public static void main(String[] args)
    {
        Bird bird = new Parrot();
        printBirdCall(bird);
    }
}

He called a static method of the class BirdStuff and passed in a Bird, he did not call a method of the Bird class or of the Parrot class. So it doesn't matter what classes contain the "printBirdCall" method.

Anyway, to the OP: consider that if you change the method to the following, it will work.

public static void printBirdCall(Bird p)

Consider the reason why this makes sense. Since Bird is the superclass, and Parrot is a subclass, that means that a Parrot has all of the things that a Bird has... and more. So if the compiler let you pass in a Bird where a Parrot was required (by the method declaration), it would not make any sense. For example, lets say the classes contain the following things:

public class Bird{
int squawk;
}
public …
BestJewSinceJC 700 Posting Maven

My confusion: Isn't one of them wrong??? If intOb calls compareTo() correctly on ob which is of type object, shouldn't the printBirdCall() be called correctly on bird, since it is an instance of Parrot? Is there a distinction to be made between these 2 cases??? Help!!!

No. Look at the method declarations. printBirdCall() is declared as taking one argument of type Parrot. You passed it a Bird, and it does not know that the type of Bird was a Parrot. However, the Integer class has a compareTo method that takes an Object as its argument. You passed it an Object. It was happy, and then underneath the covers, it probably did something like

if (objectYouPassedIt instanceof Integer){
Integer anInt = (Integer)objectYouPassedIt;
}
BestJewSinceJC 700 Posting Maven

Then you will need a WindowListener on the secondary JFrame. In particular, you will need to declare your secondary JFrame's class as "implements WindowListener" and then you will need to implement each of the methods found here. Look at the windowClosed() method in particular; since it gets called when your window is closed, you should be able to get the text from your secondary JFrame, then update the other JFrame's text field using its setText() method.

Hope that helps. Let me know if you have any questions.

BestJewSinceJC 700 Posting Maven

Well, without digging into it thoroughly, I won't be able to help (considering the size of the code), so I'll get back to you tomorrow. If I forget to get back to you, don't hesitate to PM me with a link to this thread (sometimes if I don't see the link, I forget about it). The names of the variables aren't really that important for digging through it, I can always do a search if I see something strange, but it seems like your issue is unrelated to the text field and may be caused by errors with your other components.

Oh, and in the future, for code of this length, it is better to just attach the file, or if someone requests to run your code on their machine. If you see this before I get back tomorrow could you do that?

BestJewSinceJC 700 Posting Maven

Are those JTextFields? If so, setText is the right method.
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html

Are you sure your text fields are properly initialized and added to the panel? Can you post a bit more code showing where this is done? And have you taken similar steps in your code as I have in this example:

package kyle;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class TextFieldTest {

	static JTextField field = new JTextField("text here!!");
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame("Text Field Test");
		JPanel panel = new JPanel();
		panel.add(field);
		frame.add(panel);
		frame.setVisible(true);
		frame.setSize(250,250);
		
		try {
			Thread.currentThread().sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		field.setText("different text now.");
	}

}

(Ignore bad usage of Thread.sleep, etc, that was just a quick example - I'm referring to whether or not you added your panel to your frame, otherwise your text fields won't show to begin with. Can you see your text fields to begin with?)

ceyesuma commented: Incredible! BestJewSinceJC showed me some very impotant programming concepts. +0
BestJewSinceJC 700 Posting Maven
if(tempString.equals(sBuilder))

That line will not work since sBuilder is a String, while tempString is a StringBuilder. They are different types of objects. The equals() method is meant to test if two objects of the same type (i.e. two Strings, not one String and one StringBuilder) are equal. I imagine you are having a similar problem with your other equals statement, but I can't be sure since you didn't post enough code.

BestJewSinceJC 700 Posting Maven

If you're using Scanner's next() method to read in the String, it is probably killing your whitespace. http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html#next%28%29 . Keep in mind that the default delimiter pattern matches whitespace, so your 'tokens' that it refers to in the method documentation is preceded and followed by whitespace. Do you mind posting your code?

Also, you should try this:

yourString.split("[|]");

You should look into java's regular expressions tutorial, but using "|" seems to not work, while what I have above does.

BestJewSinceJC 700 Posting Maven

i request daniweb admin need to more clarify about

what kind of question need to be asked?

list of exception that should not be in thread...

people who are not aware of rules and regulation maybe a newbie asking some questions that violate our rules should be warned first time without affecting their reputation ..

if the doing repeatedly then we should affect them..

cause some guys(newbies) come to daniweb interestingly..

if we disappoint them by putting negative mark at very first attempt of them, they are not like to come here to discuss more..

so any how i would like to warn guys if doing mistakes at their first post ...
other than we should affect them..:idea:

I find this post interesting, considering you're the guy who routinely gives people full code solutions instead of trying to guide them towards the answer with explanations and code segments. That is the last time I will mention it, but just so you know, it annoys me a great deal.

:)

BestJewSinceJC 700 Posting Maven

You will however need the @Override though.

You do not need the @Override. All you need to do to override the equals method is provide this method header (and an implementation) in your class:

public boolean equals(Object obj){
//some implementation goes here
}

Using the @Override tag is helpful, though, because by putting the @Override tag above the method header, the compiler will tell you if you have not properly overridden the method (if you didn't override anything, it gives an error I think).

@OP:

The way you implement the equals method depends on what the properties of your class are. For example, if you had a Square class, you know that any two squares with a side of the same length are the exact same square. So your equals method would simply check to see if the calling square's side is the same length as the square passed in. If they are, then the equals method would return true. Otherwise, it'd return false. For example, here is an implementation of a sample class called Square (that I'm making up right now). Square overrides the equals() method, enabling you to compare two Squares to see if they are equal.

public class Square{
private int sideLength;
//I'm too lazy to show the constructor, pretend a working one is here.

public static void main(String[] args){
Square whatever = new Square(5);
Square another = new Square(5);
boolean equalSquares = whatever.equals(another);
}


public boolean equals(Object obj){
if (this == obj) …
BestJewSinceJC 700 Posting Maven

If you are looking for suggestions on how to read from the file (and haven't already settled on an option), keep in mind that there are many options out there. I recommend using Scanner. You can create a File object and feed it to the Scanner Object, then use Scanner's methods to read from the File. Quick example for you:

File f = new File("c:/file/pathname");
Scanner readFromFile = new Scanner(f);
String element = readFromFile.next();

go read the scanner documentation on google to find out how to use its methods.

BestJewSinceJC 700 Posting Maven

You can get a simple definition from google.
And you can practice programs in a text editor, assuming you also have a compiler. Download eclipse if this is too much for you to handle.

BestJewSinceJC 700 Posting Maven

What kind of Objects are in your list? Are they Strings? if so, contains should work fine, if they are custom made Objects, you will need to override the equals() method of the Object class. You can look into how to do this properly on google; it is fairly simple.

BestJewSinceJC 700 Posting Maven

What don't you understand about those topics that Java Sun's articles can't answer? I'm not going to type you a paper about abstract classes and neither is anyone here, since the information is readily available. Ask a specific question.

BestJewSinceJC 700 Posting Maven

Well, where is your code to find the quadrant? You mentioned that you already wrote it, but you did not post it. Personally, I would just drop that piece of code into the Test2 class you created (or whatever your main class is). You could also put it in your Circle class, though. Since what quadrant you are in has nothing to do with the point itself (it has to do with where the point lies relative to the Circle's center, which is information the Point should not necessarily know about, I wouldn't put it in the Point class, though). However, programmatically speaking, you could put it anywhere you want, and still end up with a functioning program. I'd just personally put it in the main driver class, Test2, (aside of creating an interface that defines the quadrant method and forcing Circle to implement that interface, which really, would be better).

Anyway, sorry for going on a ramble that is probably confusing. If you attempt to put your quadrant method in your main class and get it working, post any problems you have while doing so, and I will help.

BestJewSinceJC 700 Posting Maven

If you want help doing it by using a HashMap you'll have to wait for jwenting. I don't understand why a HashMap would be useful for your purposes at all. It seems to be redundant to me, jwenting will have to explain why he suggested that (he may have had good reason, I just don't see it if there is one). And I already told you in my previous post how to do it using your current ArrayList. Simply put the code I provided in a nested for loop, and count the number of times you see each item, and you are done. You hardly have to do anything.

BestJewSinceJC 700 Posting Maven

I have to disagree with jwenting here. If you are already using an ArrayList then why use an additional data type that doesn't even help you in any way?

Do the following:

1. Write a for loop that iterates over your entire array.
2. For each element in the array, test if it is equal to the thing you want to compare it to (your word) using the equals method. *
3. If they are equal, increment a count.

* Since you have a String inside of a Word Object, the way you'd use the equals() method is as follows:

String currentWord = arrayWords.get(i).getWhatWord();
if (currentWord.equals(wordYourLookingFor)){
//do stuff
}

Also, you seem to be confused, because your variable is named whatWord. In one case, you want to search for a particular word to see how many times its in the array. But why don't you just made your ArrayList an ArrayList of Strings instead of one of Words?

BestJewSinceJC 700 Posting Maven

You can only have one class in each .java file, and the classname must be the same as whatever is before the .java. Does that answer your question?

BestJewSinceJC 700 Posting Maven

You can't use spaces. If you want to name your variable total of cars you simply cannot do that, so use total_of_cars instead. So yes... using invalid syntax is a sure way to cause errors.

Also, the number of errors you get does not necessarily matter. In other words, you could be getting 15 errors, change something, then get one... but that does not mean that your code is better or that you are on the right track. If you pay attention to your errors and fix the earliest errors first, you will be doing things right, even if after you make the fix, it says there are more errors. You need to read the errors, understand what they say (and if you don't, look them up on google or ask about what the error means here). Then fix them and if more show up, you'll still be comfortable with knowing that what you did was correct, and the error you just fixed was hiding more serious errors. Think of it as a good thing.

BestJewSinceJC 700 Posting Maven

Post a new thread for a different topic. If the question you asked in here was answered, you should mark the thread as solved with the blue link at the bottom of the thread.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

But how I gona to make sure every number from 1 to 8 are come out in a pairs?

You would just use the method randomInt twice to get a pair. If you mean that you wouldn't want a duplicate value in your pair, then you would keep calling it until you didn't have two of the same values in your pair.

BestJewSinceJC 700 Posting Maven

To make the components fit the entire screen, you could programmatically intercept the user's 'maximize' action (using WindowListener). Then, when the user hits maximize, you can use this technique to get the screen size. Then set the size on the JFrame using setSize to the size that you just got using the Toolkit class (as seen in the link). You might have to play around a bit with setting the JFrame's size, I don't remember exactly but you might need to call revalidate() on the JFrame after doing so, or resizing the JPanel might do it as well. I honestly don't remember but try each of those things, hopefully my suggestion about how to get the screen size and using WindowListener is helpful. If you have any more questions don't hesitate

BestJewSinceJC 700 Posting Maven

Why do you need a StringSelection Object? You should just need the String, i.e. the one that is stored in your variable called 'selection'.

Btw, the error is that you're using PrintWriter's "print" method, and you are passing it a StringSelection Object. But if you look at the class documentation for PrintWriter, no such method exists. However, PrintWriter does have a method that takes a String, so you should get rid of the StringSelection variable and do:

pr.print(selection);

http://java.sun.com/j2se/1.4.2/docs/api/java/io/PrintWriter.html
^ Here is the PrintWriter javadoc, take a look. No "print" method exists that takes a StringSelection Object as a param.

BestJewSinceJC 700 Posting Maven

Combine the path that JFileChooser undoubtedly returns with this: http://forums.sun.com/thread.jspa?threadID=760337

There might be more current solutions available, and in fact I wrote the exact program you're describing myself, but since my program is on my older machine... you're out of luck there.

BestJewSinceJC 700 Posting Maven

The folks at the NSA will pick your super secret password in less than a second. So, pick something simple you can easily type and remember in the hope that it is safe from the boss or your underage sister.

Really, how? Because the NSA might have faster computers and similarly capable algorithms, or even more advanced, than anyone else... but mathematics still applies to them and if I use a sufficiently long password they are still never going to figure it out without seizing my computer or intercepting it on the interwebs. Not that I know anything worth knowing, I'm just saying, I call BS on you.

BestJewSinceJC 700 Posting Maven

No problem, glad you got it working, mark the thread as solved.

BestJewSinceJC 700 Posting Maven

Did you even read about modulus? If 100 % yourCents > 50 then you would round up. Otherwise, your value would stay the same. This is because an int value "truncates", so when you previously did

int dollars = cents/100;

it automatically "rounds down" by default (everything is cut off except the integer value, so if you had 1.2 it would end up as 1, and if you had 1.9 it would still be 1). Again, modulus gives you the remainder of division. So if you don't get it then look at some examples online, otherwise, think about what a remainder is.

BestJewSinceJC 700 Posting Maven

Use division by 100 in combination with the 'int' primitive type to see how many dollars you have. For example,

int dollars = cents/100;

No matter what (int) value you have for cents, at the end of that operation, dollars will be an integer, so it will have the exact amount of dollars. You could have up to 99 cents left over, so you can use the % operator to figure out what your remainder is. I don't know what you mean by "round to the nearest cent", did you mean "round to the nearest dollar"?

modulus: http://en.wikipedia.org/wiki/Modulo_operation