Teach Yourself Java in 21 Days


An Introduction to Java Programming



Download 5,76 Mb.
Pdf ko'rish
bet53/54
Sana30.12.2021
Hajmi5,76 Mb.
#97759
1   ...   46   47   48   49   50   51   52   53   54
Bog'liq
LearnJava

An Introduction to Java Programming

M

T

W

R

F

S

S

DAY

DAY

1

P2/V4sqc7    TY  Java in 21 Days   030-4  sdv   12.22.95    Ch01   LP#4



Listing 1.2. The Hello World applet.

1: import java.awt.Graphics;

2:

3: class HelloWorldApplet extends java.applet.Applet {



4:

5:     public void paint(Graphics g) {

6:        g.drawString(“Hello world!”, 5, 25);

7:    }


8:}

Save that file inside your 

HTML

 directory. Just like with Java applications, give your file a name



that has the same name as the class. In this case, the filename would be 

HelloWorldApplet.java

.

Features to note about applets? There are a couple I’d like to point out:



The 



import

 line at the top of the file is somewhat analogous to an 

#include

 statement

in C; it enables this applet to interact with the JDK classes for creating applets and for

drawing graphics on the screen.



The 



paint()

 method displays the content of the applet onto the screen. Here, the

string 

Hello World

 gets drawn. Applets use several standard methods to take the place

of 


main()

, which include 

init()

 to initialize the applet, 



start()

 to start it running,

and 

paint()


 to display it to the screen. You’ll learn about all of these in Week 2.

Now, compile the applet just as you did the application, using 

javac

, the Java compiler.



javac HelloWorldApplet.java

Again, just as for applications, you should now have a file called HelloWorldApplet.class in your

HTML directory.

To include an applet in a Web page, you refer to that applet in the HTML code for that Web

page. Here, you create a very simple HTML file in the HTML directory (see Listing 1.3).


Download 5,76 Mb.

Do'stlaringiz bilan baham:
1   ...   46   47   48   49   50   51   52   53   54




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish