prog:jdeveloper_consolen_app
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
prog:jdeveloper_consolen_app [2013/06/20 11:00] – [Beispiel für ein Consolen Input] gpipperr | prog:jdeveloper_consolen_app [2014/12/16 12:28] (aktuell) – [Im JDeveloper eine Consolen Applikation mit Input entwickeln] gpipperr | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Im JDeveloper eine Consolen Applikation mit Input entwickeln ====== | ||
+ | Problem: Wird eine Java Consolen Applikation im JDeveloper gestartet, kann der Anwender nichts in das Consolen Fenster eingeben | ||
+ | |||
+ | Lösung: Über den Properity Dialog auf Projektebene den Dialog für die Run Optionen öffnen, "Tool Settings" | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | Nach der Einstellung Programm im JDeveloper starten und auf Eingabe Feld am unteren Rand der Console achten: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | <note tip>Wenn hier nichts eingegeben werden kann, rechts oben unter " | ||
+ | ====== Beispiel für ein Consolen Input ====== | ||
+ | |||
+ | In der JDeveloper IDE Kann leider nicht auf System.getConsole() zugegriffen werden, sehr ärgerlich vor allen für eine Password Eingabe. Daher wird in dieser Methode, falls Console nicht im Zugriff, klassisch über BufferedReader eingelesen. | ||
+ | |||
+ | <code java> | ||
+ | /** | ||
+ | * Read User input from the console | ||
+ | * @param prompt | ||
+ | * @param readPassword - if true use readPassword methode | ||
+ | * @return String with the input | ||
+ | */ | ||
+ | public static String readConsole(String prompt, boolean readPassword) { | ||
+ | String returnValue = null; | ||
+ | char[] password; | ||
+ | // try to use the console | ||
+ | Console console = System.console(); | ||
+ | // read the value from the command-line; | ||
+ | // if console is not avalible use Standard in | ||
+ | // fix for IDE JDeveloper ! | ||
+ | try { | ||
+ | if (System.console() != null) { | ||
+ | if (readPassword) { | ||
+ | password = console.readPassword(" | ||
+ | returnValue = new String(password); | ||
+ | } | ||
+ | else { | ||
+ | returnValue = console.readLine(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | // Write the Prompt | ||
+ | //open up standard input | ||
+ | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
+ | System.out.print(" | ||
+ | returnValue = br.readLine(); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | catch (Exception e) { | ||
+ | System.out.println(" | ||
+ | System.exit(1); | ||
+ | } | ||
+ | if (readPassword == false) { | ||
+ | System.out.println(" | ||
+ | } | ||
+ | return returnValue; | ||
+ | } | ||
+ | </ |
prog/jdeveloper_consolen_app.txt · Zuletzt geändert: 2014/12/16 12:28 von gpipperr