BestJewSinceJC 700 Posting Maven

Okie .. thanks for the answers James, I will work it out and let you know if I am having any problems, thanks for the info BJSJC. ;)

You're welcome, but I don't know how much you got out of that (unless you went on to read other articles on the topic), because I'm finding myself feeling like I know less and less about the topic as I read more. I'll be back to ask questions about it on this forum though (not the definition of mvc, but the application of it), so maybe we can all learn something.

:)

BestJewSinceJC 700 Posting Maven

^ I tried that when I edited his code, it didn't change anything (as far as the problem he mentioned). Good catch though, I forgot to add that to my comments.

edit:

And k2k, I'm not sure if it matters or not, but you didn't add everything to panels. You added your two labels directly to the frame. If I were you though, I would try out some different layout managers. Like I said, I think CardLayout would be a good idea considering you're flipping through different same-sized windows.

BestJewSinceJC 700 Posting Maven

I haven't found out the cause of your problem. . I did look through your code, and there are certainly some things I thought should be changed (minor issues).

1. Why are you adding things explicitly to the JFrame, instead of putting them in a panel, then adding the panel to the JFrame? (I'm referring to the text that shows up when you first start the program). I'm not positive that this is bad practice, but I would do it with a panel.
2. I also think the reason the menu isn't showing up might be that you are adding your items directly to the frame, rather than to a panel. Add a panel to the frame, then add everything else to that panel. . so your AddRecord would be in the panel.

You'd have

JFrame
|
PanelWDesiredLayout
|
AddRecordPanel

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

Actually what smsamrc is asking is to print at the console something like this:

To have 2 as base and 3 to be smaller and to the upper right corner of 2.

Oops. I understand now.

BestJewSinceJC 700 Posting Maven

Yes, read it in as a String and print it out. ?

BestJewSinceJC 700 Posting Maven

Well, post your code. I'll run it and fool with it and try to help you out. Also, I didn't post this yesterday because I don't want to lead you in the wrong direction, but perhaps it has something to do with some of the issues discussed here?

edit:

And this is a guess, but I think JPanels are opaque by default, (see: setOpaque method) whereas JScrollPanes are not. So that would mean that when you add the JPanel, it paints the entire JPanel, covering your menu. But since JScrollPanes are not, this doesn't happen when you add it. Try invoking the JPanels setOpaque(false) method before you add it and see what happens.

set opaque method

BestJewSinceJC 700 Posting Maven

See my post above. .

edit:

No problem, glad I could help. Your code looks good, by the way.

BestJewSinceJC 700 Posting Maven

Ok. I think I see a problem:


E temp = (E)data[top--];
data[top] = null;
return temp;

You set temp to the element at top, then you subtracted one from top, then you set top to null. What you should be doing is setting temp to the element at top, setting top to null, then subtracting one from top. (Which would look like):

E temp = (E)data[top];
data[top--] = null;
return temp;

Ezzaral commented: helpful :) +19
BestJewSinceJC 700 Posting Maven

wait, nevermind. Your code confused me. Your class is a Queue class but you called it 'stack' so I thought it was LIFO. Forget what I said.

BestJewSinceJC 700 Posting Maven

I don't see any problems with your add method. The code in your remove method looks far more complicated than it needs to be. Your 'last' variable already tells you where the last element is (it is at that index last-1) so all you need to do when removing an element is check to see if last > 0 and remove & return the element at the index last-1. Don't forget to do last-- also since you no longer have an element there.

BestJewSinceJC 700 Posting Maven

I'm hardly an expert, but have you tried programmatically "clicking" the menu item again after the JPanel is set visible? That might make it appear on top again. Worth a try anyway, although even if it works, there is probably a better solution. I ran into a similar problem but mine was because I was using netbeans and the panels actually overlapped on each other.

BestJewSinceJC 700 Posting Maven

I took a look but I didn't see anything wrong at first glance. Got tired of looking after a couple minutes though. We aren't really here to debug your code. . most people will not do it at all. You should write tests for each method to make sure they are performing as expected. Figure out the first method that has a problem, then post back here again telling us what method the problem is in, what it is supposed to do, and any other info you have.

BestJewSinceJC 700 Posting Maven

Location start = getStart(), current;

You should check that that line is doing what you want it to.

BestJewSinceJC 700 Posting Maven

When you have GUI applications, they usually should run on the Event Dispatch Thread. The EDT is what James is talking about when he says the Swing thread. Since you are waiting for a connection on the EDT, you are blocking the thread, since a Thread can only do one task at once. (Think of it like this: when you run any old program, the code executes in order, so the later code has to wait for the earlier code to execute). If you read the first page of the link, you'll gain a better understanding of the event dispatch thread. Also, there is a link in there on the first page to "memory consistency errors". I personally think it is interesting, you may want to check that out also, although it is slightly off topic.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Or you could always use google. There are tons of quick tutorials giving you the same information we can offer.

BestJewSinceJC 700 Posting Maven

Huh? Are you saying you want to compare the images to see if they are duplicates? If so, you can do that by comparing pixel by pixel, since a blown up image converts every 1 pixel to 4 pixels or something like that. I don't know much about it, but I "studied" (read: didn't pay attention) to a similar topic in class, so I could point you towards some resources that would be helpful if that is what you're trying to accomplish.

BestJewSinceJC 700 Posting Maven

In your MenuBar class, you never initialized the scrollPane. This will cause problems in your MenuBar constructor, since you are using the scrollPane Object, which was never initialized (created using new JScrollPane). Hope that helps, if not, I can clarify. If you're having problems still once you fix that, point out what you're having problems with (For example, "my method xxx is supposed to do yyy but it isn't doing it and I don't know why") etc.

BestJewSinceJC 700 Posting Maven

That explanation doesn't make sense to me. Try to work on one issue at a time. And tell us what the overall task you're trying to accomplish is so we can help you by telling you what the best way to accomplish that goal is.

BestJewSinceJC 700 Posting Maven

Yeah, no problem. Ezzaral basically handed me the easy solution though. :p Mark the thread as solved. . ? (I haven't solved one in a good while. . lol)

BestJewSinceJC 700 Posting Maven

There is your problem. You can't execute all three because testcircle is the only one with a main method. On top of that, I don't think you can execute more than one class at once with the java command. Just change it to java testcircle

BestJewSinceJC 700 Posting Maven

That is exactly what I'm saying. . you have to use a print statement or a GUI to make it display anything. To read about what Exceptions are, look at the lectures on Exceptions. They are fairly easy to read. http://www.cs.umbc.edu/courses/undergraduate/202/spring09/MiscPages/schedule.shtml

BestJewSinceJC 700 Posting Maven

Well, good luck then. I don't know what half of the methods you used are supposed to be doing. I don't know why you'd want to insert something at the tail of a linked list as part of a multiply method. And I don't know what the split method does, sounds like it splits a String into parts, but I also don't know why you would want to do that. If you explain what each section of that code is doing and how you're attempting to multiply the polys, I'd be glad to assist you further. Or you can wait for someone else who understands whats going on. Completely up to you. Either way, good luck.

BestJewSinceJC 700 Posting Maven

You use Ezzaral's suggestion to store the polynomials in the linked list, using the power as the index, and the coefficient as what is stored at that index. Then you modify my suggestion from above, it would look something like

for (int i = 0; i < firstLinkedList.size(); i++){
for (int j = 0; j < secondLinkedList.size(); j++){
- Multiply i * j. Store the results in a linked list where the index represents the power, and the number stored at that index represents the coefficient. If there is already a coefficient at the index you are trying to store something at, then add it to that number and store it there.
}
}

BestJewSinceJC 700 Posting Maven

Why are you throwing an exception, specifically, an UnsupportedOperationException, for your Animals' move and eat methods? You should be using print statements: System.out.println("A fish eats other fish"); or using the JOptionPane.showMessageDialog method.

BestJewSinceJC 700 Posting Maven

Ok, I see. It looks like you are over complicating it though. If you use a nested for loop, you can go through, multiplying each number, and storing it in an appropriate place.

for (int i = 0; i < firstPolynomialsSize; i++){
for (int j = 0; j < secondPolynomialsSize; j++){
- Multiply i by j. Store the results in an array where the index represents the power, and the number stored at that index represents the coefficient. If there is already a number at the index you are trying to store something at, then add the two coefficients and store it there.
}
}

If this does not make sense, maybe you should try a simple example on paper, following the code I just posted.

BestJewSinceJC 700 Posting Maven

To multiply two polynomials, you need to multiple each part of the first polynomial with each part of the second polynomial. This requires a for loop. And when you multiple polynomials, you need to add their exponents. I don't see you doing either of those things. . ?

BestJewSinceJC 700 Posting Maven

A recursive method calls itself in order to come up with the final answer. Your method is returning count, which does not do what I just said. Your method should have the following parameters: currentIndex (the index the array just checked), count, array (your array). A recursive method also needs a base case to tell it when to stop the recursion. In your case, since you want to go through the whole array, counting the number of times 5 appears, where do you want to stop the recursion? Clearly, you want to stop when you have gone through the entire array.

To help you out, here is the pseudocode, or at least part of it:

count(currentIndex, count, array){
if currentIndex is at the end of the array, return count.
else if the next index has a 5, return count(currentIndex+1, count+1, array)
else, the next index does not have a 5, so return count(currentIndex+1, count, array)
}

It is a little sloppy but that is the general idea. You have to call the method for it to be recursive, and you have to have some mechanism that stops it from calling itself. In this case, when it is at the end of the array, it should stop calling itself, because it has no more indexes to look at.

darkagn commented: Good explanation of recursive calls with example pseudocode +4
BestJewSinceJC 700 Posting Maven

That's because this code

 if (Character.isLowerCase(characters[i]))

               {
               characters[i] = Character.toUpperCase(characters[i]); 
               }  

Converts all of the lower case characters into upper case ones. If you don't want to do that, then remove that code.

BestJewSinceJC 700 Posting Maven

Post your full code, in code tags.

I feel like I say this 100x per day.[CODE=Java]

I feel like I say this 100x per day.

BestJewSinceJC 700 Posting Maven

Try to identify the area of your problem. You can do this by using print statements to verify that your major pieces of code are working correctly. For example, does your code ever get inside of the if statement? Then tell us where your areas of difficulty lie.

Also, post all relevant code, and post that code in code tags, read the sticky if you don't know how to do this. . I read your code but I don't see any errors.[CODE=Java]. I read your code but I don't see any errors.

BestJewSinceJC 700 Posting Maven

No. The String class and the Character class both have toUpperCase methods. If you try to use the String class's toUpperCase method with a Character, it will not work. However, if you use the Character class's toUpperCase method, it will work. You need to understand that the Character class's toUpperCase method is a static method. Therefore, the way that you call the method is Classname.methodName(arguments). In this case, that means Character.toUpperCase(yourCharacterHere). I hope you will read the article I linked you to about static methods.

Note: If you read the documentation for the toUpperCase method, you will notice that it takes an argument of type 'char', which is a primitive type (such as int, double, etc).

BestJewSinceJC 700 Posting Maven

You can easily find out what a static method is on your own. There are plenty of resources available to you that already say anything we can tell you about static methods. Here is one, if it doesn't work for you, use google to find more

http://leepoint.net/notes-java/flow/methods/50static-methods.html

BestJewSinceJC 700 Posting Maven

You could also use the String's toUpperCase as long as you converted the char to a String first. Since charArray is a char, if you did charArray + "", that is now a String in Java. Pass that to the toUpperCase method and it will return an uppercase String version of that letter.

(James' solution is better than that, just telling you that it is possible to do so)

You could also use the ANSI table and add the appropriate amount to the character to convert it to upper case.


edit: I said ANSI, java uses unicode character set though, sorry

BestJewSinceJC 700 Posting Maven

You'll also need to implement ActionListener for your JButton. Then you can get the selected index from in the actionPerformed method. Here's an example
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TableSelectionDemoProject/src/components/TableSelectionDemo.java

BestJewSinceJC 700 Posting Maven

URLs, unless what I've grown up knowing and loving is no longer sacred, point to resources on the interwebzzzz

BestJewSinceJC 700 Posting Maven

With Google.

April Fools!

Read this tutorial, I think it is what you are looking for. And I also think I linked someone to it maybe a day ago. http://java.sun.com/docs/books/tutorial/2d/images/index.html

BestJewSinceJC 700 Posting Maven

An example. . . (You can google Java WAV and a lot more will come up if this one doesn't work for you)
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml

This is probably a difficult read but it seems to have a lot of relevant and useful information.
http://java.sun.com/docs/books/tutorial/sound/sampled-overview.html

Ezzaral commented: Helpful links and a magnanimous spirit. +19
BestJewSinceJC 700 Posting Maven

edit

BestJewSinceJC 700 Posting Maven

Hey, I am not telling you to write the code for me. WTF, I am just asking for help. Its not working thats why I asking you to write your example in the same context. Anyway, don't reply to this thread if you don't want to help.

You are just explaining with complicated words, I've already told you that I am new to Java.

If you don't know something, don't try to act smart, OK !! I am losing my time trying your stupid complicated examples.

You are just a dumb and thanks a lot for your complicated help ... hope someone else will help me and learn to be polite.

It sounded to me like you were asking me to write the code for you. If this wasn't the case, there is no need for you to get upset about it, just clarify what you meant. And obviously, I wanted to help because I responded to this thread. I already know how to do the task you're attempting, and have done the same thing in the past, so it isn't a question of me "not knowing it". And your personal attacks on me are very offensive and uncalled for.

Also, if you don't know what terms such as "parameter" etc mean, you could have asked for clarification or looked them up. If you aren't willing to put in effort to learn, then don't expect your code to work. And if you don't understand the simple terms I used, …

BestJewSinceJC 700 Posting Maven

I have a way I think. Say I needed to take x to the 456th power. using while loops, I could just continuously square the number until I got to x to the 4096th power, and then multiply that by x to the 256th power, which I'd get using recursion), and multiply that by x to the 128th power, and that by x to the 64th power, that by x to the 16th power, and that by x to the 4th power and finally, that by x to the 1st power.

So I'd have x^4096 * x^256 * x^128 * x^64 * x^16 * x^4 * x^1
which equals X^(4096+256+128+64+16+4+1)
which equals x^4565

It'd be tricky I think, and might need some recursion, but this should work, right?

Can anyone think of a faster algorithm?

This may work, but I do not think it has an advantage over the multiply method. You're essentially doing the exact same operations either way, just making them appear different on paper. I'm pretty sure the computer is doing the same thing.

BestJewSinceJC 700 Posting Maven

I'm not going to write the code for you. You already did what I'm talking about once, with the theClient instance. Just do it again.

BestJewSinceJC 700 Posting Maven

You can share Objects among classes through a constructor (or other method) of one class that accepts a parameter of the other class. See the example I already posted.

BestJewSinceJC 700 Posting Maven

It seems like you've done what I suggested. Assuming Class 1 is named Client, and Class 1 has a method called sendData, then you should be fine. But if you want Class 3 to communicate with Class 1 (or Class 2) you will have to share the objects among those classes as well.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
Read through that tutorial, it should be helpful to you. Courtesy of a post by peter budo that I found by searching daniweb.

BestJewSinceJC 700 Posting Maven

If you have an object, you can use methods in that Object's class. So if you used the setup I had above, you could access any instance variables of "whatever" from the Second class.

BestJewSinceJC 700 Posting Maven
public class First{

First thing = new First();
public static void main(String[] args){
Second second = new Second(thing);
}

}

public class Second{

First whatever = null;

public Second(First param){
whatever = param;
}
}

You basically just pass one Object of the first class's type as a parameter to a method in the other class.

BestJewSinceJC 700 Posting Maven

The only way to use that instance is to have a variable of that class's type in the other class. So if you have two classes, class one and class two, and you want to use class one from inside class two, class two has to have a variable of type class one.

BestJewSinceJC 700 Posting Maven

You're using netbeans? It doesn't matter what you're using though, Java works the same regardless. If you're in one class, and you make an instance of that class, a different class will not know it exists. In order for this to happen, you would have to have something like the following:

public class whatever{

whatever oneThing= new whatever();
}

public class anything{
whatever wv = null;
public anything(whatever stuff){
wv = stuff;
}
}

I hope you see what I'm trying to get at here.

BestJewSinceJC 700 Posting Maven

What are you having trouble with. . having the numbers in forwards/normal order, or with multiplying the numbers, or both? The Math.pow method is useful, but I'm not sure how large your numbers are. You should check out the BigInteger class. It has multiplication and exponents for large numbers. http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html