Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My use of 'should' is merely in the terms of a suggestion, not an imperative. That may be a usage difference that is more subtle to a non-native speaker of English. :)

I have no moral difficulties eating the meat of animals. I'm sure that most other carnivores don't lose too much sleep over it either. If you prefer veggies, great, more veggie-power to ya - I'll stick to getting my protein from cute, furry critters.

Nick Evan commented: Hmmm... baked cute & furry critters; sounds delicious! +15
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course, it's a lot easier if you just have the index of your array/list be the power: 4x^2+5x^3+6 --> [6, 0, 4, 5]

iamthwee commented: damn right +18
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well the only thing I hope for with evolution is that we don't evolve into some sort of moster that ya see on those science fiction shows.

What makes you certain that we haven't?

ddanbe commented: Wished I had said that! +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Trash t = new Trash();
t=null;
System.gc();
System.runFinalization();

does run the finalization. Finalize is a bit of a tricky thing and really shouldn't be relied upon as a cleanup mechanism. If you need to close resources, you should put explicit methods in for that and call them when required. You can read more about this here: http://www.codeguru.com/java/tij/tij0051.shtml#Index296

stephen84s commented: Good Post +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start a thread on it if you wish to have such a discussion. Posting it on the tail end of someone else's thread on Bluetooth won't attract much participation.

Salem commented: Well said +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Correct. The drawing code needs to either be moved into the paint() method or called from it with a reference to the Graphics object. See comments in edited code:

package wk8exercise3;

import java.applet.Applet;
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;

/**
 *
 * @author Rob
 */
public class wk8Exercise3 extends Applet implements ItemListener {

    Choice myChoice;

    int rectX;
    int rectY;
    int rectWidth ;
    int rectHeight;
    String shape;
    int Selection;  // moved this up here

    public void init()
    {
        // Create the choice and add some choices
        myChoice = new Choice();
        myChoice.addItem("Pick a shape to draw");
        myChoice.addItem("Draw a rectangle");
        myChoice.addItem("Draw a Line");
        myChoice.addItem("Draw an Oval");
        add(myChoice);
        myChoice.addItemListener(this);
    }

 public void itemStateChanged (ItemEvent e)
    {
         // set new selection index
         Selection = myChoice.getSelectedIndex();
         repaint();
    }

 public void paint(Graphics g)
	{
         super.paint(g);

         if (Selection == 1)
         {  
             // you can call these methods directly here
             g.drawRect(50,50,100,100);
         }
         if (Selection == 2)
         {
             g.drawLine(50,50,200,50);
         }
         if (Selection == 3)
         {
             // or you can pass the Graphics reference as a parameter
             drawAnOval(50,50,200,50,g);
         }
	}

  // added Graphics as a parameter here
 public void drawAnOval(int ovalX, int ovalY, int ovalWidth, int ovalHeight, Graphics g)
  {
    g.drawOval(ovalX, ovalY, ovalWidth, ovalHeight);
  }

}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's kind of hard to say from a general standpoint, since it does depend on what you've coded after all, but keep in mind that repaintings of the top level container (Applet, JFrame, etc) are heavyweight AWT operations that use native code to redraw the top level window in the OS. Swing calls however (like contained JPanels) are lightweight internal repainting operations that are much more finely controlled for you through a repaint manager with double-buffering, incremental "dirty-region" repainting, etc.
You can read more about these differences in this article if you like: http://java.sun.com/products/jfc/tsc/articles/painting/

Intrade commented: Always helpful =) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If Main.class is declared in a package named "sort2" and in a folder of that same name, then from the root directory (the one containing the sorts directory), you invoke the class as "sort2.Main". The package is part of locating the class.
This tutorial may be helpful: http://java.sun.com/docs/books/tutorial/java/package/index.html

lllllIllIlllI commented: Couldnt have been a better post +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Specifically, you probably want to throw an IllegalArgumentException. You can set whatever message you want in the constructor.

stephen84s commented: The best option +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just ran across a link to this thread so I thought I would update: I quit two months ago. One less smoker in the world.

Ancient Dragon commented: Great Job :) +36
jasimp commented: Congratulations :) +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Oh, I doubt Dani wants to open the gates to hordes of pubescent leet gankers, pwning this and roflcoperting that and generally epeeing about the place.

darkagn commented: lol :) +4
jbennet commented: lol +36
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I really couldn't say because it would depend on how/what you set up there. Things do sometimes look different from the design preview at runtime and it just takes some fiddling around if that is the case. All part of the fun :P

BestJewSinceJC commented: Netbeans is pretty cool. Thanks! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use a DOM api like JAXP or JDOM.

Killer_Typo commented: agreed, no reason to not use the API. +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps

<team name="indianaTux">
    <player>
        <Name>Default Player</Name>
        <Score>0</Score>
        <Time>null minutes null seconds</Time>
    </player>
    <player>
        <Name>Another Player</Name>
        <Score>0</Score>
        <Time>null minutes null seconds</Time>
    </player>
</team>
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I just fixed the behavior that he was unhappy with, but yes, it is a bit more efficient. He was re-processing the entire content of the document when he only needed to re-process up to the current insertion point for the highlighting.

sciwizeh commented: Very good information, thanks +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
verruckt24 commented: Your answer stands out amongst all. Not to mention it the most elegant +3
stephen84s commented: Agree with verruckt +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I agree with the others above: enough with this public crush thing you have going on. At best, it's disrespectful and you should be old enough to realize that.

mitrmkar commented: Well said. +7
William Hemsworth commented: :) +7
Comatose commented: Pwnage! +12
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

such individuals logic is non-existent/faulty. An omnipotent being can manipulate the universe and adjust the laws and principles (of physics, of mathematics or even of existence itself) of that universe ... or to paraphrase "through God all things are possible"

Ah, well at least there isn't anything wrong with this logic. :icon_rolleyes:

jasimp commented: I don't see anything wrong with his logic. A being that can control every facet of existence is very logical ;) +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, based on all the code you posted and the detailed explanation of the error ...

Killer_Typo commented: hahahahaha I needed that laugh! +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i dont violate any copyrights or so, so from their perspective my potential thoughts do not cause any problem. i dont violate any laws.

I did not mention violation of laws. Show them this thread if you are so proud of it.

By the way, one of the christian missioners in my company gave me two dvds and i am totally persuaded that darwinism is just impossible because even the most primitive cell requires all at ones and simultaneous structures. i will post the name of that dvds later.

This has nothing to do with the discussion at hand and belongs in the lounge.

stephen84s commented: Bang on target !!! +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Places of origin doesn't matter.
Well, place of origin does matter when the question of the thread is "Where are you guys from?".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Listening to some Killswitch Engage this afternoon.

William Hemsworth commented: Good choice :) +7
Will Gresham commented: I like it :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And did your friend also let you know that help is only offered to those who demonstrate some effort, as stated in the community rules and many announcement threads scattered throughout the forums?

Post what you have so far or at least some specific questions related to the areas that you are struggling with. "Tell me how to do this" doesn't really indicate much effort or thought on your part.

Salem commented: Well said, and nice avatar :) +29
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just to provide a little more explanation why that works and why you had the previous difficulties, you were executing your animation loop code that slept and called repaint() on the event dispatch thread - which is the same thread that is responsible for processing those repaint() calls you were sending. By moving the animation code to it's own thread, you free up the event dispatch thread to respond to the repaints() that you are requesting.

You can read more about concurrency concerns in Swing here if you like: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

VernonDozier commented: Good link. +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So use String.valueOf(int).

notuserfriendly commented: strongly approve and thanks so much +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

table[tr/td/b/font='Nohup Files'] seems to work for getting the table element, if that's what you are wanting. I tried it out with the following structure

<root>
    <table>
        <tr><td><b><font>Not this one</font></b></td></tr>
    </table>
    <table>
        <tr><td><b><font>Nohup Files</font></b></td></tr>
    </table>
    <table>
        <tr><td><b><font>Other</font></b></td></tr>
    </table>
</root>
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just as a stapler will bind paper, love will bind people.

A stapler will bind people too, if it's big enough.

Nick Evan commented: yup +14
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

After 61 posts here, you should be well aware that "chat-speak" or "IM-speak" is discouraged in the forum rules. Are you really too lazy to type out all of the letters and use punctuation where appropriate? Should anyone else spend their time to help someone who doesn't care enough to take the time to communication properly? Think about it.

That said, try the Java Media Framework. You can find a lot of demo code and examples here: http://java.sun.com/javase/technologies/desktop/media/jmf/reference/codesamples/index.html

stephen84s commented: Excellent post. +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>and i dont mind if u can give me the whole code for this program

So, actually you are perfectly ok with cheating, even though you claim you don't want to.
Read your class notes, get a program outline or at least a decent amount of pseudo code together on your own, and post that back here with specific questions or errors.

No one here is going to complete this for you. Better get started soon, you don't have a lot of time left.

verruckt24 commented: Caught him !!! +2
stephen84s commented: lol +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is that babble supposed to make any sense at all?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

how do i create java code that randomly assign numbers to letters,

With Random and a HashMap I suppose.

sum them,

"+" operator.

display them

A console or a Swing GUI

and store them in a database

JDBC

javaAddict commented: you put a lot of effort in this response +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, not knowing your exact directory structures and where your output class files are located (you said they were in different directories), I would recommend compiling all of those java files at the same time with javac *.java . It's just a simple classpath problem that you are encountering. There is nothing wrong with the code itself.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I can't really see how anything vaguely useful could come from leaving it open.

Salem commented: Neither can I, and I've reported it as such. +28
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And what would you do after you find "that" partner you are looking for ?

Professor Chaos is born...

stephen84s commented: lolzz nice +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I Have That Same Problem........Will somebody please help!!!!!!!!!!!!

That's not enough exclamation points to bring the posters back from 2004.

Nick Evan commented: No?!??! :) +13
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So did you input 2 numbers for it to use? Your scanner is waiting for input.

Rashakil Fol commented: heh +9
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hmm... let us think about it for awhile...

No.

Read the forum policies on homework and demonstrating effort. For that matter, read the section on using proper English too - this isn't a chat room.

Salem commented: Keep up the good work, unlike some of the soft-heads who -ve rep for telling lazy students what to do. +27
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look again at your variable declarations in main(). You'll see that you declared other variables for those values, but p, r, and t are not those variables.

zaraeleus commented: Thank you... you caught the obvious that I was missing all along! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
peter_budo commented: Nice articles, specialy today.java +14
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a little bit of background reading that should help : http://www.daniweb.com/search/search.php?q=final+project+idea

Salem commented: Solid +25
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I suppose you would start with the Swing tutorial: http://java.sun.com/docs/books/tutorial/uiswing/index.html
and when you have questions, come back and post them along with your code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

...but it demonstrates extraordinary bad taste to name a son just to "have fun" ...

Well, the parents who do that probably only have that son from "having fun" and thinking things through is not their strong suit.

mrboolf commented: you're right... damn sad though. +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Nope, because you're still using == to check string equality instead of the equals() method.

Anyway, I'd recommend looking at this method in the Scanner API: Scanner.hasNextInt()

Optionally, you might want to consider looking at the regex Pattern class as well.

iamthwee commented: *nods* +17
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It means the package declaration in the file does not match the package structure on disk. Are you certain that you added the 'build' folder in the Libraries section using the "Add jar/folder" button? I downloaded the code and added that folder to my own project with no problems at all.

stephen84s commented: I would have already started abusing and swearing by now :P +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

At it's most basic, a linearly interpreted gradient just calculates the new RGB values by applying the target value percent of the linear range to the each RGB component range. Here's a Java function illustrating that:

/** returns a color between start and end colors based upon percent of the range */
private Color gradedValue(Color beginColor, Color endColor, float percent) {
    int red = beginColor.getRed() + (int)(percent * (endColor.getRed() - beginColor.getRed()));
    int blue = beginColor.getBlue() + (int)(percent * (endColor.getBlue() - beginColor.getBlue()));
    int green = beginColor.getGreen() + (int)(percent * (endColor.getGreen() - beginColor.getGreen()));

    return new Color(red, green, blue);
}

Where "percent" is just the percentage of your spatial linear range, i.e. at position x=50 on a display area 200 pixels wide, "percent"=0.25. The intermediate color for that point on a gradient from white to blue would be obtained by gradedValue(Color.WHITE, Color.BLUE, 0.25f)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it isn't, really. If you are still concerned about calling the same method again and again, instead of having your class maintain the state or cache the `red' value, shove the responsibility to the invoked method instead.

private void mutate() {
  int red = color.getRed();
  // some complicated, multi step calculation using `red'
  color.setRed(red);
}

And talking of terms like overhead for a program without any concrete profiling data whatsoever is wrong IMO.

++ to this.
Premature optimization in the absence of profiling data is a recipe for all kinds of trouble and makes baby Jesus cry.
The overhead of that method call vs the variable is negligible unless it's in a long loop and even then compiler will probably identify it as a loop invariant and use a local variable for it anyway. If not then you can always make one yourself just like s.o.s. showed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't want a while() loop in the mouseListener. You want to increment a counter each time a point is collected until you have recorded the required number of points for your polygon. You may only want to draw the points themselves until you have the entire polygon specified. You'll also need some way to reset it. Perhaps a seventh click or a right-click should clear the points and reset the counter.

stephen84s commented: You've got to have a high EQ with that IQ to put things that clearly in so few words +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Tyster commented: Many Thanks! I think using Callable will do the trick. Cheers! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you believe that I posted that answer and link to the tutorial just because I enjoy suggesting random, irrelevant possibilities?

PoovenM commented: Agreed :) +3
stephen84s commented: lolzz ..... :D +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Though it is not Java specific and not targeted for beginners, Code Complete 2nd Edition is an excellent book for anyone engaged in non-trivial programming or interested in software best practices. It's filled with a ton of information and suggestions gleaned from years of professional development experience - all that stuff that most of us working developers have learned the hard way in bits and pieces and wish we'd known from the outset.

~s.o.s~ commented: Indeed; like they say, "If I have seen further it is only by standing on the shoulders of Giants" +25