J
Johannes Beekhuizen
Hello,
What does it mean and how can I solve it? When I try to compile the
application
"TaalKeuze" I get this error:
non-static method
setDefaultLocales(java.lang.String,java.lang.String,java.lang.String) cannot
be
referenced from a static context
The sources for TaalKeuze and the class Language are at the bottom of this
message.
I am very new at programming in Java, so it may be something trivial. But even
walking is difficult when you just start
Regards,
Hans.
jdh dot beekhuizen at duinheks dot xs4all dot nl
=== import ===
import javax.swing.*; import java.awt.*; import java.awt.event.*;
import nl.jaybee.*;
public class TaalKeuze extends JPanel {
JPanel languagePanel;
String selectedLanguage;
private JFrame controllingFrame;
public TaalKeuze(JFrame f) {
controllingFrame = f;
languagePanel = createLanguagePanel();
add(languagePanel);
}
private JPanel createLanguagePanel() {
selectedLanguage = Language.currentLanguageName;
JPanel p = new JPanel();
JComboBox languageCombo = new JComboBox(Language.languageList);
languageCombo.setEditable(false);
languageCombo.setAlignmentX(Component.LEFT_ALIGNMENT);
JLabel languageLabel = new JLabel("Taal: ");
languageLabel.setLabelFor(languageLabel);
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(languageLabel);
p.add(languageCombo);
p.setAlignmentX(Component.LEFT_ALIGNMENT);
return p;
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Relotec taalkeuze");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final TaalKeuze newContentPane = new TaalKeuze(frame);
newContentPane.setOpaque(true);
newContentPane.setLayout(new BoxLayout(newContentPane,
BoxLayout.Y_AXIS));
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
String language;
String country;
if (args.length == 2) {
language = new String(args[0]);
country = new String(args[1]);
}
else {
try {
String envLang = System.getenv("LANG");
language = envLang.substring(0,2);
country = envLang.substring(3,5);
}
catch (NullPointerException e) {
language = null;
country = null;
}
}
Language.setDefaultLocales (language, country, "TaalKeuze");
System.out.println(language);
System.out.println(country);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
=== tropmi ===
=== import ===
package nl.jaybee;
import java.util.*;
public class Language {
public String defaultLanguage,
defaultCountry;
public String currentLanguage,
currentCountry;
public Locale defaultLocale,
currentLocale;
public String currentLanguageName;
public ResourceBundle messageBundle;
public static final String[] languageList = {
"Nederlands",
"English",
"Deutsch",
"Français" };
public static final String[] languageCodes = {
"nl",
"en",
"de",
"fr" };
public static final String[] countryCodes = {
"NL",
"EN",
"DE",
"FR" };
public void setDefaultLocales (String inputLanguage,
String inputCountry,
String inputMessages ) {
if (inputLanguage == null ) {
defaultLanguage = languageCodes[0];
}
else {
defaultLanguage = inputLanguage;
}
if (inputCountry == null ) {
defaultCountry = countryCodes[0];;
}
else {
defaultCountry = inputCountry;
}
currentLanguage = defaultLanguage;
currentCountry = defaultCountry;
defaultLocale = new Locale(defaultLanguage, defaultCountry);
currentLocale = new Locale(defaultLanguage, defaultCountry);
setLanguageName ();
messageBundle =
ResourceBundle.getBundle(inputMessages, currentLocale);
}
public void setLanguageName () {
currentLanguageName = "unknown";
for (int ii = 0; ii < languageCodes.length; ii++) {
if ( currentLanguage == languageCodes[ii] ) {
currentLanguageName = languageList[ii];
}
}
}
}
=== tropmi ===
What does it mean and how can I solve it? When I try to compile the
application
"TaalKeuze" I get this error:
non-static method
setDefaultLocales(java.lang.String,java.lang.String,java.lang.String) cannot
be
referenced from a static context
The sources for TaalKeuze and the class Language are at the bottom of this
message.
I am very new at programming in Java, so it may be something trivial. But even
walking is difficult when you just start
Regards,
Hans.
jdh dot beekhuizen at duinheks dot xs4all dot nl
=== import ===
import javax.swing.*; import java.awt.*; import java.awt.event.*;
import nl.jaybee.*;
public class TaalKeuze extends JPanel {
JPanel languagePanel;
String selectedLanguage;
private JFrame controllingFrame;
public TaalKeuze(JFrame f) {
controllingFrame = f;
languagePanel = createLanguagePanel();
add(languagePanel);
}
private JPanel createLanguagePanel() {
selectedLanguage = Language.currentLanguageName;
JPanel p = new JPanel();
JComboBox languageCombo = new JComboBox(Language.languageList);
languageCombo.setEditable(false);
languageCombo.setAlignmentX(Component.LEFT_ALIGNMENT);
JLabel languageLabel = new JLabel("Taal: ");
languageLabel.setLabelFor(languageLabel);
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(languageLabel);
p.add(languageCombo);
p.setAlignmentX(Component.LEFT_ALIGNMENT);
return p;
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Relotec taalkeuze");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final TaalKeuze newContentPane = new TaalKeuze(frame);
newContentPane.setOpaque(true);
newContentPane.setLayout(new BoxLayout(newContentPane,
BoxLayout.Y_AXIS));
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
String language;
String country;
if (args.length == 2) {
language = new String(args[0]);
country = new String(args[1]);
}
else {
try {
String envLang = System.getenv("LANG");
language = envLang.substring(0,2);
country = envLang.substring(3,5);
}
catch (NullPointerException e) {
language = null;
country = null;
}
}
Language.setDefaultLocales (language, country, "TaalKeuze");
System.out.println(language);
System.out.println(country);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
=== tropmi ===
=== import ===
package nl.jaybee;
import java.util.*;
public class Language {
public String defaultLanguage,
defaultCountry;
public String currentLanguage,
currentCountry;
public Locale defaultLocale,
currentLocale;
public String currentLanguageName;
public ResourceBundle messageBundle;
public static final String[] languageList = {
"Nederlands",
"English",
"Deutsch",
"Français" };
public static final String[] languageCodes = {
"nl",
"en",
"de",
"fr" };
public static final String[] countryCodes = {
"NL",
"EN",
"DE",
"FR" };
public void setDefaultLocales (String inputLanguage,
String inputCountry,
String inputMessages ) {
if (inputLanguage == null ) {
defaultLanguage = languageCodes[0];
}
else {
defaultLanguage = inputLanguage;
}
if (inputCountry == null ) {
defaultCountry = countryCodes[0];;
}
else {
defaultCountry = inputCountry;
}
currentLanguage = defaultLanguage;
currentCountry = defaultCountry;
defaultLocale = new Locale(defaultLanguage, defaultCountry);
currentLocale = new Locale(defaultLanguage, defaultCountry);
setLanguageName ();
messageBundle =
ResourceBundle.getBundle(inputMessages, currentLocale);
}
public void setLanguageName () {
currentLanguageName = "unknown";
for (int ii = 0; ii < languageCodes.length; ii++) {
if ( currentLanguage == languageCodes[ii] ) {
currentLanguageName = languageList[ii];
}
}
}
}
=== tropmi ===