วันศุกร์ที่ 14 กุมภาพันธ์ พ.ศ. 2557

DecimalFormat Class

DecimalFormat Class

new DecimalFormat ()               ใช้สร้าง Object DecimalFormat
new DecimalFormat ( pattern )    ใช้สร้าง Object DecimalFormat โดยมีการกำหนดรูปแบบของการแสดงผลไว้                                             ด้วย
new DecimalFormat ( pattern, object_decimalformatsymbols )  ใช้สร้าง Object DecimalFormat โดยมี                                            การกำหนดรูปแบบของการแสดงผลไว้ด้วย
applyPattern()                     ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
applyLocalizedPattern()         ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
setDecimalFormatSymbols()   ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
getDecimalFormatSymbols()   ใช้คืนค่า การจัดรูปแบบของการแสดงผล ของ Object DecimalFormat
format()                            ใช้คืนค่า ตัวเลข ที่ได้หลังจากการจัดรูปแบบแล้ว

method :  new DecimalFormat ();
return type :  DecimalFormat
content :  ใช้สร้าง Object DecimalFormat
example :  DecimalFormat decimal_format = new DecimalFormat ();
method :  new DecimalFormat ( pattern );
return type :  DecimalFormat
content :  ใช้สร้าง Object DecimalFormat โดยมีการกำหนดรูปแบบของการแสดงผลไว้ด้วย
example :  String pattern = new String ( "#,###.00" );

DecimalFormat decimal_format = new DecimalFormat ( pattern );
method :  new DecimalFormat ( pattern, object_decimalformatsymbols );
return type :  DecimalFormat
content :  ใช้สร้าง Object DecimalFormat โดยมีการกำหนดรูปแบบของการแสดงผลไว้ด้วย
example :  String pattern = new String ( "#,###.00" );
DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols ();
DecimalFormat decimal_format = new DecimalFormat ( pattern, decimal_format_symbols );

method :  applyPattern ( pattern );
return type :  void
content :  ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
example :  String pattern = new String ( "#,###.00" );
DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols ();
decimal_format_symbols.applyPattern ( pattern );
method :  applyLocalizedPattern ( pattern );
return type :  void
content :  ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
example :  String pattern = new String ( "#,###.00" );
DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols ();
decimal_format_symbols.applyLocalizedPattern ( pattern );

method : setDecimalFormatSymbols ( object_decimalformatsymbols );
return type : void
content : ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat โดยกำหนดในลักษณะของ Object DecimalFormatSymbols
example : DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols (); DecimalFormat decimal_format = new DecimalFormat (); decimal_format.setDecimalFormatSymbols ( decimal_format_symbols );
method : getDecimalFormatSymbols ();
return type : DecimalFormatSymbols
content : ใช้คืนค่า การจัดรูปแบบของการแสดงผล ของ Object DecimalFormat โดยคืนค่าในลักษณะของ Object DecimalFormatSymbols
example : DecimalFormat decimal_format = new DecimalFormat (); DecimalFormatSymbols decimal_format_symbols = decimal_format.getDecimalFormatSymbols ();

method :  format ( number );
return type :  String
content :  ใช้คืนค่า ตัวเลข ที่ได้หลังจากการจัดรูปแบบแล้ว
example :  String pattern = new String ( "#,###.00" );
DecimalFormat decimal_format = new DecimalFormat ( pattern );
String str_datetime = decimal_format.format ( 2000000 );

DecimalFormatSymbols Class


new DecimalFormatSymbols ()               ใช้สร้าง Object DecimalFormatSymbols
 new DecimalFormatSymbols ( locale )    ใช้สร้าง Object               DecimalFormatSymbols                                                       โดยมีค่า รูปแบบตัวเลข ตาม timezone ของ Locale ที่กำหนด
 setDecimalSeparator()                         ใช้กำหนด สัญลักษณ์ ของการคั่นตัวเลขเมื่อมีตัวเลขครบทุกๆ 3 ตำแหน่ง
getDecimalSeparator()                          ใช้คืนค่า สัญลักษณ์ ของการคั่นตัวเลขเมื่อมีตัวเลขครบทุกๆ 3 ตำแหน่ง
setMonetaryDecimalSeparator()                  ใช้กำหนด สัญลักษณ์ ของการแทนเครื่องหมายจุดทศนิยม

                   getMonetaryDecimalSeparator()  ใช้คืนค่า สัญลักษณ์ ของการแทนเครื่องหมายจุดทศนิยม
                   setPercent()    ใช้กำหนด สัญลักษณ์ ของการแทนเครื่องหมายเปอร์เซ็นต์
                   getPercent()    ใช้คืนค่า สัญลักษณ์ ของการแทนเครื่องหมายเปอร์เซ็นต์
                   setDigit()        ใช้กำหนด สัญลักษณ์ ของการแทนตัวเลข 0 ของเลขฐาน 2
                   getDigit()        ใช้คืนค่า สัญลักษณ์ ของการแทนตัวเลข 0 ของเลขฐาน 2
                   setMinusSign()    ใช้กำหนด สัญลักษณ์ ของการแทนเครื่องหมาย ลบ
                   getMinusSign()   ใช้คืนค่า สัญลักษณ์ ของการแทนเครื่องหมาย ลบ

:: DecimalFormat Class  ::  new DecimalFormat ()
    method : new DecimalFormat ();
    return type : DecimalFormat
   content : ใช้สร้าง Object DecimalFormat
   example : DecimalFormat decimal_format = new                                         
                     DecimalFormat ();

method : applyLocalizedPattern ( pattern );
return type : void
content : ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object DecimalFormat
example : String pattern = new String ( "#,###.00" ); DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols (); decimal_format_symbols.applyLocalizedPattern ( pattern );

method : setDecimalFormatSymbols                   
               (object_decimalformatsymbols );
 
return type : void
   content :              ใช้กำหนดรูปแบบของการแสดงผล ให้กับ Object
   DecimalFormat      โดยกำหนดในลักษณะของ Object
      DecimalFormatSymbols
example :  DecimalFormatSymbols decimal_format_symbols = new DecimalFormatSymbols (); DecimalFormat decimal_format = new DecimalFormat (); decimal_format.setDecimalFormatSymbols ( decimal_format_symbols )

 
method : getDecimalFormatSymbols ();
return type : DecimalFormatSymbols
content : ใช้คืนค่า การจัดรูปแบบของการแสดงผล ของ Object DecimalFormat โดยคืนค่าในลักษณะของ Object DecimalFormatSymbols
example : DecimalFormat decimal_format = new DecimalFormat (); DecimalFormatSymbols decimal_format_symbols = decimal_format.getDecimalFormatSymbols ();

       method : format ( number );
return type : String
content : ใช้คืนค่า ตัวเลข ที่ได้หลังจากการจัดรูปแบบแล้ว
example : String pattern = new String ( "#,###.00" ); DecimalFormat decimal_format = new DecimalFormat ( pattern ); String str_datetime = decimal_format.format ( 2000000 );

MessageFormat Class

 :: MessageFormat Class
 new MessageFormat ( pattern )ใช้สร้าง Object MessageFormat โดยมีการกำหนดรูปแบบของข้อความที่ต้องการจัดไว้ด้วย
                   new MessageFormat ( pattern, locale )ใช้สร้าง Object MessageFormat โดยมีการกำหนด                                                               รูปแบบของข้อความที่ต้องการจัดไว้ด้วย
                   applyPattern()ใช้กำหนดรูปแบบของข้อความที่ต้องการจัด ให้กับ Object MessageFormat
                   setLocale()ใช้กำหนด object Locale ให้กับ Object MessageFormat
                   getLocale()ใช้คืนค่า object Locale ของ Object MessageFormat
                   format ( object_array )ใช้คืนค่า ข้อความ ที่ได้หลังจากการจัดรูปแบบแล้ว
                   format ( pattern, object_array )ใช้คืนค่า ข้อความ ที่ได้หลังจากการจัดรูปแบบแล้ว
                   โครงสร้างของ Pattern ของการจัดรูปแบบได้แก่ { index }, { index, type_var }, { index, type_var, kind }

    method : new MessageFormat ( object_string_pattern );
   return type : MessageFormat
   content : ใช้สร้าง Object MessageFormat โดยมีการกำหนดรูปแบบของข้อความที่     ต้องการจัดไว้ด้วย
   example : String pattern = new String ( "{0}" );
      MessageFormat message_format   = new MessageFormat ( pattern );

method : new MessageFormat ( object_string_pattern );
return type : MessageFormat
content : ใช้สร้าง Object MessageFormat โดยมีการกำหนดรูปแบบของข้อความที่ต้องการจัดไว้ด้วย
example : String pattern = new String ( "{0}" ); MessageFormat message_format = new MessageFormat ( pattern );

  
      method : setLocale ( object_locale );
return type : void
content : ใช้กำหนด object Locale ให้กับ Object MessageFormat
example : Locale locale = new Locale ( "th", "TH" );
                        MessageFormat message_format = new MessageFormat (); message_format.setLocale ( locale ); 


method : getLocale ();
return type : Locale
content : ใช้คืนค่า object Locale ของ Object MessageFormat
example : MessageFormat message_format = newMessageFormat ();
      Locale locale = message_format.getLocale ();

                
::  MessageFormat Class ::  format ( object_array )
method : format ( object_array );
return type : String
content : ใช้คืนค่า ข้อความ ที่ได้หลังจากการจัดรูปแบบแล้ว
example : MessageFormat message_format = new MessageFormat ( "{1} explain about {0}." );
                    String [] str_data = { "JAVA-SWING", "E-Learning :: " }; String data_format = message_format.format ( str_data );

      method : format ( pattern, object_array );
return type : String
special : static
content : ใช้คืนค่า ข้อความ ที่ได้หลังจากการจัดรูปแบบแล้ว
example : String [] str_data = { "JAVA-SWING", "E-Learning :: ", new Date () };
       String pattern = new String ( "{1} explain about {0}. update-time {3, date, full}" );
       String data_format = MessageFormat.format ( pattern, str_data );

                   subject : โครงสร้างของ Pattern ของการจัดรูปแบบ
        content : โครงสร้างของ Pattern ของการจัดรูปแบบ ได้แก่
                   { index } เป็นการนำข้อความจากดัชนีที่กำหนดมาแสดง
                   { index, type_var } เป็นการนำข้อความจากดัชนีที่กำหนดมาแสดง โดยแสดงเป็นชนิดข้อมูลที่กำหนด
                   { index, type_var, kind } เป็นการนำข้อความจากดัชนีที่กำหนดมาแสดง โดยแสดงเป็นชนิดข้อมูลที่กำหนด ตามรูปแบบที่กำหนด

                   subject : ชนิดข้อมูล และรูปแบบของข้อมูล ที่ใช้ในการจัดรูปแบบ
        content : ชนิดข้อมูล และรูปแบบของข้อมูล ที่ใช้ในการจัดรูปแบบ ได้แก่
                   - time มีรูปแบบ ดังนี้ short, medium, long, full, dateFormatPattern –
                   - date มีรูปแบบ ดังนี้ short, medium, long, full, dateFormatPattern –
                   - number มีรูปแบบ ดังนี้ currency, percent, integer, numberFormatPattern
                    - choice มีรูปแบบ ดังนี้ choiceFormatPattern

Operator

::  Operator
                   ตัวดำเนินการทางคณิตศาสตร์ตัวดำเนินการทางคณิตศาสตร์
                   ตัวดำเนินการการกำหนดค่าตัวดำเนินการการกำหนดค่า
                   ตัวดำเนินการเพิ่มค่าหรือลดค่าตัวดำเนินการเพิ่มค่าหรือลดค่า
                   ตัวดำเนินการเชิงเปรียบเทียบตัวดำเนินการเชิงเปรียบเทียบ
                   ตัวดำเนินการเชิงตรรกะตัวดำเนินการเชิงตรรกะ
                   ตัวดำเนินการเชิงข้อความตัวดำเนินการเชิงข้อความ

                   subject : ตัวดำเนินการทางคณิตศาสตร์
        content : ตัวดำเนินการทางคณิตศาสตร์ ที่ใช้ใน JAVA ได้แก่
                   + ( บวก )
                   - ( ลบ )
                   * ( คูณ )
                   / ( หาร )
                   % ( หาร เอาค่า เศษ )

                   subject : ตัวดำเนินการการกำหนดค่า
        content : ตัวดำเนินการการกำหนดค่า ที่ใช้ใน JAVA ได้แก่
                   = ( เช่น num = 5 มีค่า num = 5 )
                   += ( เช่น num += 5 มีค่า num = num + 5 )
                    -= ( เช่น num -= 5 มีค่า num = num - 5 )
                   *= ( เช่น num *= 5 มีค่า num = num * 5 )
                   /= ( เช่น num /= 5 มีค่า num = num / 5 )
                   %= ( เช่น num %= 5 มีค่า num = num % 5 )

                   subject : ตัวดำเนินการเพิ่มค่าหรือลดค่า
content : ตัวดำเนินการเพิ่มค่าหรือลดค่า ที่ใช้ใน JAVA ได้แก่
                    ++ตัวแปร คือ การเพิ่มค่าตัวแปรขึ้น 1 ก่อน แล้วจึงค่อยคืนค่า ตัวแปร++ คือ คืนค่าตัวแปรก่อน แล้วจึงค่อยเพิ่มค่าตัวแปรขึ้น 1
                   --ตัวแปร คือ การลดค่าตัวแปรลง 1 ก่อน แล้วจึงค่อยคืนค่า ตัวแปร-- คือ คืนค่าตัวแปรก่อน แล้วจึงค่อยลดค่าตัวแปรลง 1

                   subject : ตัวดำเนินการเชิงเปรียบเทียบ
content : ตัวดำเนินการเชิงเปรียบเทียบ ที่ใช้ใน JAVA ได้แก่
                   == ( เท่ากับ )
                   != ( ไม่เท่ากับ )
                    > ( มากกว่า )
                    >= ( มากกว่าหรือเท่ากับ )
                    < ( น้อยกว่า )
                    <= ( น้อยกว่าหรือเท่ากับ )

                   subject : ตัวดำเนินการเชิงข้อความ
                   content : ตัวดำเนินการเชิงข้อความ ที่ใช้ใน JAVA ได้แก่ + ( บวก ) คือ ใช้เชื่อมข้อมูลชนิด String กับข้อมูลชนิด String

Structure

::  Structure
                   คำสั่งควบคุมการทำงาน IFคำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด
                   คำสั่งควบคุมการทำงาน IF ELSEคำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด
                   คำสั่งควบคุมการทำงาน IF ELSE IFคำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด
                   คำสั่งควบคุมการทำงาน NESTED IFคำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด
                   คำสั่งควบคุมการทำงาน SWITCH CASEคำสั่ง switch case คือ จะตรวจสอบค่าของตัวแปร ถ้าตรงตามเงื่อนไขใดก็จะทำตามคำสั่งนั้นๆ
                   คำสั่งควบคุมการทำงาน EXPRESSIONคำสั่ง expression คือ ใช้กำหนดคำสั่งแบบมีเงื่อนไข
                   คำสั่งควบคุมการทำงาน FORคำสั่ง for คือ จะทำงานเมื่อเงื่อนไขเป็นจริง และจะจบการทำงานเมื่อเงื่อนไขเป็นเท็จ
                   คำสั่งควบคุมการทำงาน WHILEคำสั่ง while คือ จะทำงานเมื่อเงื่อนไขเป็นจริง และจะจบการทำงานเมื่อเงื่อนไขเป็นเท็จ
                   คำสั่งควบคุมการทำงาน DO WHILEคำสั่ง do while คือ จะทำงานก่อน 1 ครั้ง แล้วหลังจากนั้นจะทำงานก็ต่อเมื่อเงื่อนไขยังเป็นจริงอยู่

                   subject : คำสั่งควบคุมการทำงาน IF
syntax :  if ( condition )
   {
   structure;
   }
                   content : คำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด
                   example : 
    int num = 100;
   if ( num > 100 )
  {
   System.out.print ( "many" );
   }

                   subject : คำสั่งควบคุมการทำงาน IF ELSE
syntax : if ( condition )
         {
         structure;
         }
        else
        {
        structure;
         }
                   subject : คำสั่งควบคุมการทำงาน IF ELSE
syntax : if ( condition )
         {
         structure;
         }
        else
        {
        structure;
         }

                   subject : คำสั่งควบคุมการทำงาน IF ELSE IF
syntax : if ( condition )
      {
        structure;
      }
      else
      if ( condition )
    {
     structure;
     } 
    else
    {
    structure;
     }
                   content : คำสั่ง if คือ ใช้ตรวจสอบเงื่อนไข ถ้าหากว่าเงื่อนไขเป็นจริง ก็จะทำตามคำสั่งที่กำหนด ส่วน else จะหมายถึง ถ้าไม่ตรงตามเงื่อนไขใดๆ ให้ทำตามคำสั่งที่กำหนดใน else
                   example : int num = 100;
         if ( num > 100 )
       {
       System.out.print ( "many" );
        }
      else if ( num > 50 )
       {
       System.out.print ( "middle" );
        }
      else
       {
      System.out.print ( "little" );
        }

                   subject : คำสั่งควบคุมการทำงาน NESTED IF
                   syntax : if ( condition )
         {
         if ( condition )
        {
        structure;
        }
        }

        subject : คำสั่งควบคุมการทำงาน FOR
syntax : for ( ค่าเริ่มต้น; เงื่อนไข; การเพิ่มค่า )
       {
         structure;
        }
     content : คำสั่ง for คือ จะทำงานเมื่อเงื่อนไขเป็นจริง และจะจบการทำงานเมื่อเงื่อนไขเป็นเท็จ โดยแต่ละรอบของการวนลูปจะมีการเพิ่มค่าตามที่กำหนด

example : for ( int i=0; i<100; i++ )
       {
        System.out.print ( i );
        }

subject : คำสั่งควบคุมการทำงาน WHILE
syntax : while ( เงื่อนไข )
      {
       structure;
       }
content : คำสั่ง while คือ จะทำงานเมื่อเงื่อนไขเป็นจริง และจะจบการทำงานเมื่อเงื่อนไขเป็นเท็จ
example : int num = 10; while ( num > 0 )
      { 
       System.out.print ( num ); num--;
        }

subject : คำสั่งควบคุมการทำงาน DO WHILE
syntax : do
      {
       structure;
     }
       while ( เงื่อนไข );

content : คำสั่ง do while คือ จะทำงานก่อน 1 ครั้ง แล้วหลังจากนั้นจะทำงานก็ต่อเมื่อเงื่อนไขยังเป็นจริงอยู่ และจะจบการทำงานเมื่อเงื่อนไขเป็นเท็จ
example : int num = 10;
                           do
                          {
                             System.out.print ( num ) num--;
                           }
                            while ( num > 10 );

ตัวอย่างการรัน แบบ Messageformat




ตัวอย่างการรันแบบ Operator





ไม่มีความคิดเห็น:

แสดงความคิดเห็น