Hi im newbie to java, and i want to set the language change according to main page..how to create it?
here is my coding:
main page:
[CODE=java] import org.eclipse.swt .SWT;
import org.eclipse.swt .widgets.Button ;
import org.eclipse.swt .widgets.Displa y;
import org.eclipse.swt .widgets.Label;
import org.eclipse.swt .widgets.Shell;
import org.eclipse.swt .widgets.Text;
import org.eclipse.swt .events.Selecti onAdapter;
import org.eclipse.swt .events.Selecti onEvent;
public class Trial {
private static Text text;
static String main = "main";
static String jadual = "jadual";
static String tarikh = "tarikh";
static String cari = "cari";
public static void main(String[] args) {
final Local local = new Local();
final Display display = Display.getDefa ult();
final Shell shell = new Shell();
shell.setSize(5 00, 375);
shell.open();
shell.setText(( "")+local.bahas a(main));
final Button pressButton = new Button(shell, SWT.NONE);
pressButton.set Text(("")+local .bahasa(jadual) );
pressButton.set Bounds(64, 63, 77, 34);
pressButton.add SelectionListen er(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
Trial2 trial = new Trial2();
trial.run(displ ay);
}}
);
final Label tarikhLabel = new Label(shell, SWT.CENTER);
tarikhLabel.set Text(("")+local .bahasa(tarikh) );
tarikhLabel.set Bounds(44, 197, 49, 22);
text = new Text(shell, SWT.BORDER);
text.setBounds( 99, 194, 80, 25);
final Button cariButton = new Button(shell, SWT.NONE);
cariButton.setT ext(("")+local. bahasa(cari));
cariButton.setB ounds(204, 197, 44, 23);
cariButton.addS electionListene r(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
Kalender2 kal = new Kalender2();
kal.run(display );
text.setText("" +kal.open());
}}
);
final Button bmButton = new Button(shell, SWT.RADIO);
bmButton.setTex t("bm");
bmButton.setBou nds(75, 273, 83, 16);
bmButton.setSel ection(true);
bmButton.addSel ectionListener( new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.setText(( "")+local.bahas a(main));
pressButton.set Text(("")+local .bahasa(jadual) );
tarikhLabel.set Text((""+local. bahasa(tarikh)) );
cariButton.setT ext(("")+local. bahasa(cari));
}
}
);
final Button enButton = new Button(shell, SWT.RADIO);
enButton.setTex t("en");
enButton.setBou nds(230, 273, 83, 16);
enButton.addSel ectionListener( new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.setText(( "")+local.engli sh(main));
pressButton.set Text(("")+local .english(jadual ));
tarikhLabel.set Text((""+local. english(tarikh) ));
cariButton.setT ext(("")+local. english(cari));
}
}
);
shell.layout();
while (!shell.isDispo sed()) {
if (!display.readA ndDispatch())
display.sleep() ;
}
}
}
the 2nd page:
import org.eclipse.swt .widgets.Displa y;
import org.eclipse.swt .widgets.Shell;
import org.eclipse.swt .SWT;
import org.eclipse.swt .events.Selecti onAdapter;
import org.eclipse.swt .events.Selecti onEvent;
import org.eclipse.swt .widgets.Button ;
public class Trial2 {
public static Display display2;
static String main2 = "main2";
static String tutup = "tutup";
static Local local = new Local();
static Trial trial = new Trial();
public void run(Display display2){
final Shell shell = new Shell();
shell.setSize(5 00, 375);
//I want to set the language change according to first page
shell.setText(( "")+);
shell.open();
final Button closeButton = new Button(shell, SWT.NONE);
closeButton.set Text(("")+local .bahasa(tutup)) ;
closeButton.set Bounds(176, 246, 44, 23);
closeButton.add SelectionListen er(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.close();
}}
);
shell.layout();
while (!shell.isDispo sed()) {
if (!display2.read AndDispatch())
display2.sleep( );
}
}
}
Class for setting language:
Local.java
import java.util.*;
public class Local {
static Locale currentLocale;
static ResourceBundle messages;
public Object bahasa(String key){
String p = key;
currentLocale = new Locale("bm", "MS");
messages = ResourceBundle. getBundle("Mess agesBundle",cur rentLocale);
p=(String) messages.getStr ing(key);
//messages.getStr ing("main");
return p;
}
public Object english(String key){
String en = key;
currentLocale = new Locale("en","US A");
messages = ResourceBundle. getBundle("Mess agesBundle", currentLocale);
en = (String) messages.getStr ing(key);
return en;
}
}
[/CODE]
now i want to mention the changes in "shell.setText( )" in Trial2.java. how to set it.Thanks in advance
here is my coding:
main page:
[CODE=java] import org.eclipse.swt .SWT;
import org.eclipse.swt .widgets.Button ;
import org.eclipse.swt .widgets.Displa y;
import org.eclipse.swt .widgets.Label;
import org.eclipse.swt .widgets.Shell;
import org.eclipse.swt .widgets.Text;
import org.eclipse.swt .events.Selecti onAdapter;
import org.eclipse.swt .events.Selecti onEvent;
public class Trial {
private static Text text;
static String main = "main";
static String jadual = "jadual";
static String tarikh = "tarikh";
static String cari = "cari";
public static void main(String[] args) {
final Local local = new Local();
final Display display = Display.getDefa ult();
final Shell shell = new Shell();
shell.setSize(5 00, 375);
shell.open();
shell.setText(( "")+local.bahas a(main));
final Button pressButton = new Button(shell, SWT.NONE);
pressButton.set Text(("")+local .bahasa(jadual) );
pressButton.set Bounds(64, 63, 77, 34);
pressButton.add SelectionListen er(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
Trial2 trial = new Trial2();
trial.run(displ ay);
}}
);
final Label tarikhLabel = new Label(shell, SWT.CENTER);
tarikhLabel.set Text(("")+local .bahasa(tarikh) );
tarikhLabel.set Bounds(44, 197, 49, 22);
text = new Text(shell, SWT.BORDER);
text.setBounds( 99, 194, 80, 25);
final Button cariButton = new Button(shell, SWT.NONE);
cariButton.setT ext(("")+local. bahasa(cari));
cariButton.setB ounds(204, 197, 44, 23);
cariButton.addS electionListene r(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
Kalender2 kal = new Kalender2();
kal.run(display );
text.setText("" +kal.open());
}}
);
final Button bmButton = new Button(shell, SWT.RADIO);
bmButton.setTex t("bm");
bmButton.setBou nds(75, 273, 83, 16);
bmButton.setSel ection(true);
bmButton.addSel ectionListener( new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.setText(( "")+local.bahas a(main));
pressButton.set Text(("")+local .bahasa(jadual) );
tarikhLabel.set Text((""+local. bahasa(tarikh)) );
cariButton.setT ext(("")+local. bahasa(cari));
}
}
);
final Button enButton = new Button(shell, SWT.RADIO);
enButton.setTex t("en");
enButton.setBou nds(230, 273, 83, 16);
enButton.addSel ectionListener( new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.setText(( "")+local.engli sh(main));
pressButton.set Text(("")+local .english(jadual ));
tarikhLabel.set Text((""+local. english(tarikh) ));
cariButton.setT ext(("")+local. english(cari));
}
}
);
shell.layout();
while (!shell.isDispo sed()) {
if (!display.readA ndDispatch())
display.sleep() ;
}
}
}
the 2nd page:
import org.eclipse.swt .widgets.Displa y;
import org.eclipse.swt .widgets.Shell;
import org.eclipse.swt .SWT;
import org.eclipse.swt .events.Selecti onAdapter;
import org.eclipse.swt .events.Selecti onEvent;
import org.eclipse.swt .widgets.Button ;
public class Trial2 {
public static Display display2;
static String main2 = "main2";
static String tutup = "tutup";
static Local local = new Local();
static Trial trial = new Trial();
public void run(Display display2){
final Shell shell = new Shell();
shell.setSize(5 00, 375);
//I want to set the language change according to first page
shell.setText(( "")+);
shell.open();
final Button closeButton = new Button(shell, SWT.NONE);
closeButton.set Text(("")+local .bahasa(tutup)) ;
closeButton.set Bounds(176, 246, 44, 23);
closeButton.add SelectionListen er(new SelectionAdapte r() {
public void widgetSelected( SelectionEvent e) {
shell.close();
}}
);
shell.layout();
while (!shell.isDispo sed()) {
if (!display2.read AndDispatch())
display2.sleep( );
}
}
}
Class for setting language:
Local.java
import java.util.*;
public class Local {
static Locale currentLocale;
static ResourceBundle messages;
public Object bahasa(String key){
String p = key;
currentLocale = new Locale("bm", "MS");
messages = ResourceBundle. getBundle("Mess agesBundle",cur rentLocale);
p=(String) messages.getStr ing(key);
//messages.getStr ing("main");
return p;
}
public Object english(String key){
String en = key;
currentLocale = new Locale("en","US A");
messages = ResourceBundle. getBundle("Mess agesBundle", currentLocale);
en = (String) messages.getStr ing(key);
return en;
}
}
[/CODE]
now i want to mention the changes in "shell.setText( )" in Trial2.java. how to set it.Thanks in advance
Comment