import java.awt.event.*;
import java.util.*;
import java.io.*;
final public class l10n extends WindowAdapter
implements ActionListener {
private Frame mainFrame;
//Menu items - file -
private Menu fileMenu;
private MenuItem exitMI;
private MenuItem openMI;
private MenuItem saveMI;
private MenuItem saveasMI;
private MenuItem printMI;
private MenuItem closeMI;
//Menu items - help -
private Menu helpMenu;
private MenuItem aboutMI;
// Panel
private Panel mainPanel;
//Window Size
private int windowWidth = 240;
private int windowHeight = 320;
private int titleHeight = 13;
private int taskbarHeight = 19;
private int margin = 2;
public l10n (String[] menu_prin, String[] menu_arch, String[]
menu_ayuda) {
// Create frame
mainFrame = new Frame("Ejemplo_Localizacion");
// Create menu bar
MenuBar mb = new MenuBar();
mainFrame.setMenuBar(mb);
//File Menu
//String menulabel = ("Exit");
fileMenu = new Menu(menu_prin[0]);
openMI = new MenuItem(menu_arch[0]);
saveMI = new MenuItem(menu_arch[1]);
saveasMI = new MenuItem(menu_arch[2]);
printMI = new MenuItem(menu_arch[3]);
closeMI = new MenuItem(menu_arch[4]);
exitMI = new MenuItem(menu_arch[5]); //"Exit");
exitMI.addActionListener(this);
fileMenu.add(openMI);
fileMenu.add(saveMI);
fileMenu.add(saveasMI);
fileMenu.add(printMI);
fileMenu.add(closeMI);
fileMenu.add(exitMI);
mb.add(fileMenu);
//Help Menu
helpMenu = new Menu(menu_prin[1]);
aboutMI = new MenuItem(menu_ayuda[0]); //"Acerca");
aboutMI.addActionListener(this);
helpMenu.add(aboutMI);
mb.add(helpMenu);
//setup panel
mainPanel = new Panel();
mainFrame.add(mainPanel);
mainPanel.setVisible(true);
// setup frame
mainFrame.addWindowListener(this);
mainFrame.setSize((windowWidth - margin + 2 ), (windowHeight - titleHeight - taskbarHeight - margin * 2 ));
mainFrame.setVisible( true );
mainFrame.setResizable(false);
}
// Event handling
// windows event
public void windowClosing (WindowEvent we) {
if(we.getWindow() == mainFrame) {
System.exit(0);
}
}
// action event
public void actionPerformed (ActionEvent ae) {
Object o = ae.getSource();
if (o instanceof MenuItem) {
MenuItem mi = (MenuItem)o;
if (mi == exitMI) {
System.exit(0);
} else if (mi ==aboutMI) {
new l10nAbout();
}
}
}
public static String locale_en_Z() throws IOException
{
StringTokenizer st1;
String quote = "";
FileReader infile = new FileReader("locale.conf");
BufferedReader buff = new BufferedReader(infile);
boolean eof = false;
boolean siguiente = false;
while( !eof ) {
String line = buff.readLine();
if( line == null )
eof = true;
else {
if( siguiente ) {
quote = line;
siguiente = false;
}
line.trim();
if( line.equals("[Language]") ) siguiente = true;
}
}
buff.close();
st1 = new StringTokenizer( quote, "=");
st1.nextToken();
return st1.nextToken();
}
public static void main (String args[]) {
String[][] menu_prin = { {"Archivo","Ayuda"}, {"File","Help"},
{"Akte","Hilfe"} };
String[][] menu_arch = { {"Abrir","Guardar","Guardar Como",
"Imprimir","Cerrar","Salir"},
{"Open","Save","Save as",
"Print","Close","Exit"},
{"Geoffnet","AuBer","AuBer wie",
"Druck","Ende","Auf Wiedersehen"} };
String[][] menu_ayuda = { {"Acerca"}, {"About"}, {"Uber"} };
int arreglo; // 0 = sp, 1 = en, 2 = de
String localiza = "sp";
try { localiza = locale_en_Z(); }
catch (IOException e) {import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
final public class l10n extends WindowAdapter
implements ActionListener {
private Frame mainFrame;
//Menu items - file -
private Menu fileMenu;
private MenuItem exitMI;
private MenuItem openMI;
private MenuItem saveMI;
private MenuItem saveasMI;
private MenuItem printMI;
private MenuItem closeMI;
//Menu items - help -
private Menu helpMenu;
private MenuItem aboutMI;
// Panel
private Panel mainPanel;
//Window Size
private int windowWidth = 240;
private int windowHeight = 320;
private int titleHeight = 13;
private int taskbarHeight = 19;
private int margin = 2;
public l10n (String[] menu_prin, String[] menu_arch, String[]
menu_ayuda) {
// Create frame
mainFrame = new Frame("Ejemplo_Localizacion");
// Create menu bar
MenuBar mb = new MenuBar();
mainFrame.setMenuBar(mb);
//File Menu
//String menulabel = ("Exit");
fileMenu = new Menu(menu_prin[0]);
openMI = new MenuItem(menu_arch[0]);
saveMI = new MenuItem(menu_arch[1]);
saveasMI = new MenuItem(menu_arch[2]);
printMI = new MenuItem(menu_arch[3]);
closeMI = new MenuItem(menu_arch[4]);
exitMI = new MenuItem(menu_arch[5]); //"Exit");
exitMI.addActionListener(this);
fileMenu.add(openMI);
fileMenu.add(saveMI);
fileMenu.add(saveasMI);
fileMenu.add(printMI);
fileMenu.add(closeMI);
fileMenu.add(exitMI);
mb.add(fileMenu);
//Help Menu
helpMenu = new Menu(menu_prin[1]);
aboutMI = new MenuItem(menu_ayuda[0]); //"Acerca");
aboutMI.addActionListener(this);
helpMenu.add(aboutMI);
mb.add(helpMenu);
//setup panel
mainPanel = new Panel();
mainFrame.add(mainPanel);
mainPanel.setVisible(true);
// setup frame
mainFrame.addWindowListener(this);
mainFrame.setSize((windowWidth - margin + 2 ), (windowHeight - titleHeight - taskbarHeight - margin * 2 ));
mainFrame.setVisible( true );
mainFrame.setResizable(false);
}
// Event handling
// windows event
public void windowClosing (WindowEvent we) {
if(we.getWindow() == mainFrame) {
System.exit(0);
}
}
// action event
public void actionPerformed (ActionEvent ae) {
Object o = ae.getSource();
if (o instanceof MenuItem) {
MenuItem mi = (MenuItem)o;
if (mi == exitMI) {
System.exit(0);
} else if (mi ==aboutMI) {
new l10nAbout();
}
}
}
public static String locale_en_Z() throws IOException
{
StringTokenizer st1;
String quote = "";
FileReader infile = new FileReader("locale.conf");
BufferedReader buff = new BufferedReader(infile);
boolean eof = false;
boolean siguiente = false;
while( !eof ) {
String line = buff.readLine();
if( line == null )
eof = true;
else {
if( siguiente ) {
quote = line;
siguiente = false;
}
line.trim();
if( line.equals("[Language]") ) siguiente = true;
}
}
buff.close();
st1 = new StringTokenizer( quote, "=");
st1.nextToken();
return st1.nextToken();
}
public static void main (String args[]) {
String[][] menu_prin = { {"Archivo","Ayuda"}, {"File","Help"},
{"Akte","Hilfe"} };
String[][] menu_arch = { {"Abrir","Guardar","Guardar Como",
"Imprimir","Cerrar","Salir"},
{"Open","Save","Save as",
"Print","Close","Exit"},
{"Geoffnet","AuBer","AuBer wie",
"Druck","Ende","Auf Wiedersehen"} };
String[][] menu_ayuda = { {"Acerca"}, {"About"}, {"Uber"} };
int arreglo; // 0 = sp, 1 = en, 2 = de
String localiza = "sp";
try { localiza = locale_en_Z(); }
catch (IOException e) {
System.err.println(e);
return;
}
localiza = localiza.trim();
if( args.length == 1 ) localiza = args[0];
arreglo = 0; // sp por defecto
if(localiza.equals("sp")) arreglo = 0;
else if(localiza.equals("en")) arreglo = 1;
else if(localiza.equals("de")) arreglo = 2;
l10n foo = new l10n(menu_prin[arreglo], menu_arch[arreglo],
menu_ayuda[arreglo]);
//System.err.println( args[0] );
}
System.err.println(e);
return;
}
localiza = localiza.trim();
if( args.length == 1 ) localiza = args[0];
arreglo = 0; // sp por defecto
if(localiza.equals("sp")) arreglo = 0;
else if(localiza.equals("en")) arreglo = 1;
else if(localiza.equals("de")) arreglo = 2;
l10n foo = new l10n(menu_prin[arreglo], menu_arch[arreglo],
menu_ayuda[arreglo]);
//System.err.println( args[0] );
}