1 / 18

Chapter 5

2. 1. System.in. ?? class System ???????? class ?????????? Java ????????????????? 3 ??? ??? in, out ??? err ??????public static final InputStream in;public static final PrintStream out;public static fianl PrintStream err;???? 3 ?????????????????? static ??? final ??????????? ????????????????

valterra
Download Presentation

Chapter 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. 1 Chapter 5 Input

    2. 2 1. System.in ?? class System ???????? class ?????????? Java ????????????????? 3 ??? ??? in, out ??? err ?????? public static final InputStream in; public static final PrintStream out; public static fianl PrintStream err; ???? 3 ?????????????????? static ??? final ??????????? ?????????????????????????? class ????????????????????? object ???? System.out.println(); ?????????????? System.in ?????????????????????????????????????????????????????????? byte

    3. 3 ???????????? 1 ??? class KeybRead { public static void main (String args[]) { char buf = \0; try { buf = (char) System.in.read(); } catch (Exception e) { System.out.println(Error:+e.toString()); } System.out.println(Your input data is +buf); } }

    4. 4 Example 2: ?????????????? StringBuffer class KeybRead2 { public static void main (String args[]) { char buf = \0; StringBuffer bufOut = new StringBuffer(); try { while ((buf = (char)System.in.read()) != \n) { bufOut.append(buf); } } catch (Exception e) { System.out.println (Error:+e.toString()); } System.out.println(Your input data is +bufOut); } }

    5. 5 Example 3. ?????????????? BufferedReader BufferedReader ???? sub-class ??? class Reader ????????????????????????? character ??????? class ????????? package java.io.* ???????????????? buffer ????????????????????????????????????? (System.in ????? buffer) ??????????? class Reader ???????????????????? character ???

    6. 6 ?????????????????? BufferedReader

    7. 7 Example import java.io.*; public class KeybRead { public static void main (String args[] ) { InputStreamReader reader = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(reader); String text = ; int aNumber = 0; System.out.print(Enter no of guest: ); try { text = input.readLine(); aNumber = Integer.parseInt(text); System.out.print(Enter rate: ); text = input.readLine(); } catch (Exception e) { System.out.println(e); System.exit(1); } Double x = new Double(text); double rate = x.doubleValue(); System.out.println(The answer is + (rate * aNumber)); } }

    8. 8 Example 4. ?????????????? JOptionPane ???? JOptionPane ????????????????? package javax.swing ???????????????????????????????????????? ????????????????????? ????????????? graphics mode ???? GUI ????????????????????????? popup window ??????????? dialog box

    9. 9 ????????? dialog box ??? JOptionPane InputDialog MessageDialog ConfirmDialog

    10. 10 Input Dialog ???????????? method ??????? showInputDialog() ?????? return ????????????? String ???????????? String response = JOptionPane.showInputDialog( null, What is your name?);

    11. 11 Arguments of showInputDialog() ??????? parent window ??????????????????????? inputDialog ?????????? (title) (option) ??????? InputDialog (option) ERROR_MESSAGE INFORMATION_MESSAGE PLAIN_MESSAGE QUESTION_MESSAGE WARNING_MESSAGE

    12. 12 showInputDialog()

    13. 13 Message Dialog MessageDialog ???? dialog box ??????????????????????? ??????????????? ?????????????? method ??????? showMessageDialog() ??? argument ??? showMessageDialog() ??????????? showInputDialog()

    14. 14 showMessageDialog()

    15. 15 Confirm Dialog ConfirmDialog ???? dialog box ??????????????? Yes No ??? Cancel ????????? ??????????? method ???? showConfirmDialog() showConfirmDialog() ?? return ??????????? ??????????????? (integer) ??????????????????????????? ??????? ???? Yes ?????????????? 0 ???? No ?????????????? 1 ??????? Cancel ?????????????? 2

    16. 16 Arguments of showConfirmDialog() ??????? parent window ??????????????????????? inputDialog ?????????? (title (option) ??????????????? Yes No ??? Cancel ?????????????? ?????? 2 ??? ??? (option) YES_NO_CANCEL_OPTION YES_NO_OPTION ??????? InputDialog ????????????????????????????????? (option) ERROR_MESSAGE INFORMATION_MESSAGE PLAIN_MESSAGE QUESTION_MESSAGE WARNING_MESSAGE

    17. 17 showConfirmDialog()

    18. 18 ????????????????????????? java ???? class Type Wrapper ????????????????????????????? Type wrapper ???????????? class ????????? package java.lang ??????????????????? primitive data type (???? int ???? double) ????? class ??? type wrapper ????????????????????????????? (????????????????? class ) ???? Integer ???? Double ??????? method ????? ?????????????????????????? primitive data type ???? ??? convert ?????????? String ???? integer ??? x=5 , int y = Integer.parseInt(x); y ??????? 5 ???? ??? convert ??? String ???? double ??? x=5.2 double y = Double.parseDouble(x); y ??????? 5.2

    19. 19 End of Chapter 5

More Related