easy Java fixes

Started by
1 comment, last by Zahlman 18 years, 1 month ago
Hey I'm writing a Java applet and am trying to override some of the default behavior of the JButton controls. I want a JButton to be capable of displaying a Unicode character (say some Japanese character -- it doesn't really matter) on its label, and when selected, to draw that character to a JTextField. So we have the simple code: JButton b1 = new JButton(/* some unicode character */); JTextField t1 = new JTextField(1); (1) How do I specify "some unicode character" in the JButton's initialization? (2) What code would I use in the handler to update the text field with this same character?
Well I believe in God, and the only thing that scares me is Keyser Soze.
Advertisement
Assuming Java supports it, you should be able to say (char)0x2345 to create a Unicode character.
If it expects a character value, you can use '\uXXXX', where the XXXX are four hex digits specifying the character; or similarly 0xXXXX. For a string, use double quotes instead of single quotes.

In the handler, you would have to ask the button for its label, and sent it to the text field. The best way to find out the necessary "magic words" is to read the API documentation (you can find it easily on java.sun.com).

This topic is closed to new replies.

Advertisement