.


:




:

































 

 

 

 


Weidhtx, weighty




. , . , , , . , . , . 㳿 Java , , (superclass). , , (subclass). . ³ , . , , extends. .

. , .

.

public public ᒺ , . public - , .

friendly ( friendly !). friendly - ᒺ, , , , .

final- -. ୺ . (, ).

abstract , , , ( ), . , -. , . , , , , ukraineCheck(), russianCheck() . . grammarCheck(), - (, , ).

 

 

  1. , .

Java . . . , . , .

, package, :

package game;

:

1. , ( ).

2. package .

, , . , Animator game, : import game.Animator;

game , , , : import game.*;

. , , : game.Animator a;

 

 

  1. . .

 

, C++, Java. , Java , . , .

? ᒺ, , ᒺ. : final, . , , .

, java.lang.Runnable run(). java- run(), Runnable- . , 䳿 , .

, , , , . , , , . , :

class Shoe implements Product

{ public int getPrice(int id)

{

if (id==1) return 5;

else return 10;

}

public String getMaker()

{

return MAKER;

}

}

implements (), extends.

  1. Java. String.

 

, new ( ), ' String. ' String , ' , - '. ' String , ' .

String , : String (), String (String str), String (byte asciichar []), String (char [] unicodechar), String (StringBuffer sbuf), String (StringBuilder sbuild) ֳ ' String char, byte ,

 

new String (str.getChars (), "UTF-8"),

 

str - Unicode, , . Java , , ' String, . , ' String , , new

 

 

  1. .

-, Java (layout manager). ³ ' , . , , , setLayout(), :

setLayout(new BorderLayout());

FlowLayout ( )

, . , .

:

FlowLayout(); //

FlowLayout(int align); //

FlowLayout(int align, int horp, int verp); //

//

//

align :

FlowLayout.LEFT, FlowLayout.RIGHT, FlowLayout.CENTER.

GridLayout ( )

GridLayout . . .

:

GridLayout(int nRows, int nCols); //

//

GridLayout(int nRows, int nCols, int horp, int verp);

//

// ( )

, , . , 0. , 0. , GridLayout(3, 4) GridLayout(3, 0).

BorderLayout ( )

5 , . BorderLayout - add() , North, South, East, West Center. , .

:

BorderLayout(); //

BorderLayout(int horp,verp); //

//

. , .

add() :

add(int poz, Component comp);

poz , , (North, South, East, West Center).

CardLayout ( )

, ( ). , . , , . , .

GridBagLayout ( )

, . , GridLayout. , . , . . ֳ ᒺ GridBagConstraints, :

gridx, gridy , .

gridx = gridy = GridBagConstraint.RELATIVE, gridx , gridy ;

gridwidth, gridheight , . 1. gridwidth = GridBagConstraint.REMAINDER gridheight = GridBagConstraint. EMAINDER, ( ). , GridBagConstraint.RELATIVE;

fill , , , . ³ :

GridBagConstraint.NONE ( ) ;

GridBagConstraint.HORIZONTAL ,

GridBagConstraint.VERTICAL ,

GridBagConstraint.BOTH ;

ipadx, ipady , ( 0);

insets Insets , ( ), , , ;

anchor . :

GridBagConstraint.NTER ( ),

GridBagConstraint.NORTH, GridBagConstraint.NORTHEAST,

GridBagConstraint.EAST, GridBagConstraint.SOUTHEAST,

GridBagConstraint.SOUTH, GridBagConstraint.SOUTHWEST,

GridBagConstraint.WEST, GridBagConstraint.NORTHWEST;

weidhtx, weighty .

 

 

10. . 11. .

 

 

. java.awt, , , java.awt. event, .

Square ( , java: Square.java) Frame. , 䳿. , ? -, Frame , 쳺 . -, 쳺 䳿 , , . , 쳺 , , . -, Frame, Container, (, ), . Square Frame .

, Square ActionListener. , actionPerformed(), . , 䳿, , .

. ֳ ( ) - . : Check. displayStr .

: (Label). ij, , , , , , .

. - Java super. ,

super("Check Square");

Frame. .

setSize() ( Java resize()). . , , . ϳ add(). button1 addActionListener() 䳿. , . , WindowAdapter 䳿 . show() .

main() Square(). , , , 4. , , .

actionPerformed() . ᒺ evt ActionEvent, , . getActionCommand() , 䳿 ( arg "Check"). equals() String, , "Check", . getText() , parseInt() Integer . displayStr. paint(). ³, paint() . , repaint(), paint().

. , .

 

  1. java.awt. . Component.

, , Java, ' . java.awt (Abstract Window Toolkit), 3.

 

 


3 java.awt

, awt? Java, (GUI). Component. MenuComponent. : Button (), Checkbox ( ), Choice ( Windows), Label (), List ( Windows) Scrollbar ( ). , Component .

java.awt , . Panel . - Container, -, . ³ Window, . : Dialog, , Frame Windows. TextComponent TextField ( Windows) TextArea. Canvas. , 䳿 .

³ Component , ' . , , ( 3):

3 Component

   
getFont() setFont() getFontMetrics()
setForeground() getForeground()
setBackground() getBackground()
preferredSize() minimumSize() ,
resize() size()
show() hide()
  3
   
isVisible() isShowing() true, , false,
disable() enable()
isEnable() true,
paint() update() repaint()
handleEvent() action()
keyDown() keyUp()
mouseDown() mouseUp() mouseDrag() mouseMove() mouseEnter() mouseExit()
   
   
  1. .

- , , -. . awt :

- (Window);

- (Panel);

- (Frame);

- (Dialog).

, , Applet Panel.

Frame, ' .

, '-, , Frame, , . , .

9 Container

add()
add(Component, int) , , '
add(String,Component) ', . , , ': North, South, East, West Center
getComponent(int) ( Component)
getComponents() Component[]
countComponent()
remove()
removeAll().

 

  1. Component ( 13)

 

Component .

 

  1. Panel .

Panel () - , . , Java- . .

:

Panel();

, .

.

Panel mainPanel, suPanel1, subPanel2;

sainPanel = new Panel();

subPanel1 = new Panel();

subPanel2 = new Panel();

mainPanel.add(subPanel1);

mainPanel.add(subPanel2);

add(mainPanel);

 

 

  1. Frame, .

 

Frame ()

Frame. Java- . , Frame . . , :

public class NewWindow extends Frame

{

TextArea output;

public NewWindow (String title)

{

super(title);

}

...

public static void main (String args[])

{

//

NewWindow win = new NewWindow("New Window Class");

//

win.show();

}

}

Frame 10.

10 Frame

pack() ,
getTitle()
setTitle(String)
getIconImage()
setIconImage(Image)
getMenuBar() '
setMenuBar(MenuBar)
remove(MenuComponent)
isResizable() true, , false
setResizable(boolean)
getCursorType()
setCursor(int) : Frame.DEFAULT_CURSOR, Frame.CROSSHAIR_CURSOR, Frame.TEXT_CURSOR, Frame.WAIT_CURSOR, Frame.HAND_CURSOR,...

 

  1. Java. Canvas.

 

Canvas. , 䳿 .

 

  1. .

 

Checkbox ( )

Checkbox . , : "" "". , . ( false).

CheckboxGroup, (radio button ), , . - , ( , ).

:

Checkbox(); //

Checkbox(String str); //

Checkbox(String str, CheckboGroup group, boolean initState);

/* , ( , , null */

5.

5 Checkbox

boolean getState() Checkbox,
getCurrent() CheckboxGroup, ,
SetCurrent() ( CheckboxGroup)
setLabel() getLabel()

. action(), wAboolean, true, , false .

 

  1. Graphics. .

 

getImage() , . ³ ᒺ Image. drawImage(), Graphics. ( ):

public abstract boolean drawImage(Image img, int x, int y,

ImageObserver observer);

public abstract boolean drawImage(Image img, int x,int y,

int width, int height, ImageObserver observer);

Image, getImage(). x y , . drawImage() width () height (), . ! , () . observerImageObserver, . ᒺ , this.

drawImage() . , . , , . , , .

getGraphics() , :

public abstract Graphics getGraphics();

, , .

 

  1. . Font.

 

' Font , : , , , , , , .

TextAttribute. 14.

, . getAvailableAttHbutes() Font.

BACKGROUND . ', Paint
FOREGROUND . ', Paint
BIDI_EMBEDDED г , 1 15
CHAR_ REPLACEMENT Գ, . ' GraiphicAttribute
FAMILY ѳ . String
FONT . ' Font
JUSTIFICATION . ' Float ( 0,0 1,0). : JUSTIFICATION__FULL JUSTIFICATION_NONE
POSTURE . ' Float. : POSTUREJDBLIQUE POSTURE_REGULAR
RUN_DIRECTION : run_direction_ltr , run_DIRECTION_rtl
SIZE . ' Float
STRIKETHROUGH . Ka strikethrough_on ( )
SUPERSCRIPT ϳ . : SUPERSCRIPT_NO, SUPERSCRIPT_SUB, SUPERSCRT_SUPER
SWAP_COLORS . Swap_colorsjdn,
TRANSFORM . ' AffineTransform
UNDERLINE ϳ . : underline_on, UNDERLINE_LOW_DASHED, UNDERLINE_LOW_DOTTED, UNDERLINE_LOW_GRAY, UNDERLINE LOW_ONE_PIXEL, UNDERLINE LOW TWO PIXEL
WEIGHT . : WEIGHT_ULTRA_LIGHT, WEIGHT_EXTRA_LIGHT, WEIGHT_LIGHT .
WIDTH . : WIDTH_CONDENSED, WIDTH_SEMI_CONDENSED, WIDTH_REGULAR, WIDTH_SEMI_EXTENDED, WIDTH_EXTENDED

Font Font(Map attrib), . ' , : HashMap, WeakHashMap Hashtable. , , deriveFont() Font.

Java 2D ' FontRenderContext, , . getFontRendexContext() Graphics2D. , , ' TextLayout. Java 2D FontMetrics. TextLayout , .

  1. 䳿. Event

 

, .

Java EventObject, java.util. . :

EventObject(Object src)

src ᒺ, .

EventObject : getSource() toString(). getSource() 䳿, toString() 䳿.

AWTEvent, java.awt, EventObject. ( ) AWT-, . 䳿 getID(). :

int getID()

java.awt.event , . 11 , . ³, AWTEvent.

11 java.awt.event

ActionEvent , ,
AdjustmentEvent
ComponentEvent , , , 쳭
ContainerEvent ,
FocusEvent ,
InputEvent
ItemEvent , , , ()
KeyEvent ,
MouseEvent , ᒺ (dragged) (moved), (clicked), (pressed) (released) ; ()
TextEvent ,
WindowEvent , , , , , (exit)

 

  1. . .

 

mouseDown() mouseUp() mouseDrag() mouseMove() mouseEnter() mouseExit()

 

  1. . .

 

keyDown() keyUp()

 

  1. . Url Image.

 





:


: 2016-07-29; !; : 723 |


:

:

- , - .
==> ...

1699 - | 1619 -


© 2015-2024 lektsii.org - -

: 0.126 .