.


:




:

































 

 

 

 


Java. . String, StringBuffer StringBuilder




String . String , , 0 2*109. String , :

A, abcd, abcd, , .

. - .

. , \n. , .

, .

Java . A , 'A' ASCII A. .

: s1 s2 , s1+s2 , () , s1 s2. ,

String s= + ;

s .

+=. s1 s2

s1+=s2 s1=s1+s2.

( ) String. String , , . , . , .

==. ,

String s1=" String";

String s2="";

s2+=" String";

if(s1==s2)

System.out.println("s1 s2");

else

System.out.println("s1 s2");

s1 s2, - . equals. s1==s2 s1.equals(s2), s1 s2.

,

String s1="";

String s2="";

if(s1==s2)

System.out.println("s1 s2");

else

System.out.println("s1 s2");

s1 s2. , Java , -.

 

, , , , .

String . . s1 subS String, charArray char[], ch1 char, i, index1 count (, ) .

String.valueOf() String, . .

String.valueOf(charArray, index1,count) , , count , index1.

 

String . .

s1.charAt(i) s1, i ( ).

s1.endsWith(subS) true , s1 , subS.

s1.equals(subS) - true , , s1, , subS.

s1.equalsIgnoreCase(subS) , ( ).

s1.getBytes() byte[], - .

s1.getBytes(charset) , (charset). charset ISO-8859-1 ( 8- ), UTF-8, UTF-16 ( UNICODE) .

s1.indexOf(subS) , s1 subS.

s1.indexOf(subS,i) i, s1 subS.

s1. lastIndexOf (subS) , s1 subS.

s1. lastIndexOf (subS,i) i, s1 subS.

s1.length() ( 16- UNICODE, ). .

s1.replaceFirst(oldSubS,newSubS) s1, oldSubS newSubS.

s1.replaceAll(oldSubS,newSubS) s1, oldSubS newSubS.

s1.split(separator) String[], s1 , separator. , separator, . .

s1.split(separator, i) , i . s1, , . i 0 , . i <0 , .

s1.startsWith(subS) true , s1 subs.

s1.startsWith(subs, index1) true , s1 index1 subs.

s1.substring(index1) , s1 index1.

s1.substring(index1,index2) , s1 index1 index2.

s1.toCharArray() , s1.

s1.toLowerCase() , s1, ( ). , (locale).

s1.toUpperCase() - , s1, ( ). , (locale).

s1.trim() s1, .

Object toString(), . , , . Object ( ), @, - (, ) . -, , . . , toString() . - , ( Char) - .

+ += , , , toString() . () . , . ,

String s=1+2+3;

s==6.

String s= =+1+2+3;

=123. , , . =+1. , . toString(), . =1. =1 2. toString(), . =12. =12 3.

String s=1+2+ +1+2;

,

3 12.

, . , ?: , .

, . ,

Byte.parseByte()

Short.parseShort()

Integer.parseInt()

Long.parseLong()

Float.parseFloat()

Double.parseDouble()

valueOf(), Byte, Short, Character, Integer, Long, Float, Double. ,

Byte.valueOf(), ..

, Integer Long :

Integer.toBinaryString()

Integer.toHexString()

Long.toBinaryString()

Long.toHexString()

(Byte, Short, Integer, Long) decode:

Byte.decode(), ..

:

Character.isDigit() , , .

Character.isLetter() , , .

Character.isLetterOrDigit() , , .

Character.isLowerCase() , , .

Character.isUpperCase() , , .

Character.isWhitespace() , , , , ..

, StringBuffer StringBuilder. , ( , , ). , , String. StringBuffer , (threads) , String StringBuilder, . StringBuilder, JDK 1.5, , . ( ).

, , . StringBuffer StringBuilder sb.append(s), sb s. sb.insert(index,s), , index, s.

:

StringBuffer sb=new StringBuffer();

sb.append(" StringBuffer");

sb.insert(0," ");

System.out.println(sb);

append insert

:

s1.contentEquals(sb) , true , s1 , sb.

java.awt.Graphics. , .

, w- , h- ; x,y- . x,y- , .

 

Color getColor() .
setColor(Color c) .
Font getFont() .
setFont(Font f) . Font( , , )
FontMetrics getFontMetrics()
FontMetrics getFontMetrics(Font f) f
setXORMode(Color c1)   XOR ( ) c1. color , color ^ c1 ( color XOR c1) RGB- . .
setPaintMode()   XOR.
translate(x0,y0) x0,y0. , , .
drawLine(x1,y1,x2,y2) x1,y1 x2,y2
   
drawRect(x,y,w,h) .
drawRoundRect(x,y,w,h,arcWidth,arcHeight)   .
draw3DRect(x,y,w,h,isRaised) . isRaised ==true, (raised), - .
drawPolygon(Polygon p); drawPolygon(int[] xPoints, int[] yPoints, int nPoints) , nPoints .
drawPolyline(int[] xPoints,int[] yPoints, int nPoints) , nPoints .
drawOval(x,y,w,h) .
drawArc(x,y,w,h,startAngle,arcAngle) . startAngle , arcAngle, .
drawImage(Image img,int x,int y, ImageObserver observer) .
clearRect(x,y,w,h) ( )
fillRect(x,y,w,h) , .
fillRoundRect(x,y,w,h,arcWidth,arcHeight) , .
fill3DRect(x,y,w,h, isRaised) , . isRaised ==true, (raised), - .
fillPolygon(Polygon p) fillPolygon(int[] xPoints, int[] yPoints, int nPoints) , .
fillOval(x,y,w,h) , .
fillArc(x,y,w,h,startAngle,arcAngle) , . , , .
copyArea(x,y,w,h,dx,dy) , dx,dy
drawString(s,x,y) s
drawChars(char[] data,int offset,int length,int x,int y)
drawBytes(byte[] data,int offset,int length,int x,int y) ,
setClip(x,y,w,h) setClip(Shape clip) . ( ).
clipRect(x,y,w,h) .
Rectangle getClipBounds() Rectangle getClipBounds(Rectangle r) , .
Graphics create() g1=g.create()- g
dispose() - ( , ).

 

, .

 

java.awt.Graphics g,g1;

 

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

java.awt.Graphics g,g1;

g=jPanel1.getGraphics();

int x1=20,x2=120,y1=20,y2=120;

int x3=20,y3=20,w3=60,h3=80;

int x4=30,y4=60,w4=30,h4=40;

int x0=10,y0=10,w0=10,h0=10;

int w1=80,h1=120;

g.setClip(0,0,60,80);//

g.drawLine(x1,y1,x2,y2);//

g.drawOval(x3,y3,w3,h3);//

g.clipRect(x4,y4,20,20);//

g.clearRect(x4,y4,w4,h4);//

g.setClip(0,0,200,280); //

g.copyArea(x1,y1,w1,h1,60,0);

g.draw3DRect(10,20,w1,h1,false);

g.drawPolygon(new java.awt.Polygon(new int[]{10,10,20,40},

new int[]{10,20,30,60},4));

}

: . , .

, , paint, . :

 

 

public void paint(java.awt.Graphics g){

super.paint(g);

g=jPanel1.getGraphics();

...

}

, ,

private void jPanel1ComponentResized (java.awt.event.ComponentEvent evt) {

...

}

, , . . .

- . , . update(Graphics g). :

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

FiguresUtil.moveFigureBy(figure,dx,dy);

update(g);

};

. , . : , . , , .

 





:


: 2017-02-28; !; : 813 |


:

:

, , . , .
==> ...

1564 - | 1396 -


© 2015-2024 lektsii.org - -

: 0.07 .