/* * [TestHebrew.java] * * Summary: example use of Hebrew in Swing. Test ability to display Hebrew characters on the screen. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-01-01 initial version */ package com.mindprod.example; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.UIManager; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Graphics; import static java.lang.System.*; /** * example use of Hebrew in Swing. Test ability to display Hebrew characters on the screen. *

* * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-01-01 initial version * @noinspection WeakerAccess * @since 2009-01-01 */ public final class TestHebrew { /** * word shalom encoded in order Shin (sh) Lamed (L) Vav (O) Mem (M) terminal. They should be rendered in reverse * order. */ private static final String shalom = "\u05E9\u05DC\u05D5\u05DD"; /** * tests Hebrew on the console. */ public static void consoleTest() { // just prints four useless question marks. out.println( shalom ); } /** * Ttests Hebrew on the console public static void consoleTest () { // just prints four useless question marks. * out.println( shalom ); } * * @param args not used. */ public static void main( String[] args ) { // In Eclipse, just prints four question marks. // In proper environment should see four Hebrew characters. consoleTest(); SwingUtilities.invokeLater( new TestJFrame() ); } /** * Component that tests drawString in Hebrew. */ static final class DrawStringComponent extends JPanel { /** * constructor. */ DrawStringComponent() { // force this component to be a 100x100 square Dimension d = new Dimension( 100, 100 ); this.setPreferredSize( d ); this.setMinimumSize( d ); this.setMaximumSize( d ); } /** * does drawing. * * @param g where to paint. */ public void paintComponent( Graphics g ) { // this gets background cleared super.paintComponent( g ); g.setColor( this.getForeground() ); // x,y is bottom left corner of text g.drawString( shalom, 50, 50 ); } // end paintComponent } // DrawStringComponent /** * nested static class to display a JFrame. */ static final class TestJFrame implements Runnable { /** * height of frame in pixels. */ private static final int height = 200; /** * width of frame in pixels. */ private static final int width = 300; /** * Date this version of the program was released to the world to see. * * @noinspection UnusedDeclaration */ private static final String RELEASE_DATE = "2006-03-06"; /** * title for frame. */ private static final String TITLE_STRING = "Hebrew JFrame Demo"; /** * program version. */ private static final String VERSION_STRING = "1.0"; /** * fire up a JFrame on the Swing thread. Attempt to Suppress warning that Sun may decommit WindowsLookAndFeel. */ @SuppressWarnings( "all" ) public void run() { try { // windows look and feel UIManager.setLookAndFeel( new com.sun.java.swing.plaf.windows.WindowsLookAndFeel() ); } catch ( Exception e ) { err.println(); e.printStackTrace( err ); err.println( "Problem setting look and feel" ); err.println(); } JFrame.setDefaultLookAndFeelDecorated( true ); final JFrame jframe = new JFrame( TITLE_STRING + " " + VERSION_STRING ); jframe.setSize( width, height ); jframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); // need bigger than usual fonts to show the intricate glyphs Font biggerFont = new Font( "Dialog", Font.PLAIN, 16 ); Container contentPane = jframe.getContentPane(); contentPane.setLayout( new FlowLayout() ); // TEST JLabel JLabel label = new JLabel( shalom ); label.setFont( biggerFont ); label.setBackground( Color.WHITE ); contentPane.add( label ); // TEST JTextField JTextField textField = new JTextField( shalom ); textField.setFont( biggerFont ); textField.setBackground( Color.WHITE ); contentPane.add( textField ); // TEST JTextArea JTextArea textArea = new JTextArea( shalom, 2, 5 ); textArea.setFont( biggerFont ); textArea.setBackground( Color.WHITE ); contentPane.add( textArea ); // TEST drawString DrawStringComponent draw = new DrawStringComponent(); draw.setFont( biggerFont ); draw.setBackground( Color.WHITE ); contentPane.add( draw ); jframe.validate(); jframe.setVisible( true ); } } // end TestJFrame } // end TesTHebrew