BestJewSinceJC 700 Posting Maven

@OP ignore this, I am asking a question relevant to this thread rather than giving you advice here. .

Searching each generated word with a long list of existing words (which might be in thousands) is itself a time consuming task, but you can have the dictionary words put into an ArrayList and then compare each generated word using the contains() method of that class, so I guess this could be much faster than iterating over the words.

Don't you have a dictionary stored in alphabetical order? You don't need to compare anything to every possible word, just check alphabetically to see if it is there period. Right?

VernonDozier commented: Yes, the fact that it is an ordered list will significantly cut down the search time. +15
BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

You both do realize that we can't access area 51 right?

They're aware. If it's anything like most sites, not a whole lot goes on in the employees only area/mod lounge/whatever its called anyway. (Although the site I adminned only has 100,000 members and this one has 5x that, so I'd imagine this one has a larger staff).

BestJewSinceJC 700 Posting Maven

I've never heard of a program being "ok" when an Exception is thrown and not caught. That error that you got means you tried to access an array at the index "-1", but "-1" isn't a valid array index, so that can never work. If you posted your code in Java code tags like you're supposed to I'd track it down for you, but since you didn't... meh.

** A little while later, when you still did not post your code in Java code tags **

no one?

...

You should read the thread stickied at the top of this forum that explains how to post in Java code tags. Its basically for the first part, then leave the second one the same.[CODE=Java] for the first part, then leave the second one the same.

BestJewSinceJC 700 Posting Maven

Der_Kaiser, if you post your code, I'll also take a look at it. But it's just as James says - once you succeed in connecting the same Server to two different Clients, it is only a matter of anytime you receive a message from the first Client, you use the Server to send that message to the second Client.

BestJewSinceJC 700 Posting Maven

You can't test a piece of code you wrote? And your professor told you not to test it? Hmm. And if you use Eclipse or netbeans, they will create a package for you quite easily. If you need instructions on how to do it in either of those IDEs, I can help you out, just mention what you are using.

BestJewSinceJC 700 Posting Maven

All the links Vernon pointed you towards are Timer related, it seems like. His may be a better solution than what I'll show you, but there is another way to do it pretty easily:

Use Thread.sleep(milliSeconds);
Then call whatever method it is you wanted to run every five seconds. You can do this in a while loop, and one simple way you could exit the while loop is with a boolean that changes to false when you want to stop calling the method.

BestJewSinceJC 700 Posting Maven

You can mark the thread as solved by clicking the link at the bottom of the thread that says "mark as solved". It should be a blue link underneath the very last post, next to the yellow button that says 'Reply to Thread'. Basically, it's just a way for the person who originally created the thread to acknowledge everyone who posted in it. It's also helpful because then people will know the thread is solved. If you can't find it though, or if for some reason it isn't there, don't worry about it, its no big deal. To me, its cool just to know that I was able to help someone solve their problem and learn more programming in the process

:)

BestJewSinceJC 700 Posting Maven

I've never heard of a program being "ok" when an Exception is thrown and not caught. That error that you got means you tried to access an array at the index "-1", but "-1" isn't a valid array index, so that can never work. If you posted your code in Java code tags like you're supposed to I'd track it down for you, but since you didn't... meh.

BestJewSinceJC 700 Posting Maven

You should also consider marking your threads as solved when you consider them solved. IMHO its kind of rude to repeatedly get help and not bother saying thank you by marking as solved.

BestJewSinceJC 700 Posting Maven

Without looking at your code, (gotta be somewhere soon) I'd recommend that you use compareTo to compare the two Dates to each other. If you aren't using the Date class to store your dates, look at the compareTo method for whatever class you're using

BestJewSinceJC 700 Posting Maven

How about you show us your code. Because I'm almost positive that calling setVisible on a JButton will work, so your code must be setting it to visible again after you set it to "invisible".

BestJewSinceJC 700 Posting Maven

You have a while loop that does while (noOfRentUnits is 0). But you never set noOfRentUnits to anything other than 0. Furthermore, you said profit = total rent - maintenance expense. But you defined total rent as noOfRentUnits * whatever, and you defined maintenance expense as noOfRentUnits * whatever. Both total rent and maintenance expense will be 0 (according to the equations you have), therefore, profit will also be 0. If profit is 0, and maxprofit is 0, then (this is referring to your if statement) maxprofit is NOT < profit. So basically, you're just repeatedly going through the while loop, but it isn't printing anything because you never set noOfRentUnits to a value, and the if statement never gets executed.

I'm posting the code that I explained above so it will be more clear to you what I'm talking about:

double noOfrentUnits = 0;
	 while(noOfrentUnits==0){
		totalrent=adjustedrentperapt*noOfrentUnits;
		maintanenceExpense=noOfrentUnits*mApts;
		profit=totalrent-maintanenceExpense;
			if(maxprofit<profit){
			//blah blah blah
			}
	 }
	}
}

As you can see from my explanation above, and from the code segment, it doesn't appear that noOfRentUnits is being set properly, and therefore, all the other equations seem to be wrong, causing the while loop to continuously be true, and the if statement to never get called.

BestJewSinceJC 700 Posting Maven

Make a class that extends JApplet. And follow this tutorial to make tabs.

BestJewSinceJC 700 Posting Maven

Save the sentence that they type in into a String, lets call the String mySentence. Then use

javax.swing.JOptionPane.showMessageDialog(null, mySentence);

and it will display your string in a window.

BestJewSinceJC 700 Posting Maven

You're in the wrong forum. And generally, a for loop is better for iteration than a while loop is if you know what values you want to iterate over.

BestJewSinceJC 700 Posting Maven

You can import the class where "InterruptedExeption" is located. You're getting the error "cannot find symbol, class InterruptedExeption" because the compiler does not know what that class is. It doesn't know because you have not imported the resources. And "InterruptedExeption" is obviously a class you created, because you spelled Exception incorrectly. . so find what package it is in and put import packageName.*; at the top of the file that's giving you the error.

BestJewSinceJC 700 Posting Maven

for(i = a; i >= 0; i--) // move all the integers by one
b[i+1] = b;


You are getting your error because b = a, (you declared the array b as being size a), and you're setting i to a also. So "i + 1" is greater than the size of b.

(i + 1 is a bigger index than b can hold)

BestJewSinceJC 700 Posting Maven

As hard as I tried, I couldn't find anywhere where you told us where the problem is. Since we can't read your mind this might be useful information.

BestJewSinceJC 700 Posting Maven

Ok, I got you now. I demonstrated my project earlier today and everything worked perfectly, btw. But I just implemented what you said and it works also, so it's probably preferable considering it's only one line of code & that's the standard.

BestJewSinceJC 700 Posting Maven

Thanks for the help guys. +rep for dealing with my questions :)

And it is almost solved at this point, the rectangles are moving around properly and I'm setting "matched" teams to white, unmatched to blue, which is also working correctly. Thanks again.

BestJewSinceJC 700 Posting Maven

If you consider that the component generally starts with a cleared surface of the background color, it's often. .

True, it did start out like that, but what is the relevance of that? I'm just moving rectangles around, but when I move the rectangle, the old ones were duplicating because the old ones never got 'erased'. I fixed that problem by using clearRect

BestJewSinceJC 700 Posting Maven

Is using (in the paint method) g.clearRect() the correct way to clear the screen? It's working but I don't know if there is a better way. . google says it is supposed to clear automatically when update is called but that doesn't seem to happen.

BestJewSinceJC 700 Posting Maven

Hmm... been working on this for awhile, I'm trying to code a method that will tell me whether two of the rectangles are within 25 pixels of each other. Distance formula will not work because there are (4 sides per rectangle)^2 = 16 different ways they could be that close to each other. Is there any easier way?

BestJewSinceJC 700 Posting Maven

In the same vein you are already discussing, keep in mind that you don't have to code all of the coordinate stuff yourself either. You can make a small wrapper to manage that glyph that just contains the other objects you need to work with

class TeamGlyph {
  private Team team;
  private Rectangle2D glyph;
  // etc
}

and you can forward to any of those methods as needed.

I have no idea what that means, unless you're saying that I should make a class that contains the rectangle and the team, and use that to move around etc. But I don't see how that would save me any time or how it has an advantage over what I'm currently doing, which is having a rectangle class w/ coordinates & the team that should be displayed inside of it.

oh, and Vernon, I figured it out already, sorry, should have updated this post more quickly. I'm just using modulus to decide when to reset the x coordinate, and incrementing x and y while drawing the rectangles.

BestJewSinceJC 700 Posting Maven

All I need is a JFrame filled with boxes. To start with, the boxes can be in any place in the JFrame. Then the user can move them wherever, and if they are put next to each other, it should say versus. How can I calculate initial positions (to put the boxes in) so that I'll be able to see all of the boxes??

edit: not sure if that made sense. But all I'm doing is putting the boxes in certain spots in the frame. Then if they are moved next to each other by the user, the word versus should appear.

BestJewSinceJC 700 Posting Maven

Thats what I just said lol. A team name is, of course, a String. I guess I'll start trying to implement this and hope that it is the right way to do it

BestJewSinceJC 700 Posting Maven

I have a list of teams, it can be any length. Now, for each team, I want to create a 2D box that says the team's name in the box. And I want to match these teams up against each other. So basically I want to be able to drag these boxes around, and if I drop them next to each other, I want it to say "Versus" between the two boxes. I'm pressed for time here as I somehow managed to finish my project, then realize I'd left out a requirement. So the easiest solution is preferred even if it isn't the most elegant. Here is what I'm thinking, if anybody has better ideas please suggest:

1. Make a Box class that represents a Box - instance variables would just be it's x, y coordinates and the Team name that is supposed to show up in the Box.
2. Make an ArrayList of boxes.
3. If the mouse is pressed on a certain window (the one where the boxes are), call the repaint method while the mouse is held down.
4. In the repaint method, go through the ArrayList of boxes, checking to see if the coordinates where the mouse current is are the coordinates of any of the boxes. If so, set the Box's coordinates to wherever the mouse currently is, and redraw the box.
5. I'd also have some method that checks the distance between the boxes after each repaint, and if …

BestJewSinceJC 700 Posting Maven

Lol. Excellent link.

BestJewSinceJC 700 Posting Maven

Actually I haven't ever practiced Judaism, though I don't care to explain the reason to you. I couldn't care in the slightest whether you are arabian or not, and even if I was a practicing Jew, I still wouldn't. Anyway, I finally followed the suggestion I was given on this site to decompile my own source code - since I was foolish enough to reformat my hard drive and I lost it - and what happened was that when I decompiled it, the code looks almost the same as when I wrote it. Unlike the code you posted, which looks like it might have gone through some sort of obfuscation technique. I'm no expert, and that might be incorrect, just saying. And lastly, I'm hopeful that nobody else will waste your time by replying to this thread.

BestJewSinceJC 700 Posting Maven

He didn't say it was impossible, he said if they wanted you to do it, they would have made the code available to begin with. It is possible for me to steal my neighbor's bike because they leave it outside unchained, but I think they would prefer to keep it.

BestJewSinceJC 700 Posting Maven

public double getRestockingFee() // calculate restocking fee
{
return super.getValue() * .05;
}

I'm personally very busy right now, so i apologize if you knew this already, but you are calling the method from your parent class when you use super.getValue() . . not the method from the class you are in. I just don't see a reason why you'd want to do that, considering you overrode the getValue method, is why I even mention it.

wedunnit commented: Great explanations and help! Problem solved! +1
BestJewSinceJC 700 Posting Maven

Putting text at the end of an existing file

^ I'm pretty sure using FileWriter with the constructor that has "append" as one of the arguments will allow you to write to a file without deleting its contents first. To use FileWriter:

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
The example of PrintWriter can be found here.

I'm going to assume you can take it from here, but if you need any more help, feel free to ask.

BestJewSinceJC 700 Posting Maven

Read the forum rules. We only give homework help to those who show effort. Ask specific questions about problems you are having with your code and you will get help. Otherwise, you will not.

BestJewSinceJC 700 Posting Maven

edit: sorry, I thought you were adding multiple things to W/N, but you were adding them to different panels. In any case, post the updated code you have and I'll take a look at it and run it on my computer if necessary.

BestJewSinceJC 700 Posting Maven

That's because scanToken = new Scanner(line); creates a new Scanner object based on the String, line, that you passed as the argument. Obviously, since line is a String, it is not an integer, and trying to read ints from it will not succeed. The first declaration of Scanner that you did Scanner scan = new Scanner(new File("Museum_Duguay.txt")); was the correct way to do it. Now all you need to do is use the nextInt() method to get the Integers from that file.

VernonDozier commented: I haven't given you rep in a while and you've had a lot of good posts lately. :) +15
BestJewSinceJC 700 Posting Maven

Still no idea what you're talking about. Maybe this will help. Maybe not. http://java.sun.com/docs/books/tutorial/uiswing/components/toolbar.html

BestJewSinceJC 700 Posting Maven

If you could read the forum rules by tonight, I'd appreciate it, unless you think someone is going to do your code for you.

http://www.daniweb.com/forums/announcement9-2.html

Salem commented: Damn straight. +30
BestJewSinceJC 700 Posting Maven

Yes but the DOWN key only wil make it move to the next line. The ENTER key is not supposed to make it move to next line in the textarea right? My problem is that when i press ENTER, the text in textarea move to lblDisplay but the cursor in textarea moves to next line after ENTER. How can i fix that?

I just told you. Use the setCaretPosition method. I'm pretty sure if you get the length of the text that is in the text field, then set the caret position to be at that length, then it will be sitting after the last character that the user typed. I've never used the method, but hey.. you're asking for solutions so try stuff out when it's suggested. The reason that typing enter is jumping down a line is pretty obvious. . that's what the enter key does.

BestJewSinceJC 700 Posting Maven
if (iStream.close() {
    // print out the results here.
        System.out.print("Enter a fname: ");
        System.out.print("Enter a fname: ");
        System.out.print("Enter a fname: ");
        System.out.print("Enter a fname: ");
        System.out.print("Enter a fname: ");
        System.out.print("Enter your vote (0-4): ");
    }
}

First of all you have a syntax error because there is no closing paren to match the first opening one. Second of all that piece of code just makes no sense.

BestJewSinceJC 700 Posting Maven

As hard as I searched, I did not see a question mark anywhere, leading me to believe you didn't ask one.

BestJewSinceJC 700 Posting Maven

If you want things to show up in a grid then use GridLayout. I'm not saying its impossible to do otherwise but why make your job harder than it needs to be.

BestJewSinceJC 700 Posting Maven

Implement ActionListener. In your actionPerformed method, write a for loop to set each element of the array to null.
http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

BestJewSinceJC 700 Posting Maven

http://lists.apple.com/archives/java-dev/2003/Aug/msg00683.html

I'm not sure how helpful that reference is, but there are hundreds of answers to this question on the web. And on daniweb there are quite a few as well.

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

Yes, it is. While you were posting, I was editing with a code example so that you understand how it works, so go check it out. & If you don't get it, don't hesitate to ask any more questions.

BestJewSinceJC 700 Posting Maven

It should say power = po; in the Lamp(boolean) constructor. That sets the power to whatever value (true or false) that was passed into the constructor. Consider this example:

public class ExampleClass{
boolean something = false;

public ExampleClass(boolean value){
     something = value;
}

public static void main(String[] args){
     new ExampleClass(true);
}

}

^ The example above will work, because what's on the left side of the "=" sign gets it's value set to whatever is on the right of the "=" sign. So if the constructor was

public ExampleClass(boolean value){
     value = something;
}

It would just set value (the parameter of the constructor), to whatever something was. So since something = false (where it says boolean something = false), we'd be setting value to false, which is not what we want to do.

BestJewSinceJC 700 Posting Maven

"however should i do this seperate from the mouselistener on the component itself??"

I might be misinterpreting what you said, but if not, you can define an inner class that implements MouseListener, then add a mouse listener of that inner class type to the component. http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html?page=2

edit: as for your latest post, unless your 2D.Double class extends Component or JComponent (or any other class that has the addMouseListener method), you won't be able to use that method with it.

BestJewSinceJC 700 Posting Maven

Yes, I see what you're saying. I initially missed the semantics. Thanks for clearing that up.

BestJewSinceJC 700 Posting Maven

Aren't "adding the books" to the database and "storing the books to the database" the same exact thing? You said them as if they were different. And we don't do chats and stuff like that, keep it on the site.