   Java Swing  NetBeans
  


            Java    NetBeans.              ,                  Java.





 

   Java Swing  NetBeans








1  








1.1  Java


Java ( ;   )  -  ,   Sun Microsystems (    Oracle).

 Java    -,        Java- (JVM)     .     23  1995 .

 Java    .










  Java    OAK,     .     Java     :










Java 2 Micro Edition,  J2ME     Java      ( , Palm  ..).          .    ""        (Midlets).      ,    , ,    (   ..). Java ME      Java        .

Java 2 Standart Edition,  J2SE      Java,     Java .             .    J2SE,   Java 2 Standart Edition.

Java 2 Enterprise Edition,  J2EE     Java       ( ).       Enterprise Java Beans (EJB), Java Server Pages (JSP)   (Servlets).    J2EE  .Net           .

    Java      Java,     :










Java Runtime Environment,  JRE     Java,    ,    .       Java Virtual Machine (JVM)   Java .       ,    Java ,      .

Java Virtual Machine,  JVM     Java      JRE.   Java    - Java.            Java (  javac).     runtime-,  Java-    JRE.

Java Development Kit,  JDK      Oracle      Java,     Java (javac),    Java, , ,      Java (JRE).   JDK       Java (IDE),  ,   JDK,         ,    .

  ,  JRE    JDK,  Oracle      .   ,   JRE        Java-.     JRE ,    JDK,     JRE   .










   ,   NetBeans, Oracle JDeveloper, IntelliJ IDEA, Eclipse        Java.    ,  JDK,     Java-      JDK.             JDK,        JDK   .

 ,     Java   JRE+JDK+NetBeans,              JRE.

  java- (  jar)     :



java -jar JavaApplication1.jar



       JavaApplication1.jar.






1.2    NetBeans


NetBeans IDE       (IDE)    Java, Python, PHP, JavaScript, C, C++,   .

 NetBeans IDE     Oracle,   NetBeans    - (NetBeans Community)   NetBeans Org.

      NetBeans IDE     ()      Java, ,  IntelliJ IDEA,  , ,    ,     ,      .

     NetBeans         NetBeans     JDK  J2EE SDK  .   NetBeans     J2SE  J2EE     J2ME.










   -:

C:\Documents and Settings\<_>\ \NetBeansProjects.

   :    "" " " (F6).

 :    "" " " (         ).

 :    "" " " (Ctrl+Shift+S).

   :    "" " " (Ctrl+Shift+O).

  :    "" "    ",    廠        ʻ.

   jar-:    "" "   " (Shift+F11).  jar-    "dist" .








1.3   









 .     .








byte b1 = 50, b2 = -99, b;

byte a1 = 0xF1, a2 = 0x07;

short det = 0, ind = 1;

int i = -100, j = 100, k = 9999;

long big = 50;








 .     .








char c1 = 'A', c2 = '?', newLine = '\n';

char s2 = '\u0042';








 .       .










float  = 0.001,  = -34.789;

double 21 = -16.2305, z2;

float x1 = 3.5f, x2 = 3.7E6f, x3 = -1.8E-7f;








 ,    "" (Math.PI)  "" (Math.E)    Math,    java.lang.

    ,      ,     Math.








 () .      true ()  false ().



boolean a, b;

a=true; b=a; c=false;











1.4.  


    Java      C++.

  if  else.        if  else,     :



if () {

1;

} else {

2;

}



     .    true,   1,    (    else)   2.  else   ,    if  else    :



if () {

;

}



int m = 4;

if (m == 4) {

System.out.println("April");

}



run: April



           .      if  else:



if (1) {

1

} else if (2) {

2

} else {

3

}



int month = 4;

String season;

if (month == 12 || month == 1 || month == 2) {

season = "Winter";

} else if (month == 3 || month == 4 || month == 5) {

season = "Spring";

} else if (month == 6 || month == 7 || month == 8) {

season = "Summer";

} else if (month == 9 || month == 10 || month == 11) {

season = "Autumn";

} else {

season = "Bogus Month";

}

System.out.println("April is in the " +season + ".");



run: April is in the Spring.



   if  else   ?   :



 ? 1 : 2



 1, 2     .



    1,   ,    2.



int m = 4; String season;

season = m == 4 ? "April" : "???";

System.out.println(season);



run: April



  switch  case.  switch        ,   case     :



switch () {

case 1:

;

case 2:

;



default:

;

}



      : byte, short, int, char.   case    -.        case,        case.

          break.      break,     ,   .

           case,      default.    default ,   switch .



int month = 4;

String season;

switch (month) {

case 12:

case 1:

case 2:

season = ""; break;

case 3:

case 4:

case 5:

season = ""; break;

case 6:

case 7:

case 8:

season = ""; break;

case 9:

case 10:

case 11:

season = ""; break;

default:

season = "  ";

}

System.out.println("   " +season + ".");



run:    .



 for.  for                :



for (; ;  ) ;



     :

;

  ;

  ;

 .

    for  .   ,         .      ,        true.       ,    :



for (;;) {

;

}



for (int i = 1; i <= 10; i++) {

System.out.println("i = " +i);

}



run:

i = 1

i = 2

i = 3

i = 4

i = 5

i = 6

i = 7

i = 8

i = 9

i = 10



for (int n = 10; n > 0; n) {

System.out.println("n= " +n);

}



run:

n= 10

n= 9

n= 8

n= 7

n= 6

n= 5

n= 4

n= 3

n= 2

n= 1



int a, b;

for (a = 1, b = 4; a < b; a++, b) {

System.out.println("a = " +a);

System.out.println("b = " +b);

}



run:

a = 1

b = 4

a = 2

b = 3



 while.    while  :



while ()

;



int n = 5;

while (n > 0) {

System.out.println("while " +n);

n;

}

run:

while 5

while 4

while 3

while 2

while 1



    .    true,   (      ),      ,      ,         false.



 do  while.        1 ,   do  while:



do

while ()



int n = 5;

do {

System.out.println("do-while " +n);

} while (n > 0);



run:

do-while 5

do-while 4

do-while 3

do-while 2

do-while 1



           .

       :

break      ;

continue        (..   ).    while  do       ,      for  continue        .

.  Java   goto.      goto    ,  ,      .            .

    Java  .        ,     ,     .



: 



  ,        ,           for, while, do,   if, switch   {}.       ,            break,     ,   .

:










   break      .

      :












boolean t = true;

a:

{

b:

{

c:

{

System.out.println(" break");

if (t) {

break b;

}

System.out.println("He   ");

}

System.out.println("He   ");

}

System.out.println(" break");

}



run:

 break

 break



   ().  Java      ()   return,          ,   .   ,    return:



boolean t = true;

System.out.println(" return");

if (t) { return; }

System.out.println("o    ");



run:

 return



      System.exit().    ,     0:



System.exit(0);






1.5   


        .      Java-.               .        null   0   .     0.      length.

      :



package tsn01.array;

import java.util.Arrays;

public class TSN01_Array {

public static void main(String[] args) {

//      

int a[], b[]; // -  

a = new int[10]; //    

b = new int[]{1, 2, 3, 4}; //    

String s[] = new String[] {"Hello ", "world", "!!!"}; //     

Arrays.fill(a, 0); //   

a[0] = 20; a[1] = 10; a[2] = 5; a[3] = 33; //   4 

Arrays.fill(a, 5,10,-1); //   5  9 (10-1)   "-1"

Arrays.sort(a); //  

b[3] = b[1]*0b11+b[2]*0x2; //    4 

System.out.println(Arrays.toString(a)); //     "a"

System.out.println(Arrays.toString(b)); //     "b"

System.out.println(Arrays.toString(s)); //     "s"

//     

System.out.println("    \"a\": " +a.length);

System.out.println("    \"b\": " +b.length);

System.out.println("    \"str\": " +s.length);

System.out.println(s[0] + s[1]); //    

}

}



  :



[-1, -1, -1, -1, -1, 0, 5, 10, 20, 33]

[1, 2, 3, 12]

[Hello , world, !!!]

    "a": 10

    "b": 4

    "str": 3

Hello world






1.6   


         .       :



package tsn01.matrix;

public class TSN01_Matrix {

public static void main(String[] args) {

//      

//    ( )     

final int r = 4; //  

final int c = 5; //  

int m[][] = new int[r][c]; //  

int k; System.out.println("Matrix:");

for (int i = 0; i < r; i++) { //   

for (int j = 0; j < c; j++) { //   

k = (int) Math.round(Math.random() * 100); //   

m[i][j] = k; //    

System.out.print(String.format("%5d", m[i][j])); //     

} System.out.println("");

}

//      

int min = m[0][0], max = m[0][0], maxi = 0, maxj = 0, mini = 0, minj = 0; //      

for (int i = 0; i < r; i++) { //   

for (int j = 0; j < c; j++) { //   

k = m[i][j]; //   

if (k > max) { max = k; maxi = i; maxj = j; } //  

if (k < min) { min = k; mini = i; minj = j; } //  

}

}

//        

k = m[maxi][maxj]; m[maxi][maxj] = m[mini][minj]; m[mini][minj] = k;

//     

System.out.println("New matrix:");

for (int i = 0; i < r; i++) { //   

for (int j = 0; j < c; j++) { //   

System.out.print(String.format("%5d", m[i][j])); //     

} System.out.println("");

}

}

}



  :



Matrix:

42 83 94 96 1

2 64 27 32 10

20 86 49 14 36

12 35 14 65 97

New matrix:

42 83 94 96 97

2 64 27 32 10

20 86 49 14 36

12 35 14 65 1






1.7  -


      : Vector  ArrayList.         ,    .

        Collection  List:

add(E o)     ;

add(int index, E element)      ;

remove(int index)      ;

remove(Object o)       ;

clear()    ;

isEmpty()  ,    ;

size()   ;

set(int index, E element)       ;

get(int index)      ;

contains(Object o)  ,       ;

lastIndexOf(Object o)     ,     -1;

indexOf(Object o)     ,     -1;

toArray()       ;

toArray(T[] a)      .

      :



package tsn01.arraylist;

import java.util.ArrayList;

public class TSN01_ArrayList {

public static void main(String[] args) {

//     

ArrayList<Integer> i = new ArrayList<>(); //     

i.add(3); //  

i.add(new Integer(3)); //  

if (i.get(0)==i.get(1)) { System.out.println("   "); }

if (i.get(0).equals(i.get(1))) { System.out.println("3=3"); }

i.add(12+5); //  

System.out.println(" : " +i.size());

System.out.println(" : " +i.get(0).intValue() + ", " +i.get(1)+ ", " +i.get(2));

}

}



  :



3=3

 : 3

 : 3, 3, 17



     :



package tsn01.arraylist;

import java.util.ArrayList;

public class TSN01_ArrayList {

public static void main(String[] args) {

//     

ArrayList<String> pozdr = new ArrayList<>(); //  

ArrayList<String> fam = new ArrayList<>(); //  

//    

pozdr.add(""); pozdr.add(""); pozdr.add("");

//    

fam.add(""); fam.add(""); fam.add("");

//   

if (fam.size() > pozdr.size()) { return; }

for (int i = 0; i < fam.size(); i++) {

//       0    

int p = (int) Math.floor(Math.random() * pozdr.size());

//  

System.out.println(" " +fam.get(i)

+ "!      ,    "

+ pozdr.get(p).toString().toLowerCase() + "!");

pozdr.remove(p); //        

} }

}






1.8   


 Java    : String, StringBuilder  StringBuffer.   String    Java,           .

  StringBuilder       .    StringBuilder    1.2-1.5  ,  StringBuffer.

  StringBuffer        .   ,  .

             .

 .    Java   String   , ..        .

    new,        .     ,            .



String s1 = "d" //     

//           

String s2 = new String("a");



             ,       (,   ,  ,   ).

 .     +,      .      ,      .        toString.

        StringBuilder  StringBuffer.             StringBuilder/StringBuffer.

 .     substring        ,   . ,        1. -           3 .         1.



String s ="very .... long string from file";

String sub1 = s.substring(2,4); //        s

String sub2 = new String(s.substring(2,4)); //       4 







 .    String:

equals(Object anObject)  ,     ;

compareTo(String anotherString)    ;

compareToIgnoreCase(String str)        ;

concat(String str)     ;

contains(CharSequence s)  ,       ;

isEmpty()   true,     0;

indexOf(String str)      ;

replace(CharSequence target, CharSequence replacement)     ;

substring(int beginIndex, int endIndex)     ;

toLowerCase()      ;

toUpperCase()      ;

trim()       ;

length()    ;

valueOf(a)        ;

charAt(int index)      ;

regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)      ,     ;

regionMatches(int toffset, String other, int ooffset, int len)      ;

endsWith(String suffix)  ,     ;

startsWith(String prefix)  ,      ;

startsWith(String prefix, int toffset)  ,         ;

getBytes()     ;

getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)      ;

hashCode()    ;

indexOf(int ch)       ;

indexOf(int ch, int fromIndex)          ;

indexOf(String str, int fromIndex)         ;

lastIndexOf(int ch)     ;

lastIndexOf(int ch, int fromIndex)        ;

lastIndexOf(String str)     ;

lastIndexOf(String str, int fromIndex)        ;

replace(char oldChar, char newChar)        ;

toUpperCase(Locale locale)      ,   ;

toLowerCase(Locale locale)      ,   ;

      -1,    .   ( replace)    ,      .

 String.    String            .  :



public static void main(String[] args) {

String s = "a";

for (int i = 0; i < 100; i++) {

s += 'a';

}

System.out.println(s); //    100  a

}



   100  ,     ,    Java      .      s     100  a,  99           .

        StringBuilder.      :



public static void main(String[] args) {

StringBuilder s = new StringBuilder("a");

for (int i = 0; i < 100; i++) {

s.append('a');

}

System.out.println(s); //    100  a

}



 .     StringBuilder  StringBuffer. StringBuffer  ,  .              .

   :

append(A)   A      ;

insert(int offset, A)   A        ;

delete(int start, int end)           ;

reverse()      ;

setCharAt(int index, char ch)      ;

setLength(int newLength)     ;

substring(int start)           ;

substring(int start, int end)     ;

deleteCharAt(int index)      ;

getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)      ;

indexOf(String str)     ;

indexOf(String str, int fromIndex)        ;

lastIndexOf(String str)     ;

lastIndexOf(String str, int fromIndex)        ;

replace(int start, int end, String str)      .

  .             String     :



package tsn01.string;

public class TSN01_String {

public static void main(String[] args) {

char s[] = {'J', 'a', 'v', 'a'}; //  

String str = new String(s); // str="Java"

if (!str.isEmpty()) {

int i = str.length(); // i=4

str = str.toUpperCase(); // str="JAVA"

String num = String.valueOf(6); // num="6"

num = str.concat("-" +num); // num="JAVA-6"

char ch = str.charAt(2); // ch='V'

i = str.lastIndexOf('A'); // i=3 (-1  )

num = num.replace("6", "SE"); // num="JAVA-SE"

str.substring(0, 4).toLowerCase(); // java

str = num + "-6";// str="JAVA-SE-6"

String[] arr = str.split("-");

for (String ss : arr) { //       ( 3 ): JAVA SE 6

System.out.println(ss);

}

} else { System.out.println("String is empty!"); }

}

}



  .              equals(),   String      hashCode(),   -  (hashCode   ,        ,     String   : s[0]*31^(n-1) s[1]*31^(n-2)  s[n-1]):



package tsn01.string;

public class TSN01_String {

public static void main(String[] args) {

String s1 = "Java";

String s2 = "Java";

String s3 = new String("Java");

System.out.println(s1 + "==" +s2 + " : " + (s1 == s2)); // true

System.out.println(s1 + "==" +s3 + " : " + (s1 == s3)); // false

System.out.println(s1 + " equals " +s2 + " : " +s1.equals(s2)); // true

System.out.println(s1 + " equals " +s3 + " : " +s1.equals(s3)); // true

System.out.println(s1.hashCode());

System.out.println(s2.hashCode());

System.out.println(s3.hashCode());

}

}



     :



Java==Java : true

Java==Java : false

Java equals Java : true

Java equals Java : true

2301506

2301506

2301506



     :



package tsn01.string;

public class TSN01_String {

public static void main(String[] args) {

String a[] = {" Alena", "Alice ", " alina", " albina", " Anastasya",

" ALLA ", "AnnA "}; //  

for (int j = 0; j < a.length; j++) { //    

//          

a[j] = a[j].trim().toLowerCase();

}

//    

for (int j = 0; j < a.length  1; j++) { //    

for (int i = j + 1; i < a.length; i++) { //    

if (a[i].compareTo(a[j]) < 0) { //  

String temp = a[j]; a[j] = a[i]; a[i] = temp; //     

}

}

}

int i = -1;

while (++i < a.length) { System.out.print(a[i] + " "); } //     

}

}



     :



albina alena alice alina alla anastasya anna



  trim()        .  compareTo()         Unicode.

    .      StringBuilder  String   toString:



package tsn01.string;

public class TSN01_String {

public static void main(String[] args) {

StringBuilder s = new StringBuilder("abcd");

s.append('e');//abcde

s.delete(1, 2);//acde

s.insert(1, 'b');//abcde

s.deleteCharAt(2);//abde

String ans = s.toString();

System.out.println(ans); //    "abde"

}

}








2  








2.1  


   Java      ,     ,         .          ,      .

         뻠  :










  Java  Java:










       .        .

    : FIOnn_DEMO,  FIO    , nn   , , TSN01_DEMO.

     : fionn.demo.App1,  fio    , nn   ,  tsn01.demo.App1.










    .










package tsn01.demo;

import java.util.Scanner;

public class App1 {

public static void main(String[] args) {

//   

Scanner sc = new Scanner(System.in); //   

System.out.print("  : "); //  

String n = sc.next(); //     

System.out.print("  : "); //  

int a = sc.nextInt(); //     

System.out.print(" : "); //  

float w = sc.nextFloat();//     

System.out.println(", " +n + "!  " +a + " ,  "

+ w + " .");

sc.close(); //  

}

}



     Windows    :



java -Dfile.encoding=Cp866 -jar TSN01_DEMO.jar










       .



package tsn01.demo;

import java.util.Scanner;

public class App1 {

public static void main(String[] args) {

//   

double a, b, c; //  

double x1, x2; //  

double d; // 

try {

Scanner sc = new Scanner(System.in); //      

System.out.println("  ");

System.out.print(" a=");

a = sc.nextDouble(); //   "a" 

System.out.print(" b=");

b = sc.nextDouble(); //   "b" 

System.out.print(" c=");

c = sc.nextDouble(); //   "c" 

d = (b * b)  4 * a * c; //  

x1 = (-b + Math.sqrt(d)) / (2 * a); //  "x1"

x2 = (-b  Math.sqrt(d)) / (2 * a); //  "x2"

if (!(Double.isNaN(x1)) && (!Double.isInfinite(x1)) //   

&& (!(Double.isNaN(x2)) && (!Double.isInfinite(x2)))) {

System.out.format("x1=%.3f%nx2= %.3f%n", x1, x2); //  

} else {

System.out.println(" !"); //  

}

sc.close(); //    

} catch (Exception e) { //    

System.out.println("  !");

}

}

}













2.2        NetBeans


   "" " ":










  "Java",   " Java":










  .       TSN01_LAB1,  TSN     , 01   (2 ),    _,  LAB      .        .   .

    ,      ,   , ..      :










     -,         .      黠  JFrame:










   ().       Form1,  Form ,   ,   ,  1    .

,    .       tsn01.lab1,  tsn     , 01   (2 ),    . (),  lab      .

  .










      Form1.      .

  :    (F6).










       .         ʻ.    .










           :










private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

//  

String a, b, c; //  

double z; //  

double x, y; //  

// int x, y; //  

a = jTextField1.getText(); //     1

b = jTextField2.getText(); //     2



try { //   

x = Double.parseDouble(a); //     

y = Double.parseDouble(b); //     

// x = Integer.parseInt(a); //     

// y = Integer.parseInt(b); //     



z = x / y; //  

// z = (double)( x) / (double) (y); //  



//  : 0/0, z/0

if ((Double.isNaN(z) == true) || Double.isInfinite(z) == true) {

throw new Exception("error"); //      

}



//    

DecimalFormat df = new DecimalFormat("#0.00");

c = String.valueOf(df.format(z)); //    

jTextField3.setText(c); //    

// jTextField3.setText(String.valueOf(new DecimalFormat("#0.00").format(z))); //    

} catch (Exception ee) { //    

Toolkit.getDefaultToolkit ().beep (); //  

jTextField3.setText(" !"); //     

} //   

}

            :










private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

//  

float x, b, d, y; //  



try {

x = Float.parseFloat(jTextField1.getText()); //  

b = Float.parseFloat(jTextField2.getText()); //  

d = Float.parseFloat(jTextField3.getText()); //  

} catch (Exception ex) {

Toolkit.getDefaultToolkit().beep(); //  

//      

JOptionPane.showMessageDialog(rootPane, "  !", " ", JOptionPane.ERROR_MESSAGE);

jTextField1.requestFocus(); //    

jLabel5.setText("    .");

jTextField1.setText(""); //  

jTextField2.setText(""); //  

jTextField3.setText(""); //  

return; //    ()

}



if (x >= 8) { //  

y = (x  2) / (x * x);

} else {

y = b * b * d + 4 * x * x * x;

}

jLabel5.setText(": " +String.format("%.2f", y)); //       

}



private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

//   

System.exit(0);

}



private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=65425013)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


