Java GUI Swing Byte Text Area?

C

cryptogirl

Hello,

I've designed a GUI in java and I want one of the text areas to be of
input bytes. Except JTextArea only inputs of type String and if I
convert the string to byte arrray I lose precious and my answer doesn't
make much sense in the end.

Is there anything call JByteArea? I tried looking inthe Java API and
found nothing or can anyone offer any other advice.

Thank you
 
V

VisionSet

cryptogirl said:
Hello,

I've designed a GUI in java and I want one of the text areas to be of
input bytes. Except JTextArea only inputs of type String and if I
convert the string to byte arrray I lose precious and my answer doesn't
make much sense in the end.

Is there anything call JByteArea? I tried looking inthe Java API and
found nothing or can anyone offer any other advice.

No, there is only textual representation of, er, text.

So you want to improve your textual representation of bytes.

What have you got ie "my text"
What do you want?
convert the string to byte arrray I lose precious and my answer doesn't

'precious' ? typo?

perhaps you want each char out put as its ascii value?

"AAA" rendered as

01000001
01000001
01000001
or in hex
414141
or in dec
65
65
65

You need to be more specific.
 
C

cryptogirl

Here is an example of my byte representation

335435-41

now if i convert it from String to byte array it will out put as the
first two bytes 3 3.
Except the first 2 bytes are suppose to be 33 54. Being two digits
long isn't always the case. for a byte array it can go any were from 1,
127, -127.

Now how would I put each one in it's ascii value?
 
V

VisionSet

cryptogirl said:
Here is an example of my byte representation

335435-41

now if i convert it from String to byte array it will out put as the
first two bytes 3 3.
Except the first 2 bytes are suppose to be 33 54. Being two digits
long isn't always the case. for a byte array it can go any were from 1,
127, -127.

Now how would I put each one in it's ascii value?

You can't because you don't know where to perform the splits.

3/3/5/4/3/5/-4/1

or

33/54/35/-41

or

3/35/43/5/-41

etc

Are you asking the real problem or your half 'solved' version of it?
If you can step back and state the real problem, it would be better.
 
C

cryptogirl

Bascially it's the representation of a encrypted packet

and it's 1500bytes.

And I need to do a GUI representation in order to be able to view the
output correctly.
 
A

Andrey Kuznetsov

Bascially it's the representation of a encrypted packet
and it's 1500bytes.

And I need to do a GUI representation in order to be able to view the
output correctly.
then output your bytes as hexadecimal numbers.
see Integer.toHexString()
You have to ensure that every byte get converted to 2 chars:
1 -> 01
10 -> 0A
255 -> FF
 
C

cryptogirl

But how would i convert each byte into an hexdecimal. I tried using
parseInt on the whole string but that doesn't work very well
 
A

Andrey Kuznetsov

But how would i convert each byte into an hexdecimal. I tried using
parseInt on the whole string but that doesn't work very well

it is pretty unclear, which representation have your 1500 bytes -
is it a byte array, or String?
In general encrypted data shold not be in a String.
If you save it to a file, then just createFileInputStream and read it byte
for byte.
 
C

cryptogirl

I know how to read it in from a file.. except i'm doing a User
interface in java to represent everything. I could read in my result
byte byte from a file and output it to the GUI and the save it some
where to be used.

I've pretty much tried everything and I guess that's what I will have
to do.

So basically i have my encrypted data and the user clicks decrypt and
in the plaintext box the data will appear. But i believe your right on
the file part and I will be changing my plans in order to read it in
from a file store it then output it on the screen in the encrypted data
text field and just work with the actually stored data to decrypt.

Thank you
 
A

Andrey Kuznetsov

I've pretty much tried everything and I guess that's what I will have
to do.

So basically i have my encrypted data and the user clicks decrypt and
in the plaintext box the data will appear. But i believe your right on
the file part and I will be changing my plans in order to read it in
from a file store it then output it on the screen in the encrypted data
text field and just work with the actually stored data to decrypt.

BTW if you want to transfer binary data as text it is good idea to use
base64 encoding/decoding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top