Created
December 13, 2018 07:30
-
-
Save aldhinya/0ff8417282efd22c31349a1499ee03a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input.addKeyListener(new KeyListener(){ | |
String loading = " . . . "; | |
String kata = ""; | |
@Override | |
public void keyTyped(KeyEvent e) { | |
// char c = e.getKeyChar(); | |
// kata = kata.concat(String.valueOf(c)); | |
// if(a.isSelected()){ | |
// Inggris translate = new Inggris(); | |
// output.setText(translate.getMean(kata)); | |
// } | |
// if(b.isSelected()){ | |
// Indonesia translate = new Indonesia(); | |
// output.setText(translate.getMean(kata)); | |
// } | |
} | |
@Override | |
public void keyPressed(KeyEvent e) { | |
if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) | |
{ | |
try{ | |
kata = kata.substring(0, kata.length()-1); | |
if(a.isSelected()){ | |
Inggris translate = new Inggris(); | |
output.setText(translate.getMean(kata)); | |
} | |
if(b.isSelected()){ | |
Indonesia translate = new Indonesia(); | |
output.setText(translate.getMean(kata)); | |
} | |
} catch (Exception err){ | |
System.out.println("by ade: "+ err.getMessage()); | |
kata = ""; | |
} | |
return; | |
} | |
if(e.getKeyCode() == KeyEvent.VK_ENTER){ | |
return; | |
} | |
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) | |
{ | |
input.setText(""); | |
return; | |
} | |
char c = e.getKeyChar(); | |
kata = kata.concat(String.valueOf(c)); | |
if(a.isSelected()){ | |
Inggris translate = new Inggris(); | |
output.setText(translate.getMean(kata)); | |
} | |
if(b.isSelected()){ | |
Indonesia translate = new Indonesia(); | |
output.setText(translate.getMean(kata)); | |
} | |
} | |
@Override | |
public void keyReleased(KeyEvent e) { | |
// try{ | |
// for(int i = 0; i < loading.length(); i++){ | |
// Thread.sleep(5); | |
// output.setText(loading.substring(0, i)); | |
// } | |
// } catch (InterruptedException z){ | |
// System.exit(0); | |
// } | |
if("".equalsIgnoreCase(input.getText())){ | |
output.setText("Silahkan Masukan Kata"); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment