Back | Reverse | Quick Reply | Post Reply |

Japanese in Java
Link | by ChaosDevil on 2008-04-09 16:52:15
Okay, so I'm using Jbuilder and would like to display Japanese Characters in the console. The following is the only way I could manage to get it to display albeit it only displays in a popup:
-------------
---------------------
import java.util.*;
import java.io.*;
import javax.swing.*;

public class japanese_test_class {
public static void main(String[] args)
throws IOException, FileNotFoundException {
PrintWriter output = new PrintWriter("temp.txt", "Cp933");
System.out.println("ひらがな の けんさ です。\u3041"); //Testing hiragana and unicode... both failed.
String test = "ひらがな の けんさ \u3041";// Testing if String will contain it... Failed
System.out.println(test);
//only the following popup displays the text...
output.println( "\u3041 おい! レイ です。 よろしく おねがいします。Hey There! Rey Here. Pleasure to make your acquaintance." );
output.println( "Hey There! Rey Here. Pleasure to make your acquaintance." );
output.close();

Scanner input = new Scanner(new File("temp.txt"), "Cp933");
JOptionPane.showMessageDialog(null, input.nextLine());
}
}
-----------------------
--------------

I would like to have the Japanese display using system.out.println("xxxx") and not have it as a pop up.
(This is my first Java Class but I'm hoping to have my final project be a program that aids students in learning Japanese Characters. I'm using OS X 10.5.2)

If you have suggestions for a different IDE that's Leopard Compatible please do suggest.

Thank you VERY VERY MUCH in advance!! ^_^


Re: Japanese in Java
Link | by gendou on 2008-04-09 18:29:02 (edited 2008-04-09 18:32:17)
Try this:
System.setOut(new PrintStream(System.out, true, "UTF8"));



Re: Japanese in Java
Link | by ChaosDevil on 2008-04-09 19:08:11
Hmmm I've used your tip and it did infact alter the text but it still only displays gibberish (Before it was all "?" characters, now they're all random symbols but not actual Japanese).

I'm using a Japanese compatible font (Hiragino Mincho ProN)
And have tried all the encodings I have available.

I can see that what you gave me is a step in the right direction... but It's not quite what I'm looking for. Perhaps you have a slightly different setup from me and this produced the desired result. Would you mind explaining what setup you use, (if you actually have used Japanese text in java before that is) :-)

Thanks again


Re: Japanese in Java
Link | by gendou on 2008-04-09 19:20:50 (edited 2008-04-09 19:21:17)
It may be that your Java source file its self is not UTF8 encoded.
You might think about having the Japanese strings loaded from a data file on startup.


Re: Japanese in Java
Link | by ChaosDevil on 2008-04-20 14:11:09
Well I was able to make the Japanese display Properly (All I did was make a new user account on my computer with Japanese as the default language) That seemed to be the easiest way to accomplish it. Anyway, Now that I have that out of the way I have a more basic question (remember this is my first programing class)

How can I change the size of the font.

For Example:

月 (200 pt. font size)
[User input] (60 pt. font size)

Would I need to import anything in particular or is java.io enough?


Re: Japanese in Java
Link | by gendou on 2008-04-20 14:16:00 (edited 2008-04-20 14:16:13)
To change font size, you will need to use graphical display instead of java.io.


Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2024 Gendou | Terms of Use | Page loaded in 0.0025 seconds at 2024-12-28 19:36:54