Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>ps: are we allow to ask people here to review the site?
Yes, you may post a review request in the Website Reviews section.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please be more specific about what you are having troubles with.

Also, learn to indent your code because that is a monolithic mess you have posted and no one wants to read that.

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

These are not methods of Thread.

setFocusable(true);
addKeyListener()
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Apparently this is now being continued here:
http://www.daniweb.com/software-development/cpp/threads/353606

Please direct further discussion to that thread.

Taumang, do not continue to make new threads for this single problem.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Really I don't think there is any reason to replace a tile button in the layout. Just change what it is displaying. A tile is initially empty and then displays the letter you placed on it. That doesn't require a new JButton.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@saranyabaskaran: No, do not hijack other posters threads to ask your own questions. Please start a new thread of your own and explain more clearly what you are trying to do when you say "set the angle".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@mKorbel: I'm really trying to understand what you have written, but honestly I cannot. It just doesn't make any sense to me.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you want to specify and replace a component at a particular grid position, you should switch to GridBagLayout.

Store the gridx and gridy values in your ScrabbleButton class as you add them to the panel. On click, you will know which component to remove and replace in your layout. You can remove it with a direct reference to the object. Add your new button to the container with the gridx and gridy values of the button you're replacing.

Edit: You could also create an extended JPanel component like "BoardSlot" that displayed your button. If both components had references to one another, you could swap out your buttons without removing anything from the top-level board container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't.

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

Since you obviously ignored it, I'll point you right back to Jon's post on the first page of this: http://www.daniweb.com/software-development/java/threads/352203/1496623#post1496623

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Most likely it's a pathing issue with your image file. Take a look at the How To Use Icons tutorial for some info on locating resources.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually the movement is from (x2,y2) to new (x2,y2) and divide by the time since your last update.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

For games, have you looked at JMonkeyEngine? It's an open-source 3D game engine for Java.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think you may be confused about variable scope. The "fees" you declared in main() is not the same variable that you are working with here

public static void displayTotal(double total)
	{
		DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
		
		[B]double fees;[/B]
		double tuition;

		fees += tuition;
		
		System.out.println("The total is: "+ tuition +".");
	}

In displayTotal, you have delared a new and completely separate varialbe "fees" that is only visible within that method declaration.

Edit: Glad you got it figured.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are supplying the total to the displayTotal(double total) method, so why are you making a separate calculation (with empty variables) for the total that you are printing out

System.out.println("The total is: "+ tuition +".");
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The compiler just wants to make sure that your variables have been assigned a value before you use them in an expression. If you assign them a default value when you declare them, the compiler will be happy

double fees = 0;

as you noted.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

526

And that makes 5700 posts.

I'll give Team B a chance to make a showing and perhaps I'll pop back in later.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

522

I only dabble now and again.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use an ImageIcon. Take a look through the tutorial on buttons.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> We just went through this, now again
Oh, surely you want to give Team B another chance, right?
:P

514

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

506

So how's work going today?

:)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

502

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

842

I believe you mean 500. You can't add 340 and you're on the subtracting side :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>check this out guys..
Why? It doesn't address the original poster's question and this thread is from 2009.

Did you have a point in posting this code? If you did, please state it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Scoreboard updated. Back to 500...

502 :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, that is the entire point of the argument array to main(). If you execute your class/jar with the following statement

java MyProgram A B C

your args array in main() will contain {"A","B","C"}

mangopearapples commented: Because I Love you for helping me! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> How could I use this in Java though?

public static void main(String[] args) {
    if (args.length > 0) {
        String filePath = args[0];
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The %1 in my example above is the first parameter to the bat file, which in the case of "Open with..." it will be the full path of the file.

You are pass that as an arg to your Java program, so you can pick it up in the args array in main(String[] args) .

>Why do you get the feeling that this is not a Java question?
Because it isn't really, it's an OS question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could create a batch file that passes the first arg along as an arg to your program:

java -jar MyProgram.jar %1

If you select your batch file in the "Open with..." dialog, the filename will be passed as that argument %1.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Closing. Nothing further to be gained from this thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

... I used to buy PC games, but then it just wasn't worth it. .... So I just get them online, get a crack and play the single player, or crack it for LAN play with friends....

So they're "just not worth it", but you'll still steal them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could take a look at Law of Cosines as well, if the vector method isn't working out for you. It's just another way to skin the same cat.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It may depend on how you represented your input vectors. For that upper point on figure b that you refered to, you would need to calculate the vectors from that point of origin such that they were pointing out and down from that position using (x2-x1,y2-y1).

Here's a small spreadsheet of the results I got with that formula. I calc'd the angle between each vector pair on an irregular triangle I just made up. The total of all calculated inner angles was 180 and each one seemed to be right by visual estimation (the lower row is degrees, I forgot a label)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The method is Math.acos() Remember that the angle is in radians. You can use Math.toDegrees(double) to convert to degrees if you need to.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@OP:
> So, could anybody help me understand as to what/where is my mistake I made in the code.
There are two main problems. One is that the desktop_pc code to initialize your StringBuffer in the start() method is never being called, so the run() method generates a null pointer exception when it tries to append to a null buffer reference. This can be easily corrected by moving

buffer = new StringBuffer();

into the constructor or on declaration.

That would fix the null pointer but not the second, greater problem: expecting to see changes in the desktop_pc buffer appear in your PcLab applet. The desktop_pc objects are completely separate from PcLab and their internal buffer variables are private to themselves. They do not affect PcLab at all.

If you want to write back to PcLab, you need to create a communication path to it between the two classes.

One way to do that would be having your desktop_pc constructor accept a reference to the PcLab instance and create a method such as append(String) on PcLab that would append a message to its buffer and refresh its display. The desktop_pc classes would call that method to write back to the applet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think you're correct, Nezachem. There doesn't appear to be any execution path to that start() code.

I misunderstood what you were getting at in the previous post and did not notice that he was not actually running that applet.

start() would be getting called by the Applet container if that class were the one being executed, but as you noted, desktop_pc here is just another class and start() won't execute unless explicitly called in the code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would agree with the above suggestions to get the ImageIO.read() out of the paint() method and override paintComponent() instead of paint() unless this is an AWT Applet.

I'd also like to mention that you don't necessarily need to create another rotated instance of AffineTransform here

AffineTransform transform = (AffineTransform) (affTransform.clone());
            g2d.transform(transform.getRotateInstance(-this.getHeadingValue() / 57.29, centerX, centerY));

You should be able to simply call

g2d.rotate(-this.getHeadingValue() / 57.29, centerX, centerY)

and draw the image. Since you're restoring the original transform anyway, you can operate directly with the current transform of the graphics context.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you look at this line of the stack trace

at lab2.readFile(lab2.java:92)

it indicates that the error occurred on line 92 of your program and the error was InputMismatch when it tried to process the nextInt() call.

Most likely you input something that was not an integer and nextInt() expects an int.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@nezachem: start() is an Applet life cycle method though. I believe that's why he has that code in start().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Since they're not right triangles, using the dot product of the vectors may be easier.
Given the vectors (x1,y1) and (x2,y2):
angle in radians = arccos((x1*x2 + y1*y2) / ( sqrt(x1*x1 + y1*y1) * sqrt(x2*x2 + y2*y2) )

More wiki info here: http://en.wikipedia.org/wiki/Dot_product#Geometric_interpretation

Pretty decent vector algebra reference here:
http://emweb.unl.edu/math/mathweb/vectors/vectors.html#vec4

Edit: You may need to twiddle the signs a bit. I'm not a vector math genius and always have to "play" with the numbers a little.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to use one of the inverse functions: acos, asin, or atan from Math. Which one depends on which sides you compute the line lengths for.

Edit: If you've forgotten which sides relate to which function, Wikipedia has a graph and table here: http://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> am helpless
Then you're failing.

Help is offered here to those who show effort. This is not a homework completion service.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those applications are compiled to run in the windowing system of the OS - not in the container provided by a JFrame. They are not Java applications and are not designed to interact with one.

What you ask is akin to wanting to open Microsoft Excel within Paint. They are completely separate and incompatible entities.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> anyone have Tutorials for this.
Oracle does. Look them up.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> My project is to...
Re-read that part. Now, re-read it again. It's an important concept - the "my" part.

If you have specific questions, ask them. Demonstrate you have made the slightest effort on this or even given it any serious thought.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you misunderstood what Jon posted? I can't even understand what you're attempting to say here.

happygeek commented: my thoughts exactly +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your repaints() are going to take a long time since you are pausing 3 seconds between each element drawn and I would agree with mKorbel that doing the animation in your paintComponent() method is probably not the best idea. repaint() can be called for many reasons by the system and should be as lightweight as possible.