473,788 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set language in other page once we did the changes in main page

2 New Member
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:


Expand|Select|Wrap|Line Numbers
  1.  import org.eclipse.swt.SWT;
  2. import org.eclipse.swt.widgets.Button;
  3. import org.eclipse.swt.widgets.Display;
  4. import org.eclipse.swt.widgets.Label;
  5. import org.eclipse.swt.widgets.Shell;
  6. import org.eclipse.swt.widgets.Text;
  7. import org.eclipse.swt.events.SelectionAdapter;
  8. import org.eclipse.swt.events.SelectionEvent;
  9.  
  10.  
  11. public class Trial {
  12.  
  13.     private static Text text;
  14.  
  15.     static String main = "main";
  16.     static String jadual = "jadual";
  17.     static String tarikh = "tarikh";
  18.     static String cari = "cari";
  19.  
  20.  
  21.     public static void main(String[] args) {
  22.         final Local local = new Local();
  23.         final Display display = Display.getDefault();
  24.         final Shell shell = new Shell();
  25.         shell.setSize(500, 375);
  26.         shell.open();
  27.         shell.setText(("")+local.bahasa(main));
  28.  
  29.         final Button pressButton = new Button(shell, SWT.NONE);
  30.         pressButton.setText(("")+local.bahasa(jadual));
  31.         pressButton.setBounds(64, 63, 77, 34);
  32.         pressButton.addSelectionListener(new SelectionAdapter() {
  33.             public void widgetSelected(SelectionEvent e) {
  34.  
  35.                         Trial2 trial = new Trial2();
  36.                         trial.run(display);
  37.                     }}
  38.                     );
  39.  
  40.         final Label tarikhLabel = new Label(shell, SWT.CENTER);
  41.         tarikhLabel.setText(("")+local.bahasa(tarikh));
  42.         tarikhLabel.setBounds(44, 197, 49, 22);
  43.  
  44.         text = new Text(shell, SWT.BORDER);
  45.         text.setBounds(99, 194, 80, 25);
  46.  
  47.  
  48.         final Button cariButton = new Button(shell, SWT.NONE);
  49.         cariButton.setText(("")+local.bahasa(cari));
  50.         cariButton.setBounds(204, 197, 44, 23);
  51.         cariButton.addSelectionListener(new SelectionAdapter() {
  52.             public void widgetSelected(SelectionEvent e) {
  53.                 Kalender2 kal = new Kalender2();
  54.                 kal.run(display);
  55.                 text.setText(""+kal.open());        
  56.                     }}
  57.                     );
  58.  
  59.         final Button bmButton = new Button(shell, SWT.RADIO);
  60.         bmButton.setText("bm");
  61.         bmButton.setBounds(75, 273, 83, 16);
  62.         bmButton.setSelection(true);
  63.         bmButton.addSelectionListener(new SelectionAdapter() {
  64.             public void widgetSelected(SelectionEvent e) {
  65.  
  66.                 shell.setText(("")+local.bahasa(main));
  67.                 pressButton.setText(("")+local.bahasa(jadual));
  68.                 tarikhLabel.setText((""+local.bahasa(tarikh)));
  69.                 cariButton.setText(("")+local.bahasa(cari));
  70.             }
  71.         }
  72.         );    
  73.  
  74.  
  75.  
  76.         final Button enButton = new Button(shell, SWT.RADIO);
  77.         enButton.setText("en");
  78.         enButton.setBounds(230, 273, 83, 16);
  79.         enButton.addSelectionListener(new SelectionAdapter() {
  80.             public void widgetSelected(SelectionEvent e) {
  81.  
  82.                 shell.setText(("")+local.english(main));
  83.                 pressButton.setText(("")+local.english(jadual));
  84.                 tarikhLabel.setText((""+local.english(tarikh)));
  85.                 cariButton.setText(("")+local.english(cari));
  86.             }
  87.         }
  88.         );
  89.  
  90.  
  91.  
  92.         shell.layout();
  93.         while (!shell.isDisposed()) {
  94.             if (!display.readAndDispatch())
  95.                 display.sleep();
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. the 2nd page:
  106.  
  107. import org.eclipse.swt.widgets.Display;
  108. import org.eclipse.swt.widgets.Shell;
  109. import org.eclipse.swt.SWT;
  110. import org.eclipse.swt.events.SelectionAdapter;
  111. import org.eclipse.swt.events.SelectionEvent;
  112. import org.eclipse.swt.widgets.Button;
  113.  
  114.  
  115. public class Trial2 {
  116.  
  117.     public static Display display2;
  118.  
  119.     static String main2 = "main2";
  120.     static String tutup = "tutup";
  121.  
  122.     static Local local = new Local();
  123.     static Trial trial = new Trial();
  124.  
  125.     public void run(Display display2){
  126.  
  127.         final Shell shell = new Shell();
  128.         shell.setSize(500, 375);
  129.  
  130.         //I want to set the language change according to first page 
  131.         shell.setText(("")+);
  132.  
  133.  
  134.         shell.open();
  135.  
  136.         final Button closeButton = new Button(shell, SWT.NONE);
  137.         closeButton.setText(("")+local.bahasa(tutup));
  138.         closeButton.setBounds(176, 246, 44, 23);
  139.         closeButton.addSelectionListener(new SelectionAdapter() {
  140.             public void widgetSelected(SelectionEvent e) {
  141.                   shell.close();
  142.  
  143.  
  144.                     }}
  145.                     );
  146.  
  147.         shell.layout();
  148.         while (!shell.isDisposed()) {
  149.             if (!display2.readAndDispatch())
  150.                 display2.sleep();
  151.         }
  152.  
  153.     }    
  154.  
  155. }
  156.  
  157.  
  158.  
  159. Class for setting language:
  160.  
  161. Local.java
  162.  
  163. import java.util.*;
  164.  
  165.  
  166. public class Local {
  167.  
  168.  
  169.     static Locale currentLocale;
  170.     static ResourceBundle messages;
  171.  
  172.  
  173.  
  174.     public Object bahasa(String key){
  175.          String p = key;
  176.         currentLocale = new Locale("bm", "MS");
  177.          messages = ResourceBundle.getBundle("MessagesBundle",currentLocale);
  178.         p=(String) messages.getString(key);
  179.          //messages.getString("main");
  180.          return p;
  181.     }             
  182.  
  183.  
  184.      public Object english(String key){
  185.          String en = key;
  186.          currentLocale = new Locale("en","USA");
  187.          messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
  188.         en = (String) messages.getString(key);
  189.          return en;
  190.      }            
  191.  
  192.  
  193. }
  194.  
  195.  
now i want to mention the changes in "shell.setText( )" in Trial2.java. how to set it.Thanks in advance
Sep 26 '07 #1
2 1816
Nepomuk
3,112 Recognized Expert Specialist
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:
Expand|Select|Wrap|Line Numbers
  1.  import org.eclipse.swt.SWT;
  2. import org.eclipse.swt.widgets.Button;
  3. import org.eclipse.swt.widgets.Display;
  4. import org.eclipse.swt.widgets.Label;
  5. import org.eclipse.swt.widgets.Shell;
  6. import org.eclipse.swt.widgets.Text;
  7. import org.eclipse.swt.events.SelectionAdapter;
  8. import org.eclipse.swt.events.SelectionEvent;
  9.  
  10.  
  11. public class Trial {
  12.  
  13.     private static Text text;
  14.  
  15.     static String main = "main";
  16.     static String jadual = "jadual";
  17.     static String tarikh = "tarikh";
  18.     static String cari = "cari";
  19.  
  20.  
  21.     public static void main(String[] args) {
  22.         final Local local = new Local();
  23.         final Display display = Display.getDefault();
  24.         final Shell shell = new Shell();
  25.         shell.setSize(500, 375);
  26.         shell.open();
  27.         shell.setText(("")+local.bahasa(main));
  28.  
  29.         final Button pressButton = new Button(shell, SWT.NONE);
  30.         pressButton.setText(("")+local.bahasa(jadual));
  31.         pressButton.setBounds(64, 63, 77, 34);
  32.         pressButton.addSelectionListener(new SelectionAdapter() {
  33.             public void widgetSelected(SelectionEvent e) {
  34.  
  35.                         Trial2 trial = new Trial2();
  36.                         trial.run(display);
  37.                     }}
  38.                     );
  39.  
  40.         final Label tarikhLabel = new Label(shell, SWT.CENTER);
  41.         tarikhLabel.setText(("")+local.bahasa(tarikh));
  42.         tarikhLabel.setBounds(44, 197, 49, 22);
  43.  
  44.         text = new Text(shell, SWT.BORDER);
  45.         text.setBounds(99, 194, 80, 25);
  46.  
  47.  
  48.         final Button cariButton = new Button(shell, SWT.NONE);
  49.         cariButton.setText(("")+local.bahasa(cari));
  50.         cariButton.setBounds(204, 197, 44, 23);
  51.         cariButton.addSelectionListener(new SelectionAdapter() {
  52.             public void widgetSelected(SelectionEvent e) {
  53.                 Kalender2 kal = new Kalender2();
  54.                 kal.run(display);
  55.                 text.setText(""+kal.open());        
  56.                     }}
  57.                     );
  58.  
  59.         final Button bmButton = new Button(shell, SWT.RADIO);
  60.         bmButton.setText("bm");
  61.         bmButton.setBounds(75, 273, 83, 16);
  62.         bmButton.setSelection(true);
  63.         bmButton.addSelectionListener(new SelectionAdapter() {
  64.             public void widgetSelected(SelectionEvent e) {
  65.  
  66.                 shell.setText(("")+local.bahasa(main));
  67.                 pressButton.setText(("")+local.bahasa(jadual));
  68.                 tarikhLabel.setText((""+local.bahasa(tarikh)));
  69.                 cariButton.setText(("")+local.bahasa(cari));
  70.             }
  71.         }
  72.         );    
  73.  
  74.  
  75.  
  76.         final Button enButton = new Button(shell, SWT.RADIO);
  77.         enButton.setText("en");
  78.         enButton.setBounds(230, 273, 83, 16);
  79.         enButton.addSelectionListener(new SelectionAdapter() {
  80.             public void widgetSelected(SelectionEvent e) {
  81.  
  82.                 shell.setText(("")+local.english(main));
  83.                 pressButton.setText(("")+local.english(jadual));
  84.                 tarikhLabel.setText((""+local.english(tarikh)));
  85.                 cariButton.setText(("")+local.english(cari));
  86.             }
  87.         }
  88.         );
  89.  
  90.  
  91.  
  92.         shell.layout();
  93.         while (!shell.isDisposed()) {
  94.             if (!display.readAndDispatch())
  95.                 display.sleep();
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. the 2nd page:
  106.  
  107. import org.eclipse.swt.widgets.Display;
  108. import org.eclipse.swt.widgets.Shell;
  109. import org.eclipse.swt.SWT;
  110. import org.eclipse.swt.events.SelectionAdapter;
  111. import org.eclipse.swt.events.SelectionEvent;
  112. import org.eclipse.swt.widgets.Button;
  113.  
  114.  
  115. public class Trial2 {
  116.  
  117.     public static Display display2;
  118.  
  119.     static String main2 = "main2";
  120.     static String tutup = "tutup";
  121.  
  122.     static Local local = new Local();
  123.     static Trial trial = new Trial();
  124.  
  125.     public void run(Display display2){
  126.  
  127.         final Shell shell = new Shell();
  128.         shell.setSize(500, 375);
  129.  
  130.         //I want to set the language change according to first page 
  131.         shell.setText(("")+);
  132.  
  133.  
  134.         shell.open();
  135.  
  136.         final Button closeButton = new Button(shell, SWT.NONE);
  137.         closeButton.setText(("")+local.bahasa(tutup));
  138.         closeButton.setBounds(176, 246, 44, 23);
  139.         closeButton.addSelectionListener(new SelectionAdapter() {
  140.             public void widgetSelected(SelectionEvent e) {
  141.                   shell.close();
  142.  
  143.  
  144.                     }}
  145.                     );
  146.  
  147.         shell.layout();
  148.         while (!shell.isDisposed()) {
  149.             if (!display2.readAndDispatch())
  150.                 display2.sleep();
  151.         }
  152.  
  153.     }    
  154.  
  155. }
  156.  
  157.  
  158.  
  159. Class for setting language:
  160.  
  161. Local.java
  162.  
  163. import java.util.*;
  164.  
  165.  
  166. public class Local {
  167.  
  168.  
  169.     static Locale currentLocale;
  170.     static ResourceBundle messages;
  171.  
  172.  
  173.  
  174.     public Object bahasa(String key){
  175.          String p = key;
  176.         currentLocale = new Locale("bm", "MS");
  177.          messages = ResourceBundle.getBundle("MessagesBundle",currentLocale);
  178.         p=(String) messages.getString(key);
  179.          //messages.getString("main");
  180.          return p;
  181.     }             
  182.  
  183.  
  184.      public Object english(String key){
  185.          String en = key;
  186.          currentLocale = new Locale("en","USA");
  187.          messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
  188.         en = (String) messages.getString(key);
  189.          return en;
  190.      }            
  191.  
  192.  
  193. }
  194.  
  195.  
now i want to mention the changes in "shell.setText( )" in Trial2.java. how to set it.Thanks in advance
Hi erag! Welcome to TSDN!

How about adding a setLanguage method like this:
Expand|Select|Wrap|Line Numbers
  1. public class Trial2 {
  2. private String language = "english";
  3. ...
  4. public void setLanguage(String language)
  5. {
  6.    this.language = language;
  7. }
  8.  
  9. public void run(Display display2){
  10. ...
  11.    //I want to set the language change according to first page 
  12.    if (language.equals("english"))
  13.       shell.setText("Hello!");
  14.    else if (language.equals("german"))
  15.       shell.setText("Hallo!");
  16.    else if (language.equals("french"))
  17.       shell.setText("Bonjour!");
  18.    else ...
  19. ...
  20. }
  21.  
You could, if you don't have many languages, use a char to define the language and use switch to set the Text correctly (because char is a basic Type, so you can use switch, but String isn't).

Greetings,
Nepomuk
Sep 26 '07 #2
erag
2 New Member
Thanks nepomuk but i still have problems....the thing is i want to know whether if i select a button from one class file n want to get that selection for the other class file, can do like that? it is because when i run the application i want to set the language using button in main class n when i open the other class, it automatically
set language followed by the button selection from other class..
can i do that in java swt? do i hv to import any library?
PLEASE answer coz i have no idea at all....THANKS.. ..
Sep 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1501
by: G25532 | last post by:
I have a form that contains a macro button which on clicking, opens a subform over the main form. I have in the macro "Where Condition" the following: =!! The subform has related fields as found in the main form for the selected QuoteNo (hence the use of the above expression. Once I have filled out the subform fields I would close the subform. Q: I can't make the main form reflect the changes made in the subform for the respective...
22
2881
by: Michael Nahas | last post by:
Antti & all interested, The draft description of my language to replace C is available at: http://nahas.is-a-geek.com/~mike/MyC.pdf I am a long time C programmer (I read the old testament in 1987) and I've tried to keep the spirit of C and make as few changes as possible. I was mostly driven by the bloat of C++ and, now, C99. I was also
134
8046
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've increasingly been using scripting languages (especially Python and Bourne shell) which offer the same speed and yet are far more simple and safe to use. I can no longer understand why anyone would willingly use C to program anything but the lowest...
2
1655
by: rjack | last post by:
I'm using VS 2005 Beta 2. In VS 2003, the Page directive in an aspx page has Language and CodeBehind attributes. You can have the language be different than the code behind file language. For instance, you can have Language="vb" CodeBehind="classA.cs" In VS 2005, the CodeBehind attribute seems to have been replaced with
669
26226
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
3
5129
by: joelpollock | last post by:
I'm having trouble continuously page numbering a large report in MS Access. The report is made up of three separate Access reports which I join together at the end. In the past I have opened the reports and viewed them to see how long they are then go in and manually type the page number and total page number. I am aware of the and lines of code but this resets with each new report.
46
3032
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented language. When I read things like "... C++ is an evolution of C ..." or "... C is a subset of C++ ..." I tend to believe that I will have to learn C+ + sooner or later. It sounds like C++ is the future and C is the past (and will be no longer...
84
8598
by: aarklon | last post by:
Hi all, I found an interesting article here:- http://en.wikipedia.org/wiki/Criticism_of_the_C_programming_language well what do you guys think of this article....??? Is it constructive criticism that needs to be appreciated always...???
22
2607
by: ben mitch | last post by:
Hi I hope you'll see this cross-post (c/c++) as appropriate. I also admit immediately that the question *may* turn out to be compiler-/os-specific, in which case I apologize. But I wonder if there's an underlying truth. We are writing a (cross-platform) 'framework' application (in C++, as it happens) that allows users to author 'plugins' (as shared library modules). Since the lifetime of plugins is expected to be long, and the
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10112
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.