SHARE
TWEET

Untitled

a guest Feb 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class GermanTextField extends JTextField implements KeyListener{
  2.   public GermanTextField() {
  3.     init();
  4.   }
  5.  
  6.   // other constructors ...
  7.  
  8.   private void init() {
  9.     addKeyListener(this);
  10.   }
  11.  
  12.  
  13.  
  14.   public void keyPressed(KeyEvent arg0) {}
  15.  
  16.  
  17.   public void keyReleased(KeyEvent arg0) {}
  18.  
  19.  
  20.   public void keyTyped(KeyEvent evt) {
  21.     if(evt.getKeyChar() == 'o' && evt.isAltGraphDown()){
  22.       setText(getText() + "ö");
  23.       evt.consume();
  24.     }
  25.   }
  26.  
  27.  
  28. }
  29.    
  30. ?
  31. ?
  32. ?
  33. ?
  34.    
  35. public void keyTyped(KeyEvent evt) {
  36.     if(evt.getKeyChar() == 'ó'){
  37.       setText(getText() + "ö");
  38.       evt.consume();
  39.     }
  40.   }
  41.    
  42. package daswort.gui;
  43.  
  44. import java.awt.event.KeyEvent;
  45. import java.awt.event.KeyListener;
  46. import java.util.HashMap;
  47. import java.util.Map;
  48.  
  49. import javax.swing.JTextField;
  50.  
  51. public class GermanTextField extends JTextField implements KeyListener{
  52.  
  53.   private Map<Integer, String> transform =
  54.       new HashMap<Integer, String>();
  55.  
  56.   public GermanTextField() {
  57.     init();
  58.   }
  59.  
  60.  
  61.   public GermanTextField(int columns) {
  62.     super(columns);
  63.     init();
  64.   }
  65.  
  66.  
  67.   public GermanTextField(String text, int columns) {
  68.     super(text, columns);
  69.     init();
  70.   }
  71.  
  72.  
  73.   public GermanTextField(String text) {
  74.     super(text);
  75.     init();
  76.   }
  77.  
  78.  
  79.   private void init() {
  80.     transform.put(KeyEvent.VK_A, "äÄ");
  81.     transform.put(KeyEvent.VK_U, "üÜ");
  82.     transform.put(KeyEvent.VK_O, "öÖ");
  83.  
  84.     addKeyListener(this);
  85.   }
  86.  
  87.  
  88.  
  89.   public void keyPressed(KeyEvent evt) {
  90.     if(evt.isAltGraphDown()){
  91.       String umlaut = transform.get(evt.getKeyCode());
  92.       if(umlaut != null){
  93.         int idx = evt.isShiftDown() ? 1 : 0;
  94.         setText(getText() + umlaut.charAt(idx));
  95.       }
  96.     }
  97.   }
  98.  
  99.   public void keyReleased(KeyEvent arg0) {}
  100.  
  101.  
  102.   public void keyTyped(KeyEvent evt) {
  103.     if(evt.isAltGraphDown()){
  104.       evt.consume();
  105.     }
  106.   }
  107.  
  108.  
  109. }
  110.    
  111. if (evt.getKeyCode() == KeyEvent.VK_O && evt.isAltGraphDown())
  112.    
  113. Object fontDefinition = new UIDefaults.ProxyLazyValue("javax.swing.plaf.FontUIResource", null, new Obje
  114.  
  115. java.util.Enumeration keys = UIManager.getDefaults().keys();
  116. while (keys.hasMoreElements()) {
  117.     Object key = keys.nextElement();
  118.     Object value = UIManager.get(key);
  119.     if (value instanceof javax.swing.plaf.FontUIResource) {
  120.         UIManager.put(key, fontDefinition);
  121.     }
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top