Pages

Ads 468x60px

Tuesday, March 12, 2013

Java: Show Urdu Text on Swing/AWT/SWT Components




This code will Show Urdu Text on Swing/AWT/SWT Components. You will have to use unicode values for Urdu characters.


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Factory extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;
JPanel bottomPanel = new JPanel();
JPanel centerPanel = new JPanel();

JLabel lblDate = new JLabel();
JLabel lblSale = new JLabel("\u06A9\u0644 \u0641\u0631\u0648\u062E\u062A :          ");
JLabel lblSpent = new JLabel("\u06A9\u0644 \u0631\u0642\u0645 \u062E\u0631\u06CC\u062F \u067E\u0631 \u062E\u0631 \u0686 :          ");
JLabel lblDailywages = new JLabel("\u062F\u06CC\u06C1\u0627 \u0691 \u06CC \u062F\u0627\u0631 \u06A9\u06CC \u062F\u06CC\u06C1\u0627 \u0691 \u06CC :          ");
JLabel lblOtherExpenses = new JLabel("\u062F\u0648\u0633\u0631\u06D2 \u0627\u062E\u0631\u0627\u062C\u0627\u062A :          ");
JLabel lblBankDeposit = new JLabel("\u0628\u06CC\u0646\u06A9 \u0645\u06CC\u06BA \u062C\u0645\u0639 :          ");

JTextField txtSale = new JTextField();
JTextField txtSpent = new JTextField();
JTextField txtDailywages = new JTextField();
JTextField txtOtherExpenses = new JTextField();
JTextField txtBankDeposit = new JTextField();

JButton btnSave = new JButton("\u0645\u062D\u0641\u0648\u0638 \u06A9\u0631 \u0648 ");

public Factory() {

lblSale.setFont(new Font("Segoe UI",1,16));
lblSpent.setFont(new Font("Segoe UI",1,16));
lblOtherExpenses.setFont(new Font("Segoe UI",1,16));
lblDailywages.setFont(new Font("Segoe UI",1,16));
lblBankDeposit.setFont(new Font("Segoe UI",1,16));
lblDate.setFont(new Font("Segoe UI",1,16));

txtSale.setPreferredSize(new Dimension(200, 30));
txtSpent.setPreferredSize(new Dimension(200, 30));
txtOtherExpenses.setPreferredSize(new Dimension(200, 30));
txtDailywages.setPreferredSize(new Dimension(200, 30));
txtBankDeposit.setPreferredSize(new Dimension(200, 30));

GridLayout layout = new GridLayout(5,1);
                layout.setVgap(8);
                centerPanel.setLayout(layout);
     
JPanel saleGridPanel = new JPanel(new GridLayout(1,2));
JPanel salePanel = new JPanel();
saleGridPanel.add(txtSale);
saleGridPanel.add(lblSale);
salePanel.add(saleGridPanel);
centerPanel.add(salePanel);

JPanel spentGridPanel = new JPanel(new GridLayout(1,2));
JPanel spentPanel = new JPanel();
spentGridPanel.add(txtSpent);
spentGridPanel.add(lblSpent);
spentPanel.add(spentGridPanel);
centerPanel.add(spentPanel);

JPanel wagesGridPanel = new JPanel(new GridLayout(1,2));
JPanel wagesPanel = new JPanel();
wagesGridPanel.add(txtDailywages);
wagesGridPanel.add(lblDailywages);
wagesPanel.add(wagesGridPanel);
centerPanel.add(wagesPanel);

JPanel expensesGridPanel = new JPanel(new GridLayout(1,2));
JPanel expensesPanel = new JPanel();
expensesGridPanel.add(txtOtherExpenses);
expensesGridPanel.add(lblOtherExpenses);
expensesPanel.add(expensesGridPanel);
centerPanel.add(expensesPanel);

JPanel bankGridPanel = new JPanel(new GridLayout(1,2));
JPanel bankPanel = new JPanel();
bankGridPanel.add(txtBankDeposit);
bankGridPanel.add(lblBankDeposit);
bankPanel.add(bankGridPanel);
centerPanel.add(bankPanel);

bottomPanel.add(btnSave);
btnSave.addActionListener(this);

setTitle("\u0641\u06CC\u06A9\u0679\u0631\u06CC ");
                setPreferredSize(new Dimension(500,600));
                setLayout(new BorderLayout());
getContentPane().add(centerPanel, BorderLayout.CENTER);
getContentPane().add(bottomPanel, BorderLayout.SOUTH);
                pack();
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                setVisible(true);
                setLocationRelativeTo(null);
}

public static void main(String[] args){
new Factory();
}

@Override
public void actionPerformed(ActionEvent e) {

if(e.getSource() == btnSave){
javax.swing.JOptionPane.showMessageDialog(null,"Saved", "Saved", javax.swing.JOptionPane.INFORMATION_MESSAGE);
}

}

}

References:
For Urdu text use Google Translator http://translate.google.com/
For Unicode Conversion http://rishida.net/tools/conversion/

No comments:

Post a Comment