File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Paint Method Puhhlease Help

 
Alisha Burke
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am in a dilemma in synchronizing my answers. As some of u might know my program is to convert binary/octal numbers to decimal. I have already done the conversion. However, as part of my program i would also need to display the positional weightage of each digit of the number.

I used the paint method to display the positional weightage for example(Binary number: 1001) :
......................................................................1...... .......... 0..............0................1

..16............................5................4.................3........... .....2..............1...............0
2...............................2...............2................2............. ....2..............2...............2

This is what my program is getting regardles of how many numbers i key in 1,10,100,10000001 etc. I don't want it to print up to 2^16 unless of course my number has 17 digits.Another problem is i am using
another method to set the Text of the binary/octal number as i am unable to use paint method (it keeps on giving me answer 0 for my conversion). So the positioning of
the numbers is wayyy off.

Basically i want it to be like this :
1................0...............0................1

.3..................2...............1................0
2..................2..............2................2
or another example:

1....................0.............1..............1................1........... .......1.................0..................1

..7...................6............5................4...............3.......... ........2................1...................0
2...................2.............2...............2................2........... ......2.................2..................2



Appreciate it if you do not repost the entire code. Just parts of it that needs correction.

Please help!!!

p/s : ignore the dots.

[ February 15, 2005: Message edited by: Alisha Burke ]

[ February 15, 2005: Message edited by: Alisha Burke ]

[ February 15, 2005: Message edited by: Alisha Burke ]

[ February 15, 2005: Message edited by: Alisha Burke ]
[ February 15, 2005: Message edited by: Alisha Burke ]
 
Liam Tiarnach
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool... Now to start looking at it...
 
Alisha Burke
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liam,

Appreciate it if you do not post the entire code or repost my code for that matter just parts that needs correction Thankx.
 
Liam Tiarnach
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a problem...

Okay here we go, now that I can see what is going on...

first we will introduce a new method to build our weighted answer display...

I believe I had put enough comments for you to understand so I will just explain the one thing that might just jump out at you...
this piece...

I think it's called a "shortcut if-else statement" which has this syntax...

it would be the same if I had done this...

the next change is in this part, the paint method...

we call the answerDisplayBuilder() method and pass it our Graphics g so that the answerDisplayBuilder method can build our weighted answer display...
and the last modification is in the actionPerformed() method...

after we do the numberkeyinLabel.setText() method, we call repaint to, well, repaint our graphics...

So with these modification done, you binary number display should work properly...

later you might want to modify the answerDisplayBuilder() method to have your weighted display self center...
and it to have it display either your binary or octal weighted number...
i.e. instead of using the string literal "2" in...

you can use a String variable that can be set to the base number that you want to display...
i.e.


Have fun...
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Liam Tiarnach:
I think it's called a "shortcut if-else statement" which has this syntax...




In the The Java Language Specification (JLS), it is simply referred to as the "Conditional Operator ?:", or "?:" for short. Details about it and its usage are available in section 15.25.

It is also often referred to as "The Ternary Operator", although it is technically only a type of a ternary operator.

It is a powerful operator, but can be confusing for beginners. Even some advanced developers avoid it since it can make code a bit more muddled in its reading. Some discussion on the topic is available in this thread.
 
Alisha Burke
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Liam!

Its working perfectly except for the fact that the positioning of the powers is going from 0,1,2,3 to 16. And i need it backwards 16,15,14.......3,2,1,0.
I know i need to edit some parts of the code in the for loop to achieve this so I am working on it and i'll post some more if i need help.

Thankx again.
 
Liam Tiarnach
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alisha Burke:
Thanks Liam!

Its working perfectly except for the fact that the positioning of the powers is going from 0,1,2,3 to 16. And i need it backwards 16,15,14.......3,2,1,0.
I know i need to edit some parts of the code in the for loop to achieve this so I am working on it and i'll post some more if i need help.

Thankx again.

hehe... and sure enough it is backwards... I was working with two different versions of the same program, Testing and Testing1...

in the buildAnswerDisplay() method, where that loop is...
check this line...

as can be seen, int i counts up... and thats were I goofed
it should be...

since j counts down...

I must admit, that was a good goof up on my part...

Have fun...
 
Alisha Burke
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Goof or no goof I appreciate you helping me
 
Liam Tiarnach
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alisha Burke:
Goof or no goof I appreciate you helping me


Thank you...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic