صفحه 1:
Pee DLs re) Ste Sy
Java)
er ال
صفحه 2:
String nekoSrc[] = {"right1.gif",
"right2.gif", "stop.gif", "yawn.gif",
“scratch1.gif",
scratch2.gif","sleep1.gif",
;"sleep2.gif","awake.gif" }
for (int i=0; i < nekoPics.length; i+
}+)
nekoPics[i] =
,()getimage(getCodeBase
;(images/" + nekoSrc[i]"
1
1
صفحه 3:
} Qpublic void start
1] )۲۷۸۳8۵۲ << (اانام
;runner = new Thread(this)
;)runner.start
i
} Qpublic void stop
srunner = null
if
} Qpublic void run
;setBackground(Color.white)
run from one side of the screen to the //
middle
snekoRun(0, size().width / 2)
صفحه 4:
stop and pause //
;currentimg = nekoPics[2]
;Qrepaint
;pause(1000)
ل"
;currentimg = nekoPics[3]
:)(( ۲
jpause(1000)
rag oll md oe)
يتاه (9)
"sleep for 5 "turns //
;nekoSleep(5)
wake up and run off //
;currentimg = nekoPics[8]
;Qrepaint
;pause(500)
jnekoRun(x, size().width + 10)
صفحه 5:
} void nekoRun(int start, int end)
} for (int i = start; i < end; i += 10)
x=i
// 12305 مد تلاد
if (currentimg == nekoPics[0])
;currentimg = nekoPics[1]
;else currentlImg = nekoPics[0]
{repaint
;pause(150)
if
if
صفحه 6:
۱5 یی ارات ار رت یال
} for (int i = numTimes; i > 0; i--)
;currentimg = nekoPics[4]
:)((
jpause(150)
;currentimg = nekoPics[5]
:)(( ۲
;pause(150)
4
} void nekoSleep(int numTimes)
} for (int i = numTimes; i > 0; i--)
;currentimg = nekoPics[6]
;Qrepaint
;pause(250)
صفحه 7:
;currentimg = nekoPics[7]
;Qrepaint
jpause(250)
{
0
} void pause(int time)
2
;Thread.sleep(time)
{} catch (InterruptedException e) {
{
} public void paint(Graphics screen)
ای یبا توبات را
;screen.drawlmage(currentimg, x, y, this)
{
{
صفحه 8:
نکته
:با وجود اینکه در زبان جاوا آزاد کردن فضای حافظه
|
Gole Graphics -L3! 5490 ۳ Re eyo
نيست. بنابر اين براى ازاد شدن فضاى حافظه اختصاص
داده شده به این شیء به صورت زیر عمل می کنیم.
}Qpublic void destroy
;(offscreenGraphics.dispose
۱
صفحه 9:
ob ت92
puffering, BEC esl oP ial بر ۳۱۳۳
۱ ease EOL ree CRE Lene see ered
کند. برای پیاده سازی بافرینگ دو گانه ابتدا بايد تصوير 01۴56۳661 و
PPPs] green را wr pres)
ESCH) eon) ort) weer
۱۳۹۵9۰ ۵9
;Graphics offscreen
CS Pe neo ل re
۱ teat ل HAE)
offscreenimage = createlmage(size().width,
;size(). height)
;0offscreen = offscreenimage.getGraphics
صفحه 10:
۱
offscreen.drawlmage(bug, 10, 10,
;this)
screen.drawlmage(offscreenimage, 0,
30, this)
"" نكته: مى توانيد متد ©0126131() را ©1110 01/6 نماييد, تا
}public void update(Graphics g)
;paint(g)
1
صفحه 11:
مثال
import java.awt
public class Checkers extends
} java.applet.Applet implements Runnable
‘Thread runner
sint xPos = 5
;int xMove = 4
;Image offscreenimg
;Graphics offscreen
} Qpublic void init
offscreenimg =
;createlmage(size().width, size().height)
:0(۵۲۴56۲۵۵۲ < ۵0۲۲56۲۵۵۱۱۳۸0۰9 ۵۵۲۵۵۳۵
if
صفحه 12:
} Qpublic void start
};if (runner == null)
jrunner = new Thread(this)
تا( Led
i
0
} Qpublic void stop
srunner = null
{
} (public void run
;)Thread thisThread = Thread.currentThread
} while (runner == thisThread)
;xPos += xMove
if ((xPos > 105) | (xPos < 5))
;xMove *= -1
صفحه 13:
(۴
ینز
;Thread.sleep(100)
} catch (InterruptedException e) {
۱
i
{
} public void update(Graphics screen)
;paint(screen)
{
} public void paint(Graphics screen)
Draw background //
صفحه 14:
;offscreen.setColor(Color.black)
soffscreen.fillRect(0,0,100,100)
;offscreen.setColor(Color.white)
soffscreen.fillRect(100,0,100,100)
Draw checker //
;offscreen.setColor(Color.red)
soffscreen.fillOval(xPos,5,90,90)
ني و .ییا 0, 0,
كنطغر
{
} Qpublic void destroy
;Qoffscreen.dispose
{
صفحه 15:
Pe RC Bee ISB) |
Eevesorni i$) ) FWY aeeeae iPS el DSR ne PS LC Ya TS) KC] FT bea
rowed SEs SCS PE IC FAO) o- | NVC Ry
Brrr eet ae لا فایل صوتی)
* با دو آر گومان(-1] لا فایل صوتی و مسیر آن)
;play(getCodeBase(), “zap.au”)
نكته: با استفاده از متدهاى ©1118235 0611006101116( و !"
60206825 ))) به عنوان آركومان متد pune Ulgixe ()Play
فایل اصلی اپلت را به تابع مذکور ارسال کرد.
صفحه 16:
ols
eeogole sapere eel reece) ila EO تزاى بيكش LS
[an eres e Peer eda Leo Be Teese ner ne a
peerel tee mon eee re eine: (120s 1 (1 @l| استفاده از متد
|
AudioClip = getAudioClip (getCodeBase(),
“audio/marimba.wav’)
Pepe ا ال MET OBIT iL!
استفاده نمائيد. بايد به صورت زير عمل كنيد
AudioClip clip = new AudioClip
; (audio/marimba.wav )
Perea eel a en prod eee) eae Ves (6 || ene Leb epee!
کنترل کنید 0
صفحه 17:
۱
Aas Ce mCi) lil Cay
jimport java.applet.AudioClip
ublic class AudioLoop extends
java.applet.Applet implements Runnable
;AudioClip bgSound
;AudioClip beep
‘Thread runner
} Qpublic void start
} if (runner == null)
srunner = new Thread(this)
0
{
{
صفحه 18:
} Qpublic void stop
if (bgSound != null)
;Q0bgSound.stop
تايافك mali
{
{
} Qpublic void init
jbgSound = getAudioClip(getCodeBase(),"loop.au")
jbeep = getAudioClip(getCodeBase(), "beep.au")
صنء لأميا ae
if (bgSound != null)
;0bgSound.loop
:)(۲۳۳6۵۵ ۲۱5۲۳۲۵۵0 < ۲۳۲۵۵ ۲۵۵۵
} while (runner == thisThread)
۷
صفحه 19:
;Thread.sleep(5000)
{} catch (InterruptedException e) {
if (beep != null)
i)beep.play
1
} public void paint(Graphics screen)
screen.drawString("Playing Sounds ...",
10, 10)
if
if
صفحه 20:
نکته
ا ل tee ی
.عمل يخش آن با متوقف شدن ۲۱۲660 اپلت متوقف
Cee nOe I CRT Denny ee) 0
9 نوم
صفحه 21:
Awt
را لت ل ل Poe
ا ا Be Oe
cer ل 0
"" 5 : لشیاء مختلفوكه مىتولنند درونولسط
كاربر قرار كيرند
JoLs as «Containers: Component ®
هاوديكر لست 11
ات 000025
111 01100116هها را درون 20115311361 تعيين مى
5
صفحه 22:
Component 409351 ها به
Container
0 ل ل ال ا petal
0 es
"! ايجاد 111 6011120116
ا ا ا ل كه
توت وله ل 00
™ ا تر ای Container
ee este) nee eee yy) 0
تفر ارف توسط متد
۲( فراخوانی شود.
صفحه 23:
افزودذن 155011نا 011111131108 ©
BS] id
;*.import java.awt
elds class AudioLoop extends
ا
Say note = "I am extremely tired and
“would prefer not
cre be clicked"
tired = new Button(note) م8
Qpublic void init }
jadd(tired)
0
i
صفحه 24:
Age ad
;*.import java.awt
} public class VCR extends java.applet.Applet
;Button rewind = new Button("Rewind")
;Button play = new Button("Play")
;Button ff = new Button("Fast Forward")
;Button stop = new Button("Stop")
;Button eat = new Button("Eat Tape")
} Qpublic void init
jadd(rewind)
00و ز )0۱۵(
:200)۶6(
j;add(stop)
jadd(eat)
0
1
1
۱
صفحه 25:
Label y
Me w wLabel :as ® يس 3 شدن نمایان خواهند شد ونیازی فراخوانی
Meer) Soil aee
لو ال و import
اللا . 31/3 [.*:
} public class Labels extends java.applet.Applet
;Label lefty = new Label("Bleeding heart!")
Label center = new Label("Centrist!",
;Label.CENTER)
Label righty = new Label("Hardliner!",
;Label.RIGHT)
;Font If = new Font("Helvetica", Font.BOLD, 14)
;GridLayout layout = new GridLayout(3,1)
} Qpublic void init
ssetFont(If)
;setLayout(layout)
jadd(lefty)
;add(center)
۲۳ ۱ oval
صفحه 26:
ی
;«.import java.awt: J
eed class CheckACzech extends
| java.applet.Applet
;Checkbox c1 = new Checkbox("Milos Forman")
fone ra c2 = new Checkbox("Paulina
;Porizkova")
;Checkbox c3 = new Checkbox("Ivan Reitman")
;Checkbox c4 = new Checkbox("Tom Stoppard")
;Checkbox c5 = new Checkbox("Ivana Trump")
} Qpublic void init
yadd(c1)
jc2.setState(true)
jadd(c2)
jadd(c3)
jadd(c4)
jadd(c5)
0
صفحه 27:
RadioButton 9955!
* مثال:
;ximport java.awt
leds class AudioLoop extends
} java.applet.Applet
CheckboxGroup p = new
;()CheckboxGroup
Checkbox p1 = new Checkbox("Samuel
;Goldwyn", p, false)
Checkbox p2 = new Checkbox("Krzysztof
;Kieslowski", p, true)
Checkbox p3 = new Checkbox("Klaus
;Kinski", p, false)
Checkbox p4 = new Checkbox("Joanna
;Pacula", p, false)
صفحه 28:
Checkbox p5 = new
Checkbox("Roman Polanski", p,
false)
} Qpublic void init
jadd(p1)
yadd(p2)
jadd(p3)
jadd(p4)
(5م)300:
{
صفحه 29:
اترودن
لت
;x.import java.awt
ublic class SelectASpaniard extends
} java.applet.Applet
;0Choice span = new Choice
} Qpublic void init
;Span.additem("Pedro Almodcvar")
;Span.additem("Antonio Banderas")
;Span.additem("Charo")
;Span.additem("Xavier Cugat")
;Span.additem("Julio Iglesias")
jadd(span)
صفحه 30:
TextBox(TextField) go 55!
Fv) "
7ximport java.awt
ublic class OutOfSite extends
EEC or
;Label siteLabel = new Label("Site Name: ")
;TextField site = new TextField(25)
Label addressLabel = new Label("Site
;Address: ")
;TextField address = new TextField(25)
Label passwordLabel = new Label("Admin
;Password: ")
;TextField password = new TextField(25)
} Qpublic void init
1
1
صفحه 31:
;add(siteLabel)
;add(site)
;add(addressLabel)
;add(address)
;add(passwordLabel)
;(*')password.setEchoCharacter
;add(password)
i
صفحه 32:
افزودن 16218۲65
java.awt فلز تیب
ublic class Virginia extends
0
String letter = "Dear Editor:\n" + "| 8
ears old.\n" +"Some of my little friends say
here is no Santa Claus." +" Papa\n" +
“says, ‘If you see it in The Sun it's so."
Please tell" + " me the truth,\n" + "is there
a Santa Claus?\n\n" + "Virginia O'Hanlon\n"
West 95th Street\n" + "New York 115" +";
2۵
Qpublic void init }
;lt = new TextArea(letter, 10, 50)
yadd(It)
{
f
صفحه 33:
صفحه 34:
Tol go) ل med Ie are yo)
* مثال:
الاج 313[ رمم لولعدر
public class Slider extends
java.applet.Applet }
;GridLayout gl = new GridLayout(1,1)
Scrollbar bar = new
Scrollbar(Scrollbar. HORIZONTAL, 50, 0, 1,
)3100
Qpublic void init }
;setLayout(gl)
j;add(bar)
i
1
صفحه 35:
افزودن 02۱0۷25
7x.import java.awt
public class Crosshair extends
} java.applet.Applet
;GridLayout gl = new GridLayout(1,1)
;0MyCanvas can = new MyCanvas
} Qpublic void init
;setLayout(gl)
j;add(can)
۱
1
i
صفحه 36:
class MyCanvas extends
}java.awt.Canvas
} public void paint(Graphics g)
‘int x = size().width / 2
jint y = size().height / 2
;g.setColor(Color.black)
;g.drawLine(x-10, y, x-2, y)
;g-drawLine(x+10, y, x+2, y)
;g-drawLine(x, y-10, x, y-2)
;g-drawLine(x, y+10, x, y+2)
i
1
صفحه 37:
۱
ape PC Te Siar we Be) و ره رز از ا
استفاده می شود. ۲ 0۷۷/ شامل پنج نوع 121010 به شرح زیر می باشد.
FlowLayout(default)
GridLayout
GridBagLayout
BorderLayout
CardLayout
SEI SN CoLt) SUL rem RP Reel rere ec ole eee eS ee FB
نمود.
;0FlowLayout layout = new FlowLayout ®
dlsic & ) of (SetLayout sz j1 estan! b Layout stu! jl jn
ا لا-] جارى سيستم در نظر مى كيريم. يس از تعيين 4لا © لا3-! جارى
200 2 ال Leal -11 ate) nC ey
صفحه 38:
FlowLayout
cuiy bComponent اكر از اين 0101لا استفاده كنيد ""
Coes eee Meo eee ie ee ee eS een)
00 تال
لل ل شوند. اگر می
خواهيد :111 011120136)ها در سمت جب يا راست درج شوند
FlowLayout.LEFT (slgite55 11 5 &
wu osu! FlowLayout. RIGHT
صفحه 39:
مثال
import java.awt
ublic class Alphabet extends
java.applet.Applet
;sButton a = new Button("Alibi")
;Button b = new Button("Burglar")
;Button c = new Button("Corpse")
;sButton d = new Button("Deadbeat")
;Button e = new Button("Evidence")
;Button f = new Button("Fugitive")
FlowLayout Im = new
;FlowLayout(FlowLayout.LEFT)
صفحه 40:
} Qpublic void init
Ta eet setup)
jadd(a)
yadd(b)
200)60(
jadd(d)
jadd(e)
;add(f)
i
1
0
eed ل ا لت ار نانفا
ا را 7
Ce ere NO Dee eee ee Ler EDT ee (mth lee Ne Seon
به صورت زير عمل مى كنيم.
FlowLayout layout = new
;FlowLayout(FlowLayout.LEFT, 10, 30)
صفحه 41:
GridLayout
Preece ele son) ل ee
)ها به حالت 63۲۱01 پشت سر هم قرار ۴
00 ل ا be
0 ل ل Cia lo) Ry Colt ia
USPC Perel a Seeley Cp) In ye wes De agce] |
آر گومان سوم بیانگر فاصله ی بین 131 011312013©6©ها و
ا
GridLayout gr = new GridLayout(10, 3,
:5, 8(
ا ا ا ل لا الا الا اا 000 | الال ل ل 00
صفحه 42:
مثال
;x.import java.awt
ublic class Bunch extends
Je eee:
GridLayout family = new
;GridLayout(3,3,10,10)
;Button marcia = new Button("Marcia")
;Button carol = new Button("Carol")
;Button greg = new Button("Greg")
;Button jan = new Button("Jan")
;Button alice = new Button("Alice")
;Button peter = new Button("Peter")
;Button cindy = new Button("Cindy")
;Button mike = new Button("Mike")
;Button bobby = new Button("Bobby")
صفحه 43:
[ (0۷۳۱۱6 ۷ g
;setLayout(family)
لیا ها
;add(carol)
;add(greg)
jadd(jan)
sadd(alice)
;add(peter)
;add(cindy)
;add(mike)
;add(bobby)
if
if
صفحه 44:
BorderLayout
Prep ye eye an remorse اي
مرکز تقسیم می کند. متد سازنده این کلاس به دو صورت قابل دسترسی می باشد.
1 ee See Pacey ee e111) ا Renee Srey OI Rey ial
;0BorderLayout
Eee SiN crac Sewer Mer tele 8] ا
تعیین کننده فاصله عمودی خواهد بود.
;BorderLayout(int, int)
Soro o er eee elie رو توا 11) ae eMUnE SCY) Te al
عمل كنيم
add(String, Component)
"" آركومان اول(51611136) مى تواند داراى يكى از مقادير :501011 :0111 للا
۲ ,51 با 6۲۱۴۵۲ باشد و بیانگر محل قرار گرفتن
11 فى باشد .
صفحه 45:
co
import java.awt a
} public class Border extends java.applet.Applet
;)BorderLayout b = new BorderLayout
;Button north = new Button("North")
;Button south = new Button("South")
;Button east = new Button("East")
:-Button west = new Button("West")
;Button center = new Button("Center")
} Qpublic void init
jsetLayout(b)
;add("North", north)
;add("South", south)
;add("East", east)
;add("West", west)
;add("Center", center)
1
0
صفحه 46:
ror |: 3 1
اضافى به 1 013831136) اصلى (در أينجا ۱
tL) Bike neem one ees 0 ا 0000
استفاده کرد .هنگام استفاده از ۴3۲06ها به موارد زیر توجه کنید:
افزودن :131 01131]201316© ها بها 2310 قبل از افزودن /23136 وت و رز ۱۳۳۱
eh
cul GSlae Layout 6)ls Panel »»
Were Ne IC be )1 1
;0Panel pane = new Panel
Pee See SECS OBI ل ل pe)
;0BorderLayout bo = new BorderLayout
jpane.setLayout (bo)
CoC Jel ST eee ee ل CMLL Lela لل NCe ey
Par ا ا رز pence Se MeCAEIN CPE NTY.V«) 0] (<1 dee CB enor 9
penne Te Ske ore na LT
j;pane.add(dialogue)
صفحه 47:
CardLayout
Component t Container sss; JolsLayout .| "" ۱۳
ا ا eee
orn Ia pe ا م OG
وا ای کار 313©1اول اضافه مى كنيم و
اللي از Pe SEN
تا
;()CardLayout cc = new CardLayout
Pete cL ele) oll eel teerott beies bec ie
استفاده می شود .
;setLayout (cc)
صفحه 48:
۱
1.add (String, Component);
2.add( String, Container)
"ا نكته: قبل از افزودن يى ([1)©2160 60118231116 بايد تمام
111 2اههاى لازم به آن 30101 شود. بعد از افزودن
هگ
0۷ استفاده کرد .اين متد دارای دو آر گومان به شرح
زیر می باشد.
۳ شاملتمام کارنهادر صورتیکه
000117 مذكور Bs) eae pee et Applet ات
7 0
* نام کارت
صفحه 49:
مثال
import java.awt
ublic class BurmaShave extends
implements Runnable ا د د
;)CardLayout card = new CardLayout
;Label[] lab = new Label[6]
0 د غمعسيك غخصار
‘Thread runner
PTO) ICM eit laa
if (runner == null) }
;runner = new Thread(this)
la تا(
{
} Qpublic void stop
srunner = null
1
صفحه 50:
} Qpublic void init
jlab[0] = new Label("Grandpa's beard")
jlab[1] = new Label("Was stiff and coarse.")
lab[2] = new Label("And that's what
;caused")
jlab[3] = new Label("His fifth")
jlab[4] = new Label("Divorce.")
jlab[5] = new Label("Burma Shave.")
;setLayout(card)
for (int i = 0; i < 6; i++)
;add("Card " + i, lab[i])
1
صفحه 51:
ادامه دارد...
* برای اطلاع از قسمت های بعدی به سایت مراجعه کنید.