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.
* <p/>
*
* @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()
{
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 )
{
consoleTest();
SwingUtilities.invokeLater( new TestJFrame() );
}
/**
* Component that tests drawString in Hebrew.
*/
static final class DrawStringComponent extends JPanel
{
/**
* constructor.
*/
DrawStringComponent()
{
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 )
{
super.paintComponent( g );
g.setColor( this.getForeground() );
g.drawString( shalom, 50, 50 );
}
}
/**
* 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
{
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 );
Font biggerFont = new Font( "Dialog", Font.PLAIN, 16 );
Container contentPane = jframe.getContentPane();
contentPane.setLayout( new FlowLayout() );
JLabel label = new JLabel( shalom );
label.setFont( biggerFont );
label.setBackground( Color.WHITE );
contentPane.add( label );
JTextField textField = new JTextField( shalom );
textField.setFont( biggerFont );
textField.setBackground( Color.WHITE );
contentPane.add( textField );
JTextArea textArea = new JTextArea( shalom, 2, 5 );
textArea.setFont( biggerFont );
textArea.setBackground( Color.WHITE );
contentPane.add( textArea );
DrawStringComponent draw = new DrawStringComponent();
draw.setFont( biggerFont );
draw.setBackground( Color.WHITE );
contentPane.add( draw );
jframe.validate();
jframe.setVisible( true );
}
}
}