Win a copy of Rust Web Development this week in the Other Languages forum!

since Mar 02, 2003

Cows and Likes

Cows

Total received

0

In last 30 days

0

Total given

0

Likes

Total received

1

Received in last 30 days

0

Total given

0

Given in last 30 days

0

Forums and Threads

Scavenger Hunt

Ranch Hand Scavenger Hunt

Greenhorn Scavenger Hunt

Hi all, just wanted to drop a quick question on you. I have a JPanel that I am placing things on but as you know the JPanel is constructed with its height and width starting from 0,0 in the upper left hand corner.

The height of my panel is 600.

The problem that I am having is that when I place the objects on the panel they are going up instead of down. I know that there has to be an easy fix for this, but I cannot seem to come up with one.

I would assume that I could just do a getHeight() - 600 to compensate for the panel, but that didn't work.

The goal is to have the objects go down instead of up.

Here is my code if anybody is interested.

Thanks in advance:

The height of my panel is 600.

The problem that I am having is that when I place the objects on the panel they are going up instead of down. I know that there has to be an easy fix for this, but I cannot seem to come up with one.

I would assume that I could just do a getHeight() - 600 to compensate for the panel, but that didn't work.

The goal is to have the objects go down instead of up.

Here is my code if anybody is interested.

Thanks in advance:

14 years ago

never mind. It works like a champ.

Sun fix.

Thanks

Sun fix.

Thanks

14 years ago

Hi All, I am having real trouble trying to remove lines from my Tetris board. I have a few methods that I can only ask that you look at.

from this method I am checking whatever row is full (for example say I am checking the very bottow row...row 0 so i = 0, sees a full line (grid array 2's when frozen) and checks for a count and a width to zero in on the line and calls removeRow(i).

And from here it removes that row making row 1 row 0.

It then goes back out to the checkRow method and by now it has iterated past 0 and is not on 1. It is now checking row 1 instead of row 0 for multiple line removal.

what am I missing to make the i go back to zero or to check with antother reference to make these lines drop?

Thanks in advance.

Gabe

from this method I am checking whatever row is full (for example say I am checking the very bottow row...row 0 so i = 0, sees a full line (grid array 2's when frozen) and checks for a count and a width to zero in on the line and calls removeRow(i).

And from here it removes that row making row 1 row 0.

It then goes back out to the checkRow method and by now it has iterated past 0 and is not on 1. It is now checking row 1 instead of row 0 for multiple line removal.

what am I missing to make the i go back to zero or to check with antother reference to make these lines drop?

Thanks in advance.

Gabe

14 years ago

Hi all, just wondered if yall could help me with this rotate method for my tetris game. This method works fine, but I want the points of the body of the pieces to stay positive, for example, if I rotate the "J" Piece once (90 degrees) it will rotate out of the standard 0,0 origin and actually have one of the blocks (points) sticking out of this quadrant.

Is there an easy way to implement the rotation around a central origin for EVERY piece, or a way to reset the origin after the piece has been moved?

Thanks in advance

Gabe.

Is there an easy way to implement the rotation around a central origin for EVERY piece, or a way to reset the origin after the piece has been moved?

Thanks in advance

Gabe.

14 years ago

I am trying to create a single method that holds all of the event listeners of my simple drawing class and when I try to incorporate the drawing thickness radio button listeners into that I have problems.

Below are a few snippets of code to show you what I am trying to do, and

possibly what I am doing incorrectly. What I end up with is the last radio

button to be selected is the one that is used (for drawing). So if I select 1 then I draw with 1, if I select 2 then it draws with a 2, if I select 4 then it draws with a 4. But when I try to go back to 2 or 1 it draws with a 4(the last one selected). I assumed that it was because this was a listener for mulitple actions and that I am adding them in at the same time and that I am creating a new JRadioButtonMenuItem everytime I add something (Basically I have N action listeners, one for each item I create. I have tried to pass this in as a parameter only to get the same results. Can I do this or is there really

not an elegant design option here? Ultimately I want to pull all of my

listeners into a seperate class (Not Inner), but currently I am testing it in a method.

Thanks in advance.

[ April 30, 2007: Message edited by: Gabriel White ]

Below are a few snippets of code to show you what I am trying to do, and

possibly what I am doing incorrectly. What I end up with is the last radio

button to be selected is the one that is used (for drawing). So if I select 1 then I draw with 1, if I select 2 then it draws with a 2, if I select 4 then it draws with a 4. But when I try to go back to 2 or 1 it draws with a 4(the last one selected). I assumed that it was because this was a listener for mulitple actions and that I am adding them in at the same time and that I am creating a new JRadioButtonMenuItem everytime I add something (Basically I have N action listeners, one for each item I create. I have tried to pass this in as a parameter only to get the same results. Can I do this or is there really

not an elegant design option here? Ultimately I want to pull all of my

listeners into a seperate class (Not Inner), but currently I am testing it in a method.

Thanks in advance.

[ April 30, 2007: Message edited by: Gabriel White ]

14 years ago

MyFirstApp.java must exist. If you goto the directory where that file exists and then run that command it will work and compile your .java file into a .class file and run when you type java MyFirstApp.java.

If you created your file (in a text editor or wherever) you will have to save the extension as type .java.

Ensure this and it will work.

HTH

If you created your file (in a text editor or wherever) you will have to save the extension as type .java.

Ensure this and it will work.

HTH

14 years ago

Ok, I finally figured this one out but there are still a few kinks.

I need to finalize my Mantissa in 2's power form. So if after shifting I am left with the fraction of the hex number in floating point and it looks something like this: 11001001, then the 2's power of that would be (since it is the Mantissa all of the exponents are neg) 2^-1 + 2^-2 + 2^-5 + 2^-8.

When I try to mask by 0x1 and shift to the left I get the number that is actually there at that position rather than what I need (above).

Here is my code so far. There are a few erroneous SOP lines in there for testing, but it is pretty straight forward.

Thanks in advance.

I need to finalize my Mantissa in 2's power form. So if after shifting I am left with the fraction of the hex number in floating point and it looks something like this: 11001001, then the 2's power of that would be (since it is the Mantissa all of the exponents are neg) 2^-1 + 2^-2 + 2^-5 + 2^-8.

When I try to mask by 0x1 and shift to the left I get the number that is actually there at that position rather than what I need (above).

Here is my code so far. There are a few erroneous SOP lines in there for testing, but it is pretty straight forward.

Thanks in advance.

14 years ago

Just a quick question, how do you take an input variable into the program from a command line. As from my other program question the command line is: c:\java Fexpand 3e900000

so 3e900000 is the input into the program (args).

I know that this is an easy thing to do but I have just never done it.

Any help would be appreciated.

Thanks.

Gabe

so 3e900000 is the input into the program (args).

I know that this is an easy thing to do but I have just never done it.

Any help would be appreciated.

Thanks.

Gabe

15 years ago

Yes, I just checked and java.lang.Number includes java.lang.Long.

Gabe

Gabe

15 years ago

When you use generics you will have to include a reference to a type of object that is going in the List. In this case you are trying to tell the ArrayList to reference only values of type long, or int or double, etc...

You need to declare the objects that will be referenced in a generic by usinig big D Double and Big I Integer and Big L Long as these are object types.

I'm not too sure if you can box a Long as an object type but check your API and you will see.

This code works:

List<Long> lngDate = new ArrayList<Long>();

HTH

Gabe

You need to declare the objects that will be referenced in a generic by usinig big D Double and Big I Integer and Big L Long as these are object types.

I'm not too sure if you can box a Long as an object type but check your API and you will see.

This code works:

List<Long> lngDate = new ArrayList<Long>();

HTH

Gabe

15 years ago

Hi Marc and thanks for the reply. Is there a way to do single floating precision? I just found this as an example as how to find the exponent. I guess my question is how do I write the code to shift in order to go through the binary representation of this number which is:

3e900000 = 00111110100100000000000000000000

0 represents the sign (so positive) 01111101 represents the exponent = 127 -127 =-2 so knowing that the mantissa has bits in it then we know that it is also part of the decimal notation of 2^-3, so in all this is the result of 2^-2 * (1 + 2^-3) (normalized from 0.28125 which is the Float of the int hex. This is why I used a double here to represent the value of the bits. The offset is used because of the 64 bit shift.

Is there another way of doing this? For example, can I just use 2* 1 + exponent ^-23 ?

As you can see, I can do the math, it is just the shifting that I am having trouble with. I have never performed ANY bitwise or shifting operations before this. This is an obvious program to complete using an array and using math.pow, but as placed in the restrictions I am not allowed to do so.

Thanks again.

3e900000 = 00111110100100000000000000000000

0 represents the sign (so positive) 01111101 represents the exponent = 127 -127 =-2 so knowing that the mantissa has bits in it then we know that it is also part of the decimal notation of 2^-3, so in all this is the result of 2^-2 * (1 + 2^-3) (normalized from 0.28125 which is the Float of the int hex. This is why I used a double here to represent the value of the bits. The offset is used because of the 64 bit shift.

Is there another way of doing this? For example, can I just use 2* 1 + exponent ^-23 ?

As you can see, I can do the math, it is just the shifting that I am having trouble with. I have never performed ANY bitwise or shifting operations before this. This is an obvious program to complete using an array and using math.pow, but as placed in the restrictions I am not allowed to do so.

Thanks again.

15 years ago

Hi there, I have this program that I am supposed to write but I have restrictions as listed here:

Write a program that takes a hexadecimal number which it interprets to be a IEEE single precision floating point value and prints it out as 2 to the exponent times the sum of powers of 2. The input value should be a command line parameter. Use of the program should look like this:

C:\> java floatPTest 3e900000

3e900000 ==> 2^-2(1 + 2^-3)

Use only integer (bitwise and shift) operations. Do not use floating point variables in any of the intermediate steps. Do not use Strings where you can avoid it. Avoid arrays. Avoid Math.pow(...).

So no arrays, no using Float.intBitsToFloat(x) when int x= 0x3e900000, no strings for the lengths for the bit arrays.

I really need a push in the right direction on this one. I know how to do the math on this one, but I guess I am a little shakey on how to implement shift and bitwise operands to find the double that I will use to find the precision floating point value.

I have implemented this code, but it is nowhere near the output that I need because I need to be able to shift through the mantissa to find the next bit and covert it to a power of 2 (or do I?)and I also used the floating point variables like I wasn't supposed to.

Any ideas would be great

Thanks

Write a program that takes a hexadecimal number which it interprets to be a IEEE single precision floating point value and prints it out as 2 to the exponent times the sum of powers of 2. The input value should be a command line parameter. Use of the program should look like this:

C:\> java floatPTest 3e900000

3e900000 ==> 2^-2(1 + 2^-3)

Use only integer (bitwise and shift) operations. Do not use floating point variables in any of the intermediate steps. Do not use Strings where you can avoid it. Avoid arrays. Avoid Math.pow(...).

So no arrays, no using Float.intBitsToFloat(x) when int x= 0x3e900000, no strings for the lengths for the bit arrays.

I really need a push in the right direction on this one. I know how to do the math on this one, but I guess I am a little shakey on how to implement shift and bitwise operands to find the double that I will use to find the precision floating point value.

I have implemented this code, but it is nowhere near the output that I need because I need to be able to shift through the mantissa to find the next bit and covert it to a power of 2 (or do I?)and I also used the floating point variables like I wasn't supposed to.

Any ideas would be great

Thanks

15 years ago