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

Yeah, but as the OP said . .

Hi, I'm a freshman and I just started programing.

The simpler loop helps you understand indexing arrays. The fancier one does not.

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

Jwenting said probably said that because googling "vector arraylist java" returns thousands of helpful results to the exact question the OP asked. Why reiterate a question that has been answered so many times that can be found so easily? And you upping this thread was also unnecessary. Look at the date it was posted.

For example, this article, although outdated, provides enough information to answer the OP's question.

BestJewSinceJC 700 Posting Maven

Best solution IMO: scrap both rep and voting and give mods more power to remove useless and factually incorrect posts (which are the main reason people (should) vote posts down anyway) and posts in violation of the TOS (which apparently can't be removed now for some reason).

Disagreed. The mods here are pretty good, but I disagree with removing factually incorrect posts. Deleting it can actually lead to the person who posted it never knowing the correct information, or other people who have the same misconceptions never clearing those up. But I do agree on your other point about removing completely useless posts. And I also think reputation is useful. I don't have the problem of crushing people's reps, but I can see how Ancient Dragon and others do, so I think the option you guys discussed is a good idea (as long as the default option is to give full rep points, and I don't have to change it every time).

And as far as the up/down voting system goes, I was complaining about it quite a bit before in this forum, but I gave in and started ignoring it. I also agree with others who have said that the negative aspects outweigh the benefits.

BestJewSinceJC 700 Posting Maven

http://beej.us/guide/bgnet/output/html/multipage/index.html

The above is the one my computer networks class used. I don't know how good it is compared to other guides, but it was good enough for me to get my projects working (with a little help from the fine members here :) ).

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

Java Addict is absolutely correct.

From online (would credit source, closed the tab accidentally): "Since Strings are objects, the equals(Object) method will return true if two Strings have the same objects. The == operator will only be true if two String references point to the same underlying String object. Hence two Strings representing the same content will be equal when tested by the equals(Object) method, but will only by equal when tested with the == operator if they are actually the same object."

In summary, if you wanted to test if two People objects were the same person, you would probably consider them the same person if they had the same name, social security number, and birthday. You would therefore need to use the equals() method to make this comparison, since using '==' would tell you if those two Java Objects had the same memory address. Similarly, you would probably consider two Strings that both said "Same thing" to be the same String, however, if you tested this with '==', it would only test to see if those Strings were the same Object... and therefore, resided in the same place in your computer's memory. . not to see if they are logically the same String.

kvprajapati commented: Helpful +7
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

http://www.pcmech.com/article/monitor-your-computers-bandwidth-usage/

Just the first thing I found. Something like that is what you're talking about, right? Since there are pre-existing programs that do what you want, anyone of any experience level can accomplish this task.

BestJewSinceJC 700 Posting Maven

Start like this:

Student[] student = new Student[SIZE];

After you design a Student class similar to the Person class described above. Your teacher might want some sort of hierarchy, such as Student extending Person. Read about inheritance. Read about classes. And read about arrays. Feel free to ask about those concepts here at Daniweb, we will be glad to help you. But do not ask us to tell you how to do your assignment again. Specific and appropriate questions (i.e. you put in the effort) get specific answers.

BestJewSinceJC 700 Posting Maven

two-letter words don't count ;)

Haha. Fair enough. In High School we were forced to take typing class, which I didn't like, so I only typed there with two fingers whenever the teacher wasn't looking. Their typing assessment programs usually said I typed around 30-40 wpm, but I didn't own my own laptop at the time, and I've improved significantly since that changed. I can only imagine the same will be true for the OP if he continues to practice and forgoes the typing class.

BestJewSinceJC 700 Posting Maven

Here is a for loop that can iterate over an array

for (int i = 0; i < array.length; i++){
    //Now add your code in here to access your array etc
}
BestJewSinceJC 700 Posting Maven

I type with two fingers, and I probably type at well over 60 wpm, (over 70 according to some typing thing someone posted here - but who knows how accurate that was). My advice is just to type however you want and to do so more often. Save your money on the typing class.

BestJewSinceJC 700 Posting Maven

This is a very simple algorithm that requires little more than common sense. Just pretend someone is handing you money and that you get to keep the smallest and largest bills. When you're done outlining the steps, turn the process into a flow chart.

It may sound harsh, but if you can't figure this one out, you might want to consider switching your major. It doesn't get any easier.

I doubt the OP is struggling with doing this conceptually. He/she is probably confused about what a flowchart is, as simple as a flowchart is. . that is a different story.

http://en.wikipedia.org/wiki/Flowchart

BestJewSinceJC 700 Posting Maven

What bugs did it solve? Did anything else in your program change? Post your updated code.

Your program might not be working even though you think it is. Simply taking out or fixing one thing can cause another thing to break. Errors can cover other errors, making them look correct. Etc.

BestJewSinceJC 700 Posting Maven

The search option is obviously still missing. The way it is not, is that ok? I have no idea how to implement the search though. I don't know how to do the search.
Help would be relly appreciated.

Create an 'Automobile' class. Your ArrayList should be filled with Automobiles. In the Automobile class, override the equals() method. The equals() method should be designed like so. After you do all of that, searching will be as simple as using the appropriate method listed here. (i.e. contains, indexOf(), whatever else you find).

BestJewSinceJC 700 Posting Maven

Apologies if this has been stated, but I saw something about craigslist:

Do not buy a car on craigslist. If you insist on doing so, at least compare the prices to other similar cars (according to make & model) and make sure the craigslist one isn't outrageously cheaper. And never buy a car without doing so in person. And Toyota and Honda are two of the most reliable manufacturers, neither of which is American.

BestJewSinceJC 700 Posting Maven

Check out my previous comment. I could be wrong (it has happened before :) ) - but either way, I'm going to get to sleep now. Once you check out what I said, reply back if you have any more issues.

BestJewSinceJC 700 Posting Maven

If your "start" Node is null, then your method will never run like you want it to. Try checking to see if start is null simply by doing this:

if (start == null) System.out.println("start node null error");

Furthermore, as far as I can tell, this loop has no effect since you set idx to 'start' before and after the loop.

while(idx!=null){
c++;
idx = idx.next;
}
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

Why? Why not get a computer from a reputable place that actually will give you service and put everything you need into the computer rather that an off-the-shelf this-is-what-we-got solution? And without all that extra crap software, too.

In case of problems, do you get the M$ OS cd's so you can actually reinstall?

Just askin' :icon_wink:

Yeah, when you buy a Dell, they send everything you need with it. And even if they didn't, you can order it from them over the phone or do so online.

BestJewSinceJC 700 Posting Maven

I first ran into Adatapost in the C# section. He was a fairly prominent figure there when I first started (all those long months ago!!) and still keeps up his posts as a mod. I think he's patient and kind to the extreme and truly enjoys helping people learn. He's also encouraging with rep and nice comments!

P.S. Just like with vegaseat, I have yet to figure out what an adatapost is. Is that like a sign post for data to follow? ;)

Huh, I never even knew he posted there, but I stick to Java. I also browse the C forum but almost exclusively to read answers to interesting topics, I hardly venture an answer unless it is something fairly simple. Anyway, I always thought his name just referred to the content of his posts.

BestJewSinceJC 700 Posting Maven

adatapost

When he first joined the site he seemed different in some ways (one being that his English wasn't as good, or didn't seem as good to me). However, he has since become a mod in the Java forum (and perhaps other forums as well?) and has definitely earned my respect. I'm not going to claim that his solutions are always correct or the best, but I don't recall seeing any of his solutions that anyone disagreed with, and he is generally helpful with replying to questions, providing useful information, and enforcing code tags and other rules.

BestJewSinceJC 700 Posting Maven

So you want us to fix something you didn't write for you? No thanks.

BestJewSinceJC 700 Posting Maven

Think about how you're accessing your array. You're going from index 0 to index sales.length in one for loop. In the other for loop, you're going from index 0 to index sales.length. The problem is that you're using these indexes to access the array

totalPerDay[j] += sales[j];

Which is causing it to go out of bounds. In order to help you solve your problem I need to know what you are actually trying to do, because the way you index the array depends on what you want to do with it. And you're doing it wrong, otherwise you wouldn't be going out of bounds, which means you are stepping past the maximum index that you have set aside for your array.

edit: sorry, masijade got to it while I was writing my post apparently.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

What is the error? Give us the error message, usually it includes line numbers and other useful information.

BestJewSinceJC 700 Posting Maven

>>> Aside from stuff like rent-a-coder, you're probably not going to find a part-time job doing C++.
>Does that apply to full time job as well, in your opinion?

Not really. The point was that any serious programming job is unlikely to be part-time. Though concessions can be made if you're going to school at the time, I imagine.

>Seems like all the discussion here is about those in the 98th percentile
This thread seems to me more about weeding out the hopeless cases. The best people look for the best jobs, and the jobs they ignore are left for everyone else. Continue that trend down the chain until even the hopeless cases manage to get a job. It all evens out so that regardless of your level, someone will be willing to hire you.

Narue, I found that "else-if" statement which was implemented using a while loop and a break statement pretty funny. You guys should all check out that link. Haha.

BestJewSinceJC 700 Posting Maven

Complexity should be O(n). You only need to scan through the entire String once. If you get to a point where your current sequence it is no longer in sorter order, start your current counter over, moving to the next character. Then repeat.

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

And neither of you guys think it is fishy that nobody with over 10 posts on this forum cares? But that two people with one post each happen to come in this thread and co-sign? Fooled us.

BestJewSinceJC 700 Posting Maven

WaltP,

On the same token, some of your statements mean nothing. How many taxes I voted for and how many were actually enacted have no relationship. Even if you apply this to the average citizen; who cares? People don't want to be taxed in general, and many people do not realize that taxes are necessary for national infrastructure, defense spending, government programs, etc. That is why every proposed spending point is not listed on questionnaires or voting "booths" (machines, whatever) in the U.S. - because it isn't reasonable.

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

That is odd. Back when I was programming in college, you were not allowed to write any code until the flowcharts and pseudo-code were done. They also had to be approved by the teacher.

No shit. Just like you don't design the plumbing after the house has been built. Or something along those lines. lol.

BestJewSinceJC 700 Posting Maven

I started out with a temp agency here in St Louis in 1986/7. At the time I had zero programming experience, not even college degree. My sole assets were that I was about 43 years old, recently retired US military, bought an Intro to C programming book and cheap computer, then studied that book for a few weeks. I saw an ad in the local newspaper for an entry level job, applied for it, and was hired.

I could be wrong but I suppose there are still a few entry-level jobs like that for us normal-brained folks.

I imagine it was a bit easier at that time than it is now (considering sheer volume of programmers), but that is still no small feat. And as someone who has seen your posts on this site, I'll say that I have never doubted your ability to program. Not that my opinion is relevant on that matter, but I think that many others feel the same. You obviously weren't looking for compliments, but who's to say that some agency couldn't be favorably impressed with X candidate regardless of their education level.