| | |
Display unicode character
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 103
Reputation:
Solved Threads: 14
I am trying to write a program to display the unicode character when a user enters a unicode character code.
ex: If the user enters: "\u00C3" in the textfield, I want to display a capital "A" with a tilda (~) over the top of it. Here's my code so far:
Main.java
ex: If the user enters: "\u00C3" in the textfield, I want to display a capital "A" with a tilda (~) over the top of it. Here's my code so far:
Main.java
Java Syntax (Toggle Plain Text)
import javax.swing.*; import java.awt.event.*; public class Main { private static JTextField inputTextBox; private static JLabel displayLbl; public static void main(String s[]) { //create new frame JFrame frame = new JFrame("Unicode Characters"); //add window listener frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); //create new JPanel JPanel contentPane = new JPanel(); frame.setContentPane(contentPane); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.setBorder(BorderFactory.createEmptyBorder(100,100,100,100)); inputTextBox = new JTextField(JTextField.CENTER); displayLbl = new JLabel(); //this sets the text to what the user would enter inputTextBox.setText("\\u00C3"); JButton showBtn = new JButton(); showBtn.setText("Show"); displayLbl.setText(" "); //add objects to JPanel contentPane.add(inputTextBox); contentPane.add(displayLbl); contentPane.add(showBtn); frame.pack(); frame.setVisible(true); //add listener for button showBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { //do something, in this case we call method //showBtnActionPerformed showBtnActionPerformed(evt); } }); } //main private static void showBtnActionPerformed (java.awt.event.ActionEvent evt){ String userText; char myUnicodeChar; //get user inputed unicode character ex: \u00C3 userText = inputTextBox.getText(); //display character for unicode code displayLbl.setText("" + userText); //the line below displays what I want to display //but I want the user to be able to enter "\u00C3" //and then I want to display the character that is //represented by it. //displayLbl.setText("\u00C3"); } //showBtnActionPerformed }
Last edited by cgeier; Oct 21st, 2009 at 6:05 pm.
•
•
Join Date: Sep 2008
Posts: 1,568
Reputation:
Solved Threads: 196
1
#2 Oct 21st, 2009
Java Syntax (Toggle Plain Text)
Character ch = new Character('\u00C3'); char prim = ch.charValue(); System.out.println(prim);
Something I just learned how to do after a quick look up in the Character class documentation. I'm sure if you read some stuff yourself and try some things out, you'll find many more useful methods. http://java.sun.com/j2se/1.5.0/docs/...Character.html
Last edited by BestJewSinceJC; Oct 21st, 2009 at 11:37 pm.
Out.
•
•
Join Date: Oct 2008
Posts: 103
Reputation:
Solved Threads: 14
0
#4 Oct 25th, 2009
I was able to find a solution on another site.
http://www.velocityreviews.com/FORUM...va-string.html
Here is the solution:
http://www.velocityreviews.com/FORUM...va-string.html
Here is the solution:
Java Syntax (Toggle Plain Text)
private static String unescape(String s) { int i=0,len=s.length(); char c; StringBuffer sb = new StringBuffer(len); while (i<len) { c = s.charAt(i++); if (c=='\\') { if (i<len) { c = s.charAt(i++); if (c=='u') { c = (char) Integer.parseInt(s.substring(i,i+4),16); i += 4; } // add other cases here as desired... } } // fall through: \ escapes itself, quotes any character but u sb.append(c); } return sb.toString(); }
![]() |
Similar Threads
- Strip u' Unicode character from List (Python)
- VB6 Menu Bar - display in unicode? (Visual Basic 4 / 5 / 6)
- Unicode - character printing probelm (Java)
- Display a single unicode character? (Pascal and Delphi)
Other Threads in the Java Forum
- Previous Thread: Another iText question...
- Next Thread: Urgent! I need to teach someone 'special'
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






