Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Um, okay, so you learned three things that do not work. Congratulations?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So... you have or have not bothered to look for any examples? You just want someone to write this for you?

What have you tried yourself? Post code. Post specific questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, enough of this. If the thread can't get back on topic it will be closed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Duplicate thread. Closing this one. Please direct all further discussion here:
http://www.daniweb.com/forums/showthread.php?t=364938

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Great, so what is your question? Specifically, not just a dump of the assignment.

From the site rules:
Do provide evidence of having done some work yourself if posting questions from schoolwork assignments.

Post your code, post error messages, ask about specific things you are having trouble with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

BigDecimal not work for you?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you bothered to search at all on your own? I did and found a ton of examples immediately.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I recommended that you move the table creation code into initUI, not all of the database and model code. Create only your UI components in initUI(). Do not create your table model there. The entire point is to create the UI components only once.

In your action listener, create or update your table model. The model will initially be null, so you create it the first time a selection is made. If the model is not null, simply call setQuery() with the new query string.

Do NOT re-create your entire UI just because they selected a different value to query.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you could use a Set of 1-9 and remove each entry as you encounter it. The remove() method returns a boolean to indicate if the element was in the set, so invalid numbers or repeats would be detected easily and you would also be able to verify that you had all 1-9 if the set is empty.

Set<Integer> s = new HashSet<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9));
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I already said, it will not be deleted unless the post is in violation of the rules and I do not see any reason to do so in this case.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Marking this solved. I think the OP has found an answer by now.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your updated code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Posts can be edited within 30 minutes of submission. After that, only a moderator of administrator can edit the post. Posts will only be deleted if they are in violation of the site rules.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I was also going to suggest something similar to what James mentioned above originally, but I like that the ClientProperty approach would allow for a single listener for all labels and the property is easier to change at run time if the array position were to change.

You could swap a custom listener object with a new one if necessary, but changing the client property seems easier and cleaner than digging out the listener and replacing it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

From that other answer

You could use the ClientProperty associated with each JComponent to save any info about a component you want, like its position in an array. See the put... and get... methods.

Adding to that a bit: you can create a single listener instance that uses the getSource() method to get the label that was clicked, cast it to JLabel and get the value of that property. Add the listener to each label as you create it in your loop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would recommend moving the table creation code out of conn() into your initUI() method.

Your action listener for the combo box then needs to initialize the table model if it is null or setQuery() with the new query string if the model has already been created.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are correct that they are adding a new JTable every time, but the solution is not to remove those tables before adding the new one. The solution is to keep one JTable.

There is absolutely no need to create a new table just to update the data. The data is the model's responsibility and that is all that needs to change here. There is even a method to change the query without creating a new ResultSetTableModel, so it's simply a matter of calling that method on the existing model instance with a new query string.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No need to remove or create new JTables at all. Change the data that is within the model instead.

It looks like you can call setQuery() on your ResultSetTableModel to query a new set of data. If you maintain a single instance of that model, you can just update it's query when your combobox selection changes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You've been trying over and over, but haven't made changes? How do you figure that is going to work out?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> I don't think I said it enough.
I think you've said it plenty and you're blatantly ignoring what you've been told. The code is a wreck and you are going to have to re-write it if you want it to work at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look up the substring() method of the String class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps JToggleButton will work for you. You can set separate images for icon, selected icon, disabled icon, etc.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I agree with Norm, you should start a new method from scratch.

Start with your loop. You know you need a certain number of letters. It doesn't matter what they are, just how many. So make that your loop condition.

Then decide what you need to do with the input letter. If you want to keep them, put them in an array. There are functions in the string class that can make things upper or lower case, so think about how that can be used to make your comparisons easier. You shouldn't have to hard-code every one of your letter checks. Use your array.


That should give you some things to work on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> I don't have that much time on my hands...

That's unfortunate, because you still have a lot of work left on this.

Can you answer the question I posed above?

Can you explain how this will ever allow you to enter any more than one letter out of the three you're expecting?

while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
{
key = c.getChar();

This code is just not workable and you really need to take NormR1's advice and step back to a simpler case and work from there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, why not just put a boolean intersects(Ball) method on the ball class itself and check for intersection with another ball that is passed as a parameter to the method?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You're checking for intersection outside both of your loops - which means they are essentially doing nothing except adding garbage collection overhead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Too impatient to wait longer than 4 minutes for an answer on a forum? Perhaps you need to pay a tutor.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll have to figure out which variable you're accessing in that method is null and why. The code that you provided is not enough to answer that question. Put in some debug println() statements to check the values of those array elements prior to that method call to isMatch().

Edit: bleh sorry, cross-posted with Norm. :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would also think really carefully about what you think this line is doing for you

else if(JAVA[0] == 'j' && JAVA[1] == 'a' && JAVA[2] == 'v')
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Welcome, Adam!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Welcome back :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, as Emily notes, we have a forum specifically for that. I'll move this thread over there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Maps are data structures that maintain key to value pair mappings. They are extremely powerful and flexible structures.
http://download.oracle.com/javase/tutorial/collections/interfaces/map.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just need to subdivide the period of your function over a certain number of pixels and build a Path2D from the (x,y) value pairs.

Here are some fragments of pseudocode to get you started:

periodValueOfPixel = x/graphWidth*periodOfFunction

Looping over an x range you calc

y = Math.sin(periodValueOfPixel)*graphHeight

and connect your path to the next point

path.lineTo(x,y)

When your path is complete use Graphics2D.draw(Shape) to render it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's just constructing a string "ipAddress" from the bytes in the packet using this String constructor: String(byte[] bytes, int offset, int length)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Is there really no way do to this in an object-oriented fashion?
An action map as I mentioned above

class SomeAction{
  public execute(){}
}

mapped to strings or an enum or he could consider a state pattern.

More information about the specifics of the problem would definitely help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> You dont need to help if you dont want to ..
Or perhaps I could just delete the post altogether and issue a warning for violating the Keep It Organized rule:

Do provide evidence of having done some work yourself if posting questions from schoolwork assignments

If you want help here, demonstrate some effort. Don't just post assignments and expect others to give you the answers.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No one is going to take your quiz or complete your homework for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not sure what is being done that would require runtime selection between 25 different methods, but perhaps a command pattern inner class implementation for the actions and a hashmap to map them to your strings might work out.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This was another site that had a lot of info online: http://whyquit.com/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> You might not have intended it, but the statement I quoted implies that nicotine usage simply is addiction
In the vast majority of cases, it is. I'm not speaking of the people who have perhaps 3 cigarettes a year at a party or a cigar once a month on poker night. I'm talking about semi-regular use, such as at least weekly.

> you give addicts an easy choice: stay addicted, because you'll never make it cold turkey.
I am making the case that eventually you have to stop and face the withdrawal and I am speaking solely of nicotine - not heroin or alcohol, which have far greater medically significant physical effects from withdrawal. "Cold turkey" from nicotine is nowhere in the same ballpark of detox. I would never suggest you approach them the same way.

I do get what you're saying, but my point is that your body will remain addicted until you get off the nicotine entirely. It doesn't just dial back to a state of "a little bit addicted" as you cut your intake. You are still just as addicted and your body is craving a certain level of nicotine in your blood stream. How you respond to that craving may vary and some people obviously can tolerate longer periods of abstention more easily than others, but that doesn't change the existence of the craving. Most cutting back fails pretty quickly as your body pushes you back to that level that …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Threads merged. Please do not create multiple threads for a single question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't. You can push them all into a single .java file, but the compiler is going to break them up again as you have seen (and NormR1 mentioned above).

You can't make separate classes not be separate classes. Sorry I didn't make a distinction above. I meant a single java code file.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

(Edit: Wow, quite a coincidental cross-post. I was writing this when BitBlt posted... yeah, I was busy trying to do other stuff as well, so I'm slow...)

@kraai: I smoked for 23 years. Started around 15 and quit at 38. I tried quitting a few times, tried the gum, tried the patch, but never really committed to it enough. So I just kept smoking and occasionally would think, "Yeah, I really need to give this up some day".

It was during one of those times that I ran across some recommendations of a book by Alan Carr, "The Easy Way to Stop Smoking". There were a lot of positive reviews about it by people who said it really helped them quit. It was a pretty inexpensive book, so I figured it couldn't hurt to drop by the book store and check it out.

I ended up buying it and can honestly give that book the credit for my finally quitting. He does a really good job of showing you just how little you're getting out of it and how much you already know that. As a former smoker, he'd been though it all before and knew the mindset. He actually recommends that you keep smoking while you read the book, which makes it a much less daunting attempt at quitting.

I'll admit that I had to read it three times before I did finally bite the bullet and just quit, but that book did eventually get …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Jon, I was referring to a regular smoker, who actually is physically addicted to nicotine. The physical addiction itself remains until the body has had a sufficient period of time completely free of nicotine in which to mend itself of that dependence. It is a chemical process. My point is that until you face that period of time, the physiological addiction is still there.

I didn't make any claim about people getting addicted from one hit of nicotine, so I'm not sure why you're trying to use my statement to make your point. I don't think there's really any medical disagreement that a physiological addiction will not heal itself until the addicting substance is removed.

My statements weren't made to preach to anyone that they need to quit anything nor to engage in fear mongering to prevent them from trying something. That's their own choice and potentially their own problem. I was merely addressing the fact the nicotine replacement therapy isn't some magical, easy way to give up smoking. Giving up nicotine is the way to give up smoking. NRT just delays that process.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I quit cold turkey as well.

Nicotine replacement therapy (gums, patches, etc) just puts off the inevitable nicotine withdrawal. Until you stop taking in any nicotine at all, you're still addicted. They claim that NRT helps you first break the "cigarette habit" and then you can just slowly ween yourself off the nicotine, but that's just bullshit. NRT only lengthens the process and puts money in the pockets of the people selling the products.

Nicotine is one of the most addictive substances known to man and getting off the gum or patch is going to suck just as much as stopping cold turkey from the start. You may as well save the expense and face the withdrawal head-on from the beginning. You're going to eventually aynway.

(And yeah the OP was just copy-paste spam, but since some discussion grew out of it, I suppose it should stay up without the link)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The question has nothing to do with UI components. It's a class structure issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I stated in my initial post: I am not recommending that he do that. I believe they should be individual class files.

I was merely showing him a way that he could do what he asked about.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you read the sticky thread at the top of this forum entitled "Starting Java"?