• Java dasturchiga derazalar, tarmoqlar va kirish -chiqish tizimlarida ishlatiladigan ko'plab tizim funktsiyalarini aniq ajratish uchun boy sinflar to'plamini beradi. Bu sinflarning asosiy xususiyati shundaki, ular tizim interfeyslarining keng assortimenti uchun platformadan mustaqil abstraktlarni beradi. Sintaksis elementlari:
Satr oxirigacha izoh qoldiring
|
//
|
Ichki joylash mumkin bo'lmagan fikrlar
|
/* ... */
|
Vaziyat sezgirligi
|
да
|
O'zgaruvchan identifikator regex
|
[_a-zA-Z$][_a-zA-Z0-9$]*
|
O'zgaruvchiga qiymat tayinlash
O'zgaruvchan deklaratsiya
Topshiriq bilan o'zgaruvchan deklaratsiya
|
=
|
O'zgaruvchan deklaratsiya
|
type variable
|
Topshiriq bilan o'zgaruvchan deklaratsiya
|
type variable = value
|
Ifodalarni guruhlash
|
( ... )
|
Bloklash
|
{ ... }
|
Tenglik
|
==
|
Tengsizlik
|
!=
|
Taqqoslash
|
< > <= >=
|
Funktsiya ta'rifi
|
public funct(a,b,c) { .... }
|
Funktsional qo'ng'iroq
|
f(a, b, ...)
|
Parametrlarsiz funktsiyani chaqirish
|
f()
|
Keyingi
|
;
|
Agar – keyin
|
if (condition) ...
|
Agar - keyin - aks holda
|
if (condition) ... else ... или condition ? ... : ...
|
Cheksiz sikl
|
while (true) ...
|
Old shart bilan halqa
|
while (condition) ...
|
import java.applet.*;
import java.awt.*;
public class Rectangles extends Applet
{ DrawRectangles m_DrawRectThread = null;
DrawEllipse m_DrawEllipseThread = null;
NotifyTask m_NotifyTaskThread = null;
public String getAppletInfo()
{ return "Name: Rectangles";
}
public void paint(Graphics g)
{ Dimension dimAppWndDimension = getSize();
g.setColor(Color.yellow);
g.fillRect(0, 0, dimAppWndDimension.width - 1,dimAppWndDimension.height - 1);
g.setColor(Color.black);
g.drawRect(0, 0,dimAppWndDimension.width - 1,dimAppWndDimension.height - 1);
}
public void start()
{ if (m_DrawRectThread == null)
{ m_DrawRectThread = new DrawRectangles(this);
m_DrawRectThread.start();
}
if(m_DrawEllipseThread == null)
{ m_DrawEllipseThread = new DrawEllipse(this);
m_DrawEllipseThread.start();
}
if (m_NotifyTaskThread == null)
{ m_NotifyTaskThread =new NotifyTask(m_DrawEllipseThread);
m_NotifyTaskThread.start();
}
}
public void stop()
{ if (m_DrawRectThread != null)
{ m_DrawRectThread.stop();
m_DrawRectThread = null;
}
if (m_DrawEllipseThread == null)
{ m_DrawEllipseThread.stop();
m_DrawEllipseThread = null;
}
if (m_NotifyTaskThread != null)
{
m_NotifyTaskThread.stop();
m_NotifyTaskThread = null;
}
}
}
|
|
Labarotoriya ishlari uchun topshiriqlar.
1. Vektorni tasvirlaydigan klass yarating (uch o'lchovli fazoda).
2. Konstruktori ikkita massivni oladigan sinfni yozing: qiymatlar massivi va qiymatlar massasi.
3. Berilgan element massivda yoki yo'qligini tekshiradigan usulni yozing.
Ushbu muammoni hal qilish uchun ikkilik qidiruvdan foydalaning.
4. Tenglamaning ildizini toping.
Dostları ilə paylaş: |