.


:




:

































 

 

 

 





, ? paint. , .

, Graphics. , , , , ..

Component paint , Graphics, :

 

public void paint(Graphics g) { g.drawLine(0, 0, getWidth(), getHeight()); g.drawLine(0, getHeight(), getWidth(), 0);

}

Graphics. :

; ;

.

Graphics.

drawLine(x1, y1, x2, y2)

1 , (x1, y1) (x2, y2).

drawRect(int x, int y, int width, int height)

, (x, y), width height

. x+width, y+height.

fillRect(int x, int y, int width, int height)

. x x+width-1 , y y+height-1 . , , :

g.fillRect(0, 0, getWidth(), getHeight());

drawOval(int x, int y, int width, int height)

, , . , (.. ), .

fillOval(int x, int y, int width, int height)

.

drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)

, . startAngle arcAngle. , 3 . . , 90 ( ). "" . , , 45 , .

fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)

, , .

drawString(String text, int x, int y)

, . (x, y) . :

g.drawString("abcdefgh", 15, 15);

g.drawLine(15, 15, 115, 15);

 

repaint update

paint Component , . , paint , , . , . , , . ( ), .

repaint. , Graphics, (, , Graphics ). repaint . . long . . int (x, y, width, height), , . , 5 , .

, paint, update. Graphics

( background), paint. , paint? , , . , , update . , update .

 

, Java (applets). , . . JVM , JVM . [2].

Java, Applet, , , panel. , , . , Panel, FiowLayout. Applet java. applet, , . , .

JVM , main (), . . , .

, .

, main(), init() Applet. Java . Applet:

public void init(){}

init () , Applet. , destroy , . Applet .

init() destroy() Applet , . start() stop(), . stop() , , start() . , [2].

paint(Graphics g) . AWT , , , . , , , paint(Graphics g).

update(). update() repaint, update: repaint();

repaint(time);

repaint(x, y, w, h);

repaint(time, x, y, w, h);

, .

import java.awt.*;

import java.applet.*;

public class HelloWorld extends Applet{

public void paint(Graphics g){

g.drawstring("Hello, XXI century World!!!", 10, 30);

}}

 

HelloWorld.java : javac HelloWorld.java.

HelloWorkLclass, java main(). .

, (tags), HTML (HyperText Markup Language). , <applet>. code, width height . HTML :

<html>

<head><title> Applet</title></head><body> .<br>

<applet code = "HeiioWorid.class" width = "200" height = "100">

</applet>

</body>

</html>

html htm, . HelloWorld.html. , . HelloWorld.html HelloWorld.class , HelloWorld.html

, Internet. , HTML-, <appiet> .

. -, , <applet>. , , . , . , , ,

<applet code = "HelloWorld.class" width = "100%" height = "100%">

-, , . , . , setBackground(Color.white), init ().

<APPLET> [1]:

<APPLET

CODE = appletFile

WIDTH = pixels

HEIGHT = pixels

[ARCHIVE = jarFiles]

[CODEBASE = codebaseURL]

[ALT = alternateText]

[NAME = appletInstanceName]

[ALIGN = alignment]

[VSPACE = pixels]

[HSPACE = pixels]

>

[HTML-,

Java]

</APPLET>

CODE = appletClassFile; CODE , , . codebase, , , CODEBASE.

WIDTH = pixels

HEIGHT = pixels; WIDTH HEIGHT - ,

HTML -.

ARCHIVE = jarFiles; jar - ( ), Web -. , , , . , .

CODEBASE = codebaseURL; CODEBASE , URL ; , ( CODE). , HTML -. , .

ALT = alternateAppletText; ALT , , ( , ) , <applet>, . , HTML -, <applet> </applet> , .

NAME = appletInstanceName; NAME ,

. , , Java Script.

ALIGN = alignment VSPACE = pixels

HSPACE = pixels; , IMG. ALIGN , : LEFT, RIGHT, TOP, TEXTTOP, MIDDLE, ABSMIDDLE, BASELINE, BOTTOM, ABSBOTTOM.

JDK appletviewer. , . Internet-, . Appletviewer :

appletviewer HelloWorld.html

. (status bar) .

str showstatus(string str).

RunningString.Java import java.awt.*; import java.applet.*;

public class Runningstring extends Applet{ private Boolean go;

public void start(){ go = true;

sendMessage(" "); }

public void sendMessage(String s){

String s1 = s+"";

while(go){

showStatus(s);

try{

Thread.sleep(200);

}catch(Exception e){}

s = s1.substring(1)+s.charAt(0);

s1 =s; }

}

public void stop(){

go = false; } }

(Running.zip)

: , . . , Thread, . Runnable. ( bouncingcircle.java).

import java.applet.*;

import java.awt.*;

// ,

// Applet

// Runnable

public class BouncingCircle extends Applet implements Runnable { int x = 150, y = 50, r = 50; //

int dx = 11, dy = 7; // Thread animator; // ,

volatile boolean pleaseStop; //

//

public void paint(Graphics g) {

g.setColor(Color.red); // g g.fillOval(x-r, y-r, r*2, r*2); //

}

// ""

// , .

//

public void animate() {

Rectangle bounds = getBounds();

//

if ((x - r + dx < 0) || (x + r + dx > bounds.width)) dx = -dx; if ((y - r + dy < 0) || (y + r + dy > bounds.height)) dy = -dy;

// , - .

x += dx; y += dy;

//"" paint()

repaint();

}

/* Runnable. , . start()*/

public void run() {

while(!pleaseStop) {// ,

// .

animate();//

try { Thread.sleep(100); }// 100

catch(InterruptedException e) {} //

}

}

//

public void start() {

animator = new Thread(this); //

pleaseStop = false;//

}// , public void stop() { pleaseStop = true; }

}

:

(BouncingCircle)

 





:


: 2018-10-18; !; : 210 |


:

:

, , .
==> ...

1552 - | 1452 -


© 2015-2024 lektsii.org - -

: 0.058 .