Java Kitap
Java Kitap
Java Programlama dili ºu anda dünyadaki en popüler programlama dillerinden biri haline
gelmiºtir. Java SUN bilgisayar ºirketince orijinal olarak elektrikli ev araçlarýnýn (mikrodalga
fýrýnlarý, buzdolaplarý , televizyonlar, uzaktan kumanda cihazlarý vs.) birbiriyle haberleºmesini
saðlamayý amaçlayan bir proje içerisinde 1991 yýlýnda geliºtirilmeye baºlandý. Orijinal adý bu
dilin yaratýcýlarý James Gosling, Patrick Naughton, Chis Wartdh, Ed Frank ve Mike Sheridan
tarafýndan Oak olarak konulan programlama dili daha sonra bu isimde baºka bir
programlama dili olduðu keºfedilince o anda bir kahvehanede kahve içen programlama
gurubu tarafýndan kahve markasýndan esinlenerek Java olarak deðiºtirildi. Akýllý elektronik ev
araçlarý pazarý SUN gurubunun tahminlerinden çok daha yavaº bir geliºme gösteriyordu. Bu
yüzden Java dili projesi ticari bir geliºtirme projesi olarak büyük olasýlýkla iptal edilecekti.
1993 Yýlýnda "World Wide Web" büyük bir atýlým göstererek bütün dünyaya yayýlmaya
baºladý. Javanýn Dinamik Web sayfalarý hazýrlamadaki büyük potansiyelini gören SUN ºirketi
projeyi bu tarafa yönlendirdi ve bu javaya yeni bir canlýlýk ve yaºama umudu saðladý.
Mayýs 1995 de SUN javayý büyük bir konferansta tanýttý. Program iº dünyasý tarafýndan
derhal büyük bir ilgiyle karºýlandý. Java Modern bilgisayar dünyasýnýn ses, grafik iºlem,
haberleºme gibi ihtiyaçlarýna cevap verebilen ve Ticari gayeler için hazýrlanan bir Program
dili olarak daha önceki bilgisayar dillerinin hiç birinin kapsayamadýðý özellikleri içermekteydi.
Bunun yaný sýra dil komut yapýsý olarak C++ diline çok yakýn olmasý da öðrenilmesini
kolaylaºtýrýyordu. SUN Javayý "World Wide Web" de kullanmak isteyen herkese ücretsiz
olarak sundu. Java internette yayýnlanmasýnýn ardýndan çok büyük bir patlama yaºadý. 1997
ye gelindiðinde dünyadaki bütün bilgisayar okullarýnda temel bilgisayar dili olarak
gösterilmeye baºlandý. Dünyada ºu anda hala en çok kullanýlan bilgisayar dili olan C++ dilinin
yapýlan hatalarý tam olarak denetlememesi programýn çalýºma hýzýný arttýrma yönünden iyi bir
özellik olsa da profesyonel programcýlar dýºýnda kullanýlmasýný sýnýrlandýrýcý bir etki
yapýyordu. Java ise bütün hatalarý bildiren yapýsý ve modern bilgisayarýn bütün
fonksiyonlarýna ulaºabilen kütüphaneleriyle programcýlarýn çok daha kolaylýkla
öðrenebileceði bir dildir. Burada hemen ºunu da belirtelim. C dili hýzlý çalýºma amacý birinci
planda tutularak yaratýlmýº bir dildir. Javada ise emniyet ilk planda yer almýºtýr. Hýz açýsýndan
düºünüldüðünde java C (ve C++) diliyle rekabet edemez. zaten program derleyicisi de C++
dilinde yazýlmýºtýr.
Javanýn diðer önemli bir temel özelliði Nesne kökenli (object oriented) bir dil olmasýdýr.
Nesne kökenli diller, nesneleri gerçek dünyadakine daha benzer bir yapýda tanýmlayarak
anlaºýlmalarýný kolaylaºtýrýrlar. Nesneleri gerçek dünyadaki gibi masa, sandalye, bilgisayar,
gerçek gaz, ýsý eºanjörü gibi tanýmlayarak programlamak insan beyninin anlamasý açýsýndan
çok daha kolaydýr. Bundan önceki tam nesnel kökenli programlama dillerinden hiçbiri çok
yaygýnlýk kazanmamýºtý. Bu tür dillere Smalltalk,u Örnek verebiliriz. C++ nesnel kökenli
programlama yapabilen bir dildir. Fakat yapýsal (structural) birprogramlama dili olan C dilinin
bir uzantýsý olarak geliºtirildiðinden tam anlamýyla nesnel kökenli bir dil olduðu söylenemez.
Java dilini geleceðin dili yapan diðer bir özelliði de çok kullanýmlý (multi-tasking) ve paralel
kullanýmlý(multi-treading) bir dil olmasýdýr. Çok kullanýmlýlýk birden fazla iºlemin ayný anda
yapýlabilmesinin tanýmýdýr. Paralel kullanýmlýlýk ise birden fazla programýn ayný anda hafýzayý
beraber kullanarak kullanýlabilmesidir. Örnek olarak World ve Excel programlarýnýn Windows
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
NT ortamýnda ayný anda kullanýlmasýdýr. ADA gibi bazý eski Program dillerinde çok
kullanýmlýlýk programlanabiliyordu. Paralel kullaným olanaklarýný sunan ilk bilgisayar dili ise
javadýr. Paralel kullaným paralel programlama kavramýndan ayrýdýr ve karýºtýrýlmamalýdýr.
Paralel programlanmada birden fazla Bilgi iºlem Ünitesine (CPU ) ayrý programlar veya bir
programýn ayrý parçalarý gönderilir. Paralel kullanýmda ise bir CPU nun kullaným zamaný
küçük parçalara ayrýlarak deðiºik Program veya Program parçacýklarý bu zaman
paketçiklerini paylaºarak kullanýrlar.
Javayý önemli bir Program dili haline getiren en önemli özelliði ise kullanýlan bilgisayardan
baðýmsýz olmasýdýr. Javada yazýlan bir Program Unix, Machintosh, Windows 95 veya
Windows NT veya herhangi bir 32 bit makinada hiç deðiºtirilmeden kullanýlabilir. Java
programlarýnýn grafikleri "Wold Wide Web" sayfalarýnýn programlama dili olan html (hypertext
markup language) ile aktarýlýr. Bu yüzden html ve java programlarýný birlikte kullanmak ve
java programlarýný gerçek zamanda www sayfalarýnda göstermek mümkündür. Kendi web
sayfanýzý veya webde yazýlmýº kitabýnýzý bütün dünyaya aktarýrken yaptýðýnýz analizleri de bu
kitabýn dinamik bir parçasý olarak sunabilirsiniz. Bu Türkiye gibi ülkelerin dünyaya kapýlarýný
daha kolay açmalarý açýsýndan oldukça önemli bir özelliktir.
Javanýn HTML diliyle kullanýlabilmesi, bazý kiºilerde htmlin bir parçasý olduðu gibi bir kavram
geliºmesine yol açmiºtir. Programlamaya yeni baºlayanlar sýk sýk html ile javayý birbirine
karýºtýrýrlar. veya javanýn HTML'nin bir uzantýsý olduðunu düºünürler. Bu temelde oldukça
yanlýº bir varsayýmdýr. HTML internet belgelerini birbirine baðlamak amacýyla geliºtirilmiº bir
belge iºlem sistemidir ve bir programlama dili deðildir. HTML ile javanýn tek gerçek ilgisi
HTML deki applet komutudur. bu komut yardýmýyla java dilinde yazýlmýº programlarýn
sonuçlarý HTML ortamýna dinamik olarak aktarýlabilir.
ªüphesiz programý yazmadan önce Java compilerýnýn bir kopyasýný edinmeniz de gerekir.
Java geliºtirme seti (Java Developers kit - JDK) SUN bilgisayar ºirketinin
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
veya
[Link]
Java programý [Link] seklinde editörle yazýlýr. Java programýnýz yazýldýktan sonra ilk step
java derleyici (compiler) programýyla [Link] ara bilgisayar kodunu oluºturmaktýr.
Java programýný yazarken dikkat etmeniz gereken diðer bir özellik de javanýn nesne sýnýfýnýn
ismiyle dosyadaki isminin ayný olmasýdýr. Bilgisayar konsol ekranýnda (DOS veya UNIX
Console)
javac [Link]
java isim
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
komutu kullanýlarak sonuçlar ekranda veya açýlan bir pencerede görülebilir. Eðer Program
applet ortamýnda yazýlmýºsa java programýna ilave olarak html dilinde [Link] dosyasý
açýlýr. En basit ºekilde html dosyasý ºu ºekilde tanýmlanabilir :
<html >
</applet >
</html>
Buradaki width pencerenin enini pixel olarak, height’da yüksekliðini yine pixel(görüntü
noktasý) olarak vermektedir. daha sonra bu dosya konsoldan
appletviewer [Link]
Programcýlýkta adeta adet haline gelen ilk uygulama daima o dilde ekrana Hosgeldiniz çiktisi
almaktýr. Bizde bu kuralýn dýºýna çýkmayalým. Aºaðýdaki listede ilk konsol programýmýz
[Link] görülmektedir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bu programý çalýºtýrmak için
javac [Link]
java Hosgeldiniz
Yazýsýný alýrýz.
import [Link].*; Bu deyim java konsol girdi çýktý kütüphanesindeki metotlarý programýmýza
aktarýr.
class Hosgeldiniz Class (sýnýf) nesne kökenli programlama yapýsýnýn temel taºýdýr. Her
Class'ýn kendine özgü bir ismi olmasý gerekir. Daha önce yazýlmýº Class'lar import
deyimiyle programa çaðýrýlabilirler. Yeniden yazýlmalarý gerekmez. Class yapýsý ve
tanýmlamalarý üzerinde daha sonraki bölümlerde çok daha detaylý bilgi verilecektir.
{ } baºlatma ve bitirme : Sýnýf tanýmlamasý da dahil olmak üzere Tüm Program parçacýklarý {
iºaretiyle baºlar ve } iºaretiyle son bulur. {} iºaretleri arasýnda yazýlan program
parçacýklarýný normal metin yazýlmasýndaki paragraf kavramýna benzetebiliriz. Ayrýca
program koduna baktýðýmýzda "; " iºaretine sýk sýk rastlýyoruz. Bu iºaret java komutunun
bittiðini belirtir. Cümle yaðýsýnda kullanýlan nokta ". " iºareti gibi iºlev görür. Java
programlarýný istersek " ;" ve "{} " ayraçlarýný kullanarak tek bir satýr olarak yazabiliriz. Fakat
bu programýn bizim tarafýmýzdan okunurluðunu zorlaºtýrýr. Program kodunu yazarken boºluk
ve satýr aralýklarý býrakarak insanlar tarafýndan programýn okumasýný kolaylaºtýrabiliriz.
Modern programcýlýktaki en büyük sorunlardan biri bigisayar kodlarýnýn bakým ve onarýmý
sorunudur. Ticari olarak yazýlan her programýn belli bir ömrü olduðunu ve daha sonra
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
baºka bir programcý tarafýndan üzerinde tekrar çalýºýlacaðýný sürekli olarak hatýrlamak
zorundayýz.
public static void main(String args[]) diðer dillerde fonksiyon (function), subroutine,
procedure gibi adlarla anýlan Program alt parçacýðýnýn baºlýðý. Bu Program parçacýklarý
javada Metot (Method) adýyla anýlýr. Metotlarýn girdileri ve çýktýlarý olabilir. Bu metotun adý
main (ana Program) dýr. String deðiºken türü args[] deðiºkeni girdi olarak girebilir. Bu
metotta void çýktý türü kullanýlmýºtýr. Void kelimesi bu metotdan hiçbir çýktý alýnmayacaðýný
belirtir. public metota dýºarýdan ulaºýlabilme izni verir.
"Java Sinifina Hos Geldiniz!" stringi aynen aktarýlýrken içinde c dilinde kullanýlan temel
kontrol terimleri yer alabilir ve aynen c dilindeki anlamlarýyla kullanýlabilir. Bu kontrol
terimlerinden en yaygýn olarak kullanýlan bazýlarý:
\\ \ iºaretini yaz
\” “ iºaretini yaz
ºeklinde gösterilebilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.2 [Link] programý
import [Link] ;
class HosgeldinizSW {
"HosgeldinizSW programý",JOptionPane.INFORMATION_MESSAGE);
[Link](0) ;
Bu programý
javac [Link]
ve
java HosgeldinizSW
[Link]
ªekil 1.1 HosgeldinizSW dosyasýnýn konsol SWING pop-up grafik çýktýsý kullanarak
görülmesi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu çýktýyý alabilmek için java SWING kütüphanesi içerisinde yer alan
[Link](....) metodunu kullandýk. Bu metodun görevi
[Link] metoduyla aynýdýr. Farký ise grafik ortamda çýktý vermesidir. Metot içindeki
ikinci sýrada verilen String tipi sabit , "Java sýnýfýna hoº geldiniz!" grafik çýktýya aktarýlmýºtýr.
Üçüncü sýrada verilen string tipi "HosgeldinizSW programi" sabiti de grafik kutusunun adýný
belirtmiºtir. JoptionPane.INFORMATION_MESSAGE komutu ise bilgi (information) mesajý
penceresi açýlacaðýný belirtmiºtir. (grafikteki i harfi – information – bilgi kelimesinin baº
harfidir). Bu alanda kullanabileceðimiz diðer alternatifler ºunlardýr :
Üçüncü konsol program örneðimizde iki java programýný birleºtireceðiz Ýlk programýmýz
[Link] Program 1.3 de verilmiºtir. Program 1.4 ise [Link]
programýný kapsamaktadýr. BasicWindowMonitor programýný bundan sonraki
programlarýmýzda sýk sýk kullanacaðýz.
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Window w=[Link]();
[Link](false);
[Link]();
[Link](0);
import [Link].*;
import BasicWindowMonitor;
[Link](new BasicWindowMonitor());
[Link]().add(etiket);
[Link]();
[Link](true);
Burada iki ayrý program bulunmaktadýr. Bu iki programlýk seti çalýºtýrmak için önce iki
programý da derlemek gerekir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
javac [Link]
javac [Link]
java HosgeldinizSWF
[Link]
ªekil 1.2 HosgeldinizSWF dosyasýnýn konsol SWING JFrame pop-up grafik çýktýsý
kullanarak görülmesi
Görüldüðü gibi burada yazma iºlemini yaptýrmak için tek bir komut yerine bir komutlar ve
metotlar zinciri kullanýldý. Bu program swing grafik kütüphanesiyle grafik formatýnda çýktý
almanýn çok daha standart bir yoludur. Temel olarak SWING grafik penceresine JLabel sýnýf
tipi etiket eklenerek yazý grafik ekrana aktarýlmýºtýr.
Program 1.5 de yine swing metodu kullanýlmýºtýr. Buradaki küçük farklýlýk bir önceki
HosgeldinizSWF programýnda kullanýlan Jlabel nesnesi üzerinden yazdýrma yerine paint
metodunun kullanýlmýº olmasýdýr. Burada da BasicWindowMonitor programý kullanýlmýºtýr.
fakat bu programý daha önce derlemiº olduðumuzdan tekrar derlememiz gerekmez. Sadece
javac [Link]
java Hosgeldiniz1SWF
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.5 [Link] programý
import [Link].*;
import [Link].*;
import BasicWindowMonitor;
[Link](new BasicWindowMonitor());
[Link](160,50);
[Link](true);
Program çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.3 [Link] dosyasýnýn konsol SWING pop-up grafik çýktýsý
kullanarak görülmesi
metodunu kullanarak pencere ortamýna aktardýk. bu metodda kullanýlan 10,40 deyimi yazýnýn
grafik ortamýndaki x ve y koordinatlarýný göstermektedir. y koordinatý yukardan aºaðý doðru
tanýmlanmýºtýr.
[Link](160,50);
[Link](true);
ªimdi de applet grafik ortamýnda çýktý almaya örnek verelim. Ýlk applet programýmýz
[Link] listesi Program 1.6 da verilmiºtir
import [Link];
import [Link].*;
public class HosgeldinizApplet extends Applet
{
public void paint(Graphics g)
{
[Link]("Java sýnýfýna hoº geldiniz!",25,35);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bu programý çalýºtýrmak için önce [Link] HTML dili programýný yazmamýz
gerekir
<html >
</applet >
</html>
bu html kodunda
javac [Link]
appletviewer [Link]
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.4 [Link] dosyasýnýn appletviewer programý kullanarak
görülmesi
Bu programýnda temel olarak bazý farklýlýklar dýºýnda bir önceki programlara benzediðini
gözlemleyebiliriz. Bu programýn temel farký internet ortamýndan herhangi bir bilgisayardan da
(gerekli ayarlama ve kopyelemelerden sonra) görülebilir olmasýdýr.
import [Link];
import [Link].*;
public void paint(Graphics g) deyimi appletin grafik olarak çizilmesini saðlar. Bu Metot
Graphics sýnýfý g nesnesini girdi olarak kullanýr. Metotun çýktýsý yoktur.
Bu programda temel grafik kütüphanesi olarak abstract window toolkit (awt) kullanýlmýºtýr.
ayrýca konsol programlarýndan farklý olarak bu programda main metodunun kullanýlmadýðýna
da dikkat ediniz. bir program hem applet hem de konsol olarak da oluºturulabilir, yani hem
main metodu olabilir hem de applet (html) ortamýnda çalýºabilir.
Ayný appleti oldukça benzer bir ºekilde SWING kütüphanesini kullanarak da oluºturabilirdik.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link];
[Link]
Bu programdaki
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class HosgeldinizSWA extends JApplet
deyimi HosgeldinizAppletSWA isimli sýnýfý (class) yaratýr. Bu sýnýf swing sýnýfýndaki JApplet
sýnýfýnýn bir devamý olarak tanýmlanmaktadýr ( extends JApplet). Diðer bir deyimle JApplet
sýnýfýnýn bütün metotlarý extends deyimiyle HosgeldinizAppletSWA sýnýfýmýzýn içine
kopyalanmýºtýr.
Ayný iºi yapmak için bir çok deðiºik program yazdýk. Bazýlarýmýz buna ne gerek vardý, tek bir
ºekilde bu iºi halledemezmi idik diyebilirler. Haklýdýrlarda. Fakat modern bilgisayar dillerinde
kullanýcýlarý da göz önüne almak durumundayýz. Ayný iºi daha renkli ve çeºitli ºekillerde
yapmamýz temel olarak program kullanýcýlarýna daha çeºitli alternatifler sunabilir. Ayný
zamanda diðer programlama alternatiflerine göre daha üstün bir çalýºma ortamý yaratabilir.
çýktýsýný verecektir.
import [Link].*;
class Hosgeldiniz2 {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String isim=new String([Link]());
[Link]();
=============================
C:\co\java\prog>java Hosgeldiniz2
isminizi giriniz :
Turhan
C:\co\java\prog>
=============================
Ayný iºlemi yapan fakat girdi çýktý sýnýf tanýmlarýnda Ek 1 de verilen Text sýnýfýný kullanan
[Link] programý ºekil 1.10 da verilmiºtir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.10 [Link] programý
import [Link].*;
import Text;
class Hosgeldiniz3 {
String isim=[Link]();
import [Link];
class Hosgeldiniz1SW {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String isim=[Link]("Lutfen isminizi giriniz :");
"Hosgeldiniz1SW programi",JOptionPane.INFORMATION_MESSAGE);
[Link](0);
javac [Link]
java Hosgeldiniz1SW
komutuyla çalýºtýrmamýz gerekecektir. Program girdi ve çýktý pencereleri ºekil 1.7 ve ªekil 1.8
de verilmiºtir.
[Link]
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.8 [Link] dosyasýnýn pencere popup çýktý penceresi
ªimdi ayný girdi ve çýktý programlamasýný JApplet sýnýfýný kullanarak yapalým. Input (girdi) için
yine JoptionPane sýnýfýndan yararlanacaðýz.
import [Link].*;
import [Link];
String isim;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
javac [Link] komutunu kullanacaðýz. sonra [Link]
dosyasýný oluºturacaðýz.
</applet>
</html>
appletviewer [Link]
Resim [Link]
Resim [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.10 [Link] dosyasýnýn applet çýktý penceresi
olacaktýr. Son olarak girdi ve çýktý iºlemlerini ayný pencerede yapýldýðý biraz daha kompleks
olan [Link] programýna göz atalým.
//sýnýf deðiºkenleri
String isim;
Container c=getContentPane();
[Link](new FlowLayout());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
isim="Mürºide Gökaðaç";
kutugirdisi=new JTextField(10);
ciktiAlani=new JTextArea();
Color co=[Link]();
[Link](co);
[Link](ciktiAlani);
[Link](this);
isim=[Link]();
repaint();
bu programý da yine
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
javac [Link] deyimiyle compile edip,
Resim [Link]
Bu programda verilen komut detaylarýný ºu anda bilmek zorunda deðilsiniz. Benzer iºlemleri
yapmak için ayný formattan yararlanabilirsiniz. Ýlerki bölümlerde grafik programlarýnýn alt
metodlarý detaylý olarak incelenecektir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
9223372036854775808 e
float Gerçek sayý 32 -3.40292347e+38 den
deðiºkeni 3.40292347e+38 e
double Gerçek sayý 64 -1.7976931348623157e+308
deðiºkeni den
1.7976931348623157e+308 e
boolean deðiºken türü mantýk iºlemlerinde kullanýlýr. Sadece true veya false deðerleri alýr.
true doðru false yanlýº anlamý taºýr. Mantýk deðiºkenleri ne doðrudan true veya false
deðerleri yüklenebileceði gibi diðer deðiºkenleri mantýk iºlemlerini kullanarak
karºýlaºtýrarakta deðerleri programlarýn içinde hesaplanabilir.
Aºaðýdaki küçük program parçasý mantýk deðiºkeni ilk mantýk deðiskenini tanýmlamakta ve
doðru deðerini bu deðiºkene yüklemektedir.
boolean ilkmantýkdegiskeni ;
ilkmantikdegiskeni=true;
char deðiºken türü harflerin tanýmlanmasýnda kullanýlýr. Harfler java dilinde ISO Unicode
kodu ile bilgisayara aktarýlýr. Unicode 4 hekzagonal (16 tabanlý) sayýnýn bir araya gelmesiyle
oluºur. Hekzagonal sayý sisteminin onlu ve ikili sayý sistemiyle eºitliði ºöyledir :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
ISO Unicode da tanýmlanan '\u0041' kodu 'A' harfi anlamýna gelir. Veya '\u03E1' kodu ''
harfini tanýmlar. ISO Unicode karakter setinin ilk iki rakamý sýfýr olduðunda ASCII karakter
kodunu tanýmlar. Unicode hakkýnda daha ayrýntýlý bilgi için
http:\\[Link]
internet adresini ziyaret edebilirsiniz. Aºaðýdaki küçük program parçacýðý char tipi A1, A2 ve
alpha1,alpha2 deðiºkenlerine A ve harflerini yüklemektedir.
char A1,A2;
char alpha1,alpha2;
A1='\u0041';
A2='A';
alpha1='\u03E1';
alpha2='a ';
Burada ºunu kaydedelim alpha1 deðiºkenini her ortamda doðru olarak görebiliriz, fakat
alpha2 deðiºkeni bazý ortamlarda doðru olarak görülmeyebilir.
Tam sayý deðiºkenler hafýzada iºgal ettikleri yere göre byte(8 bit), short(16 bit), int(32 bit) ve
long(64 bit) adýný alýrlar. Bir bitlik hafýzaya sadece iki rakamýn (0 veya 1) yazýlabileceði göz
önüne alýnýrsa örneðin sekiz bitlik byte türü tamsayý deðiºkenine 256 sayý (ikili sayý eºiti
11111111) yazýlabileceði ortaya çýkar. Bitlerden biri + veya - iºareti için kullanýldýðýndan byte
deðiºkeninin sýnýr deðerleri -128den 127 e kadardýr (toplam 256 sayý). Eðer bir tamsayý
deðiºkenin sadece artý deðerlerini kullanmak istersek unsigned terimini kullanýrýz. Örneðin
unsigned byte tipi tamsayý deðiºkenin sýnýr deðerleri 0 dan 256 ya kadardýr. Tamsayý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
deðiºken türleri içinde en fazla kullanýlan int türüdür. Aºaðýdaki küçük program parçacýðýnda
int türü ilktamsayi deðiºkenine 32 rakamý yüklenecektir.
int ilktamsayi;
ilktamsayi=32;
int ilktamsayi=32;
ºeklinde de yazýlabilirdi.
Javadaki tamsayý deðiºken türleri + ve – deðeri alabilen türlerdir. Örneðin byte deðiºken türü
–128 den +127 e kadar toplam 256 sayý kullanabilir. Eðer – bölgeyi kullanmayacaksak
tamsayý deðiºkenlerin kullaným bölgesini unsigned deyimini kullanarak tamamen artý
bölgeye çekebiliriz. Örneðin
Tablo 1.3 gerçek sayý 22.625e-17 yazýlmasýnda kullanýlan onlu ve ikili sayýlarýn bellekte
gerçek sayý organizasyonu örneði
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Yukarýda 16 bitle temsil edilen sayý : +16+4+2+0.5+0.125)*10-(16+1) = 22.625e-17 rakamýdýr.
Gerçek sayý deðiºkende yeterli hassasiyeti saðlayabilmek için genelde 64 bit uzunluðundaki
double deðiºken türü kullanýlýr. Javadaki Matematik kütüphaneleri de double deðiºken türü
için tanýmlanmýºtýr. Aºaðýdaki küçük program parçacýðýnda double türü ilkgercekdegisken
deðiºkenine 22.625e-7 sayýsýný yüklüyoruz.
double ilkgerçekdegisken;
ilkgerceldegisken=22.625e-17;
eðer 64 bit double sayý hassaslýðý yetmezse long double kullanýlabilir. Bu deðiºken türü 128
bit boyutundadýr.
Java nesne temelli bir dildir. Javadaki tüm deðiºken türlerinin nesne kökenli eºdeðerleri
mevcuttur. Bunun yanýnda temel deðiºken türleri arasýnda yer almýyan String gibi sadece
nesne kökenli olarak tanýmlanmýº deðiºken türleri de mevcuttur. ªimdi bunlarýn bir kýsmýný
biraz daha detaylý inceleyelim.
String deðiºkeni yazý yazdýrma iºleri için kullanýlýr. Nesne türü deðiºkendir. Java dilinde char
deðiºken türü kullanýlarak tanýmlanmýº bir nesne tipi deðiºkendir. Aºaðýdaki küçük program
parçacýðýnda bu deðiºken türünün kullanýlmasýný görüyoruz.
String a="ali";
String c="veli";
String d;
d=a+b; // d nin deðeri "ali veli"
String türü sabitler her zaman " iºaretleri arasýna yazýlýrlar ve + iºaretiyle bir araya
getirilebilirler.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String a=new String("ali");
String c=new String("veli");
String d=new String();
d=a+b; // d nin deðeri "ali veli"
[Link](d); // bu satýr ali veli çýktýsý verir
Formunu da kullanabiliriz. Ýkinci verdiðimiz form iºlem olarak ilk verilenin tamamen aynýdýr.
String türü bir deðiºkenin toplam boyutu length() alt metoduyla belirlenebilir. Örneðin
int x=[Link]();
boolean y=[Link](“ali”);
boolean z=[Link](“veli”);
Integer i;
i=new Integer(3);
veya
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String s=”15”;
Tanýmý 15 deðerini yükler. Integer deðerini int deðerine (temel deðiºken) çevirebiliriz.
int x;
x=[Link](y);
String s=”15”;
Ýnt x=[Link](s);
kullanýlýr.
int x=3;
String s=[Link](x);
kullanýlýr.
Double deðiºkeni kullaným olarak Integer deðiºkeninden bir farký yoktur. Ayný tanýmlamalar
Integer yerine Double kullanýlarak yapýlabilir. Deðiºkenler
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double x;
X=new Double(3.66e5);
veya
String s=”15.66e-3”;
Tanýmý 15.66*10 -3 deðerini yükler. Double deðerini double deðerine (temel deðiºken)
çevirebiliriz.
double x;
X=[Link](y);
int x;
x=[Link](y);
String deðerini double (temel deðiºken) deðerine direkt olarak çevirmek içinse
String s=”15.25”;
double x=[Link](s);
ݺlemi kullanýlabilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double tipi (temel) deðiºkeni String deðiºkenine deðiºtirmek için
double x=3.75;
String s=[Link](x);
kullanýlýr.
Object, Long, Float, Boolean, Character, Vector gibi diðer nesne tipi deðiºken türleri de
mevcuttur. Object nesne tipi tüm bu deðiºken nesne tiplerini içinde barýndýran genel bir tiptir.
Tüm nesne tipi deðiºkenlerin bizim için temel avantajý alt metodlarýný kullanarak iºlemler
gerçekleºtime olasýlýklarýdýr. Fakat bu tür deðiºkenler temel deðiºken türlerine göre daha çok
hafýza yeri iºgal ettiklerinden mecbur kalýnmadýkça da kullanýlmamalýdýrlar. Ayrýca Yine
nesne tipi BigDecimal ve BigInteger türleri de hassasiyeti kullanýcý tarafýndan belirlenen
nesne tipi deðiºkenler olarak kullanýlabilirler.
Java dilinde deðiºken yerine sabit kullanmak istersek tanýmýn baºýna final sözcüðünü
getiririz. Final olarak tanýmlanan sabitlerin bir kere deðerleri verildikten sonra deðiºtirilemez.
Örneðin
pi sabitini tanýmlar.
+ toplama
- çýkarma
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* çarpma
/ bölme
% tamsayýlar için bölmede kalan (modül )
Program 1.15 deki program örneði int tamsayý kullanarak bu aritmetik iºlemlerin yapýlmasýný
göstermektedir.
sayi1 + sayi2 =5
sayi1 - sayi2 =-1
sayi1 * sayi2 =6
sayi1 / sayi2 =0
sayi1 % sayi2 =2
ºeklinde olacaktýr. Swing grafik kütüphanesi çýktýsý pratiði yapmak amacýyla ayný programý
swing JoptionPane çýktýsý ile yazarsak :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.16 : [Link] konsol programý
class AritmetikSW
String s;
int sayi1,sayi2;
int toplama,cikarma,carpma,bolme,kalan;
sayi1=[Link](
);
sayi2=[Link](
);
toplama = sayi1+sayi2;
cikarma = sayi1-sayi2;
carpma = sayi1*sayi2;
bolme = sayi1/sayi2;
kalan = sayi1%sayi2;
s="";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s=s+sayi1+" % "+sayi2+" = "+kalan +"\n";
[Link](null,s,
"Aritmetik islemleri",JOptionPane.PLAIN_MESSAGE);
[Link](0);
Bu programýn çýktýsý :
[Link]
Java ve C dillerinde temel aritmetik iºlemlerinin yaný sýra bu iºlemlerin kýsaltýlmýº sembolleri
de oldukça sýk kullanýlýr. Bu iºlemler :
++ bir ilave et
-- bir çýkar
+= sað taraftaki rakamý ilave et
-= sað taraftaki rakamý çýkar
*= sað taraftaki rakamla çarp
/= sað taraftaki rakama böl
%= sað taraftaki rakama bölüp kalanýný al iºlemleridir.
++ ve -- iºlemleri deðiºkenden önce veya sonra gelebilir. Bu iki ºeklin deðiºken tek
baºlarýna kullanýldýðýnda bir farklýlýklarý yoktur, fakat ikinci bir deðiºkenle birlikte tek bir
deyimde kullanýldýklarýnda ikinci deðiºkenin deðeri deðiºir. Aºaðýdaki iki program parçacýðýna
göz atalým.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
++ iºlemcisinin deðiºkenden sonra kullanýlmasý
int a=2;
int c;
c=a++; // a nýn deðeri 3 c nin deðeri 2
int a=2;
int c;
c=++a; // a nýn deðeri 3 c nin deðeri 3
a deðiºkeninin deðeri baºlangýçta 2 ise görüldüðü gibi hem ++a iºleminde hem de a++
iºleminde deðeri 3 e çýkmaktadýr. Ancak c deðiºkeninin deðeri c=a++ iºleminde 2 olarak
kalýrken (önce deðeri yükle sonra arttýr), c=++a iºleminde 3 olmaktadýr(önce arttýr, sonra
deðeri yükle). ++ ve -- iºlemleri genelde tam sayý deðiºkenler için kullanýlýr.
Program 1.17 da aritmetik iºlemleri gösteren bir program verilmiºtir. Bu programýn sonuçlarý
da altta verilmektedir. Programý basamak basamak takip ederek sonuçlarýn doðruluðunu
elde hesaplayarak kontrol edebilirsiniz.
import [Link].*;
public class Aritmetik1
{ public static void main(String[] args)
{
int sayi1=1;
int sayi2=2;
sayi1+=sayi2;
[Link]("sayi1+= : "+ sayi1);
sayi1-=sayi2;
[Link]("sayi1-= : "+ sayi1);
sayi1*=sayi2;
[Link]("sayi1*= : "+ sayi1);
sayi1/=sayi2;
[Link]("sayi1/= : "+ sayi1);
}
}
sayi1+= : 3
sayi1-= : 1
sayi1*= : 2
sayi1/= : 1
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1.7 JAVADA MANTIKSAL ݪLEMLER
Javadaki temel deðiºken türlerine bakarken boolean türü deðiºkenleri tanýmlamýºtýk. Tam
sayý ve gerçek deðiºkenlerin aritmetik iºlemlerde kullanýlabildiði gibi boolean deðiºkenler de
mantýksal iºlemlerde kullanýlabilirler. Mantýksal iºlem iºlemcileri ºunlardýr :
import [Link].*;
boolean b1,b2;
b1=true;
b2=false;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int sayi1,sayi2;
sayi1=1;
sayi2=2;
[Link]("sayi 1 : "+sayi1);
[Link]("sayi 2 : "+sayi2);
b1=(sayi1 == sayi2);
b1=(sayi1 != sayi2);
Aºaðýda bu örnek problemin (Program 1.5) sonucunu verilmektedir. Satýr satýr proðramý takip
ederek sonucularý kontrol ediniz.
b1 : true b2 : false
b1 && b2 false
b1 || b2 true
sayi 1 : 1
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi 2 : 2
1 > 2 false
1 < 2 true
1 == 2 false
1 >= 2 false
1 <= 2 true
1 != 2 true
Bit iºlemi doðrudan doðruya bitler üzerinde yapýlan iºlemlerdir. Bit iºlemleri genellikle veri
trasferi (bilgisayardan bilgisayara veya çeºitli kontrol sistemlerinde) iºlemlerinde kullanýlýr.
Javadaki bit iºlemleri Tablo 1.4 de verilmiºtir.
int x=7;
x=x<<1;
bit iºleminde x deðiºkeninin bit yapýsý sola doðru bir bit kaydýrýlmýºtýr. 7 deðerinin bit
eºdeðeri
00000000000000000000000000000111
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
00000000000000000000000000001110
int x=7;
x=x<<1;
x=~x;
iºlemi
11111111111111111111111111110001
deðerini verecektir.
class bitislemi{
int x=7;
[Link]("x = "+x);
x= x<<1;
[Link]("x = "+x);
x= x<<1;
[Link]("x = "+x);
x= x>>2;
[Link]("x = "+x);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x= ~x;
[Link]("x = "+x);
bu programýn sonucu
x=7
x = 14
x = 28
x=7
x = -8
ºeklinde olacaktýr. Çýkan sonuçlarýn bit eºdeðerlerini kontrol ediniz. Bit iºlemleri aslýnda
bilgisayarýn ve digital elektronik devrelerin temel iºlemleridir. Bu iºlemler assembler dillerinin
de temel iºlemlerini teºkil ederler.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
{ yukardaki boolean deðiºken vede sabitlerin hiçbiri true deðerine eºit deðilse
yapýlacak olan iºlemler}
else if yapýsý probleme göre istenilen sayýda olabilir, if ve else yapýsý sadece bir tane olarak
kullanýlýr.
deðiºken adý = ( boolean deðiºken yada sabit ? boolean true ise deðiºken deðeri :
boolean false ise deðiºken deðeri );
class ifyapisi
{
public static void main (String args[]) throws IOException
{
double not;
//
Text cin=new Text();
not=[Link]();
if( not ==90)
{ [Link]("A"); }
else if(not ==75)
{ [Link]("B"); }
else if(not ==60)
{ [Link]("C"); }
else if(not ==50)
{ [Link]("D"); }
else if(not ==40)
{ [Link]("E"); }
else
{ [Link]("F"); }
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Ýf yapýsý programýnýn çýktýsý :
Bu programda öðrenci notu ekrandan girdi olarak girilmektedir. Bunu saðlayabilmek için önce
not deðiºkeni bir ekran girdisi olduðundan girilen nota göre bilgisayar A,B,C,D,E veya F
notlarýndan birini verecektir. Bu ilk programýmýzda if ve else if parantezlerinin içinde direk
olarak boolean sabit kullanýlmýºtýr. Parantez içi boolean deðiºken de olabilir.
Ayný program kodunu java swing kütüphanesi JoptionPane alt sýnýfýný kullanarak yazacak
olursak :
import [Link];
class ifyapisiSW
double not;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
not=[Link]([Link]("Ogrencinin notunu giriniz (0-
100) : "));
{ [Link](null,"A","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
{ [Link](null,"B","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
{ [Link](null,"C","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
{ [Link](null,"D","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
{ [Link](null,"E","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
else
{ [Link](null,"F","Ogrenci
notu",JOptionPane.PLAIN_MESSAGE);}
[Link](0);
Program çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
boolean a=true;
if(a)
{[Link]("a degiºkeninin deðeri : true");}
else
{[Link]("a degiºkeninin deðeri : false");}
if - elseif - else yapýlarý iç içe girmiº yapýlar veya basit mantýklarýn && (ve) , || (veya)
iºlemleriyle baðlanmasýyla daha kompleks mantýksal ºartlar oluºturulabilir.
Ýç içe geçmiº if yapýsý kullanýlarak mantýksal kontrol prosesi alttaki program parçasýnda
açýklanmýºtýr :
double x = 7.0;
double y = 3.0;
if(x > 5)
{
if(y > 5) { [Link]("x ve y besten buyuktur.");}
elseif(y==5) { [Link]("x besten buyuktur ve y bese esittir.");}
else { [Link]("x besten buyuktur ve y besten kucuktur.");}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
{
if(y > 5) { [Link]("x besten kucuktur veya esittir ve y 5 den buyuktur.");}
elseif(y==5) { [Link]("x besten kucuktur veya esittir ve y bese esittir.");}
else { [Link]("x besten kucuktur veya esýttýr ve y besten kucuktur.");
}
}
double x = 7.0;
double y = 3.0;
While en çok kullanýlan tekrarlama yapýlarýndan biridir. ( ) içindeki boolean terim true (doðru)
olduðu sürece yeniden iºlemi döndürür. Eðer programda boolean iºlemini sonuçlandýracak
bir ifade yoksa sonsuza dek veya program baºka bir yöntemle durdurulana dek devam eder.
örneðin :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
while(true)
{ [Link]("Bu yazý surekli olarak tekrar edecektir");}
yapýsý sonsuz bir döngü oluºturur. Aºaðýdaki program yapýsý ise sayý 1000 den büyük veya
1000 e eºit olduðunda durur.
int sayý=2;
while(sayý <= 1000)
{ sayý *= 2; }
While tekrarlama yapýsý bazen biraz daha farklý bir yapý içinde verilebilir. Aºaðýda gösterilen
bu yeni yapý, bir önceki while yapýsýna göre daha ender kullanýlar. do..while yapýsýnýn while
yapýsýndan temel farký, döngünün içine en az bir kere girilme zorunluðunun olmasýdýr.
do
{
boolean degiºken veya sabitin deðeri true olduðunda yapýlan iºlemler.
Bu paranteze boolean deðerinin ne olduðuna bakýlmaksýzýn en az bir kere girilir
}
while( boolean deðiºken yada sabit)
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu program calýstýðýnda appletviewer ªekil 1.15 deki sonucu verecektir.
[Link]
import [Link].*;
int saydirici=1;
String s="";
do {
s=s+[Link](saydirici)+" ";
[Link](null,s,
"do-while yapisi",JOptionPane.PLAIN_MESSAGE);
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Program çýktýsý :
[Link]
For tekrarlama yapýsý genellikle sayýlarý belli bir düzen içinde arttýrmak için kullanýlýr. Genel
yapýsý aºaðýda gösterilmiº[Link] sayý saydýrmaya dönük uygulamalarda en
fazla kullanýlan yapýdýr.
Program 1.23 de 1 den yüze kadar sayýlarýn toplamýný hesaplayan bir konsol programý
verilmiºtir.
import [Link].*;
class foryapisi
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String args[])
{
int toplam=0;
for(int sayi=1;sayi<=100;sayi++)
{ toplam+=sayi;}
[Link]("1 den 100 e sayilarin toplami : "+toplam);
}
}
sonucunu verecektir.
Program 1.24 de yine for döngüsünün uygulamasý konusunda bir örnek problem verilmiºtir.
Programý nasýl çalýºtýðýný inceleyiniz. Bu programda yýllýk bileºik faizler on yýl için
hesaplanmaktadýr. Ýlk iki faiz oranýný elde hesaplayýnýz. Programý çalýºtýrarak sonuçlarý
kontrol ediniz. Program sonuçlarý ªekil 1.14 de listelenmiºtir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
double paraMiktari=ilkYatanPara;
int y=40;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int yil=1; yil<=10 ; yil++)
paraMiktari*=(1.0+faizOrani);
s=s+yil+" "+paraMiktari+"\n";
[Link](null,s,"faiz orani",
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Switch case yapýsý çeºitli alternatifler içeren bir tablodan seçme yapma türü iºlerde kullanýlýr.
Temel yapý:
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
switch - case yapýsý:
................
default :
eðer yukarýdaki case kutularýndan hiçbirine girilemediyse
yapýlacak iºlemler
break;
}
ºeklindedir. Switch yapýsýndan sonra deðiºken ismi gelir. Her case deyiminden sonra ise
deðiºkenin alacaðý yeni bir deðer alternatifi verilir. Eðer switch yapýsýnda verilen alternatif
hiçbir case bloðunda tanýmlanmamýºsa default bloðuna gider ve buradaki iºlemler
gerçekleºtirilir. Case ve default bloklarý break deyimi ile sona erer. break deyimi herhangi bir
döngü yapýsýndan döngü bitmeden çýkma amacýyla da kullanýlabilir. break yapýsýyla
döngünün dýºýna çýkma amacýyla diðer döngü yapýlarýnda da kullanýlabilir(if, for while gibi),
fakat bu tür break kullanýlarak döngü dýºýna çýkýlmasý yapýsal programlama teknikleri
tarafýndan tavsiye edilmez. Bilgisayar listelerini yapýsallýktan uzaklaºtýrýp, spagetti
programlama dediðimiz karmakarýºýk programlamaya yol açabilir. Döngü yapýlarýndan
standart kontrollarý yoluyla çýkýlmasý tavsiye edilir.
int i=0;
while(true)
{
i++;
if(i==3) break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.27 de verilen [Link] proðramý switch deyiminin nasýl kullanýldýðýný
göstemektedir. Programcýlara göre kullanýlma sýklýðý deðiºebildiði varsayýlsa bile, switch
yapýsý ºu ana kadar bahsedilen yapýlar içinde en az kulanýlanýdýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
++Asayisi;
break;
case 'B': case 'b':
++Bsayisi;
break;
case 'C': case 'c':
++Csayisi;
break;
case 'D': case 'd':
++Dsayisi;
break;
case 'E': case 'e':
++Esayisi;
break;
case 'F': case 'f':
++Fsayisi;
break;
default:
showStatus("yanlýs not tanýmlandý yani bir not giriniz.");
break;
} // switch deyiminin sonu
repaint();//pencereyi yeniden paint metotuna gore ciz
}
[Link]
Program 1.28 switch - case yapýsý örneði [Link] swing applet programý . Bu
program öðrenci notlarýný appletden girer ve her nottan kaç tane girildiðini listeler.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*; // java pencere awt sinifini cagir
//sinif degiskenleri
char not;
int Asayisi=0,Bsayisi=0,Csayisi=0,Dsayisi=0,Esayisi=0,Fsayisi=0;
Container c=getContentPane();
kutugirdisi=new JTextField(5);
[Link](ciktiAlani,[Link]);
[Link](" ");
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String cikti="\n";
String not1=[Link]();
not=[Link](0);
switch(not)
++Asayisi;
break;
++Bsayisi;
break;
++Csayisi;
break;
++Dsayisi;
break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
case 'E': case 'e':
++Esayisi;
break;
++Fsayisi;
break;
default:
break;
cikti=cikti+"A : "+Asayisi+"\n";
cikti=cikti+"B : "+Bsayisi+"\n";
cikti=cikti+"C : "+Csayisi+"\n";
cikti=cikti+"D : "+Dsayisi+"\n";
cikti=cikti+"E : "+Esayisi+"\n";
cikti=cikti+"F : "+Fsayisi+"\n";
[Link](cikti);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.20 switch - case yapýsý örneði [Link] swing appletinin sonuçlari
C veya C++ dilinde bir deðiºken türünden deðiºkeni diðer deðiºken türünden deðiºkene direk
olarak atama mümkündür. örneðin
char a='x';
int b=a;
iºlemi c++ da geçerli bir iºlemdir. Javada ise bu iºlem hata verir. fakat ayný islem
char a='x';
int b=(int)a;
ºeklinde gerçekleºtirilebilir (int) deyimi orijinal olarak char olarak tanýmlanan a deðiºkeninin
deðerini int türüne dönüºtürmüº sonra da in türünden b deðiºkenine yüklemiºtir. Bu dönüºüm
iºlemlerini tüm deðiºken türleri için kullanabiliriz, yalnýz burada programcýnýn çok dikkatli
olmasý ve deðiºken türlerini, ve sýnýrlarýný iyi tanýmasý gerekmektedir. Deðiºken türlerini
deðiºtirirken bazý bilgiler kaybolacaðý gibi hiç istemediðimiz bir sonuca ulaºma olasýlýðýmýz da
mevcuttur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1.11 SAYI DEÐÝL VE SONSUZ SONUÇLARI
Java gerçek sayý deðiºken türleri sayý deðil (NaN ) ve artý sonsuz (Pozitif infinity ) ve eksi
sonsuz(negative infinity ) sonuçlarý verebilirler. sayý deðil (NaN) sonucu sýfýr bölü sýfýr, sýfýr
çarpý sonsuz gibi iºlemlerden çýkar. sonsuz iºlemi ise sayi bölü sýfýr gibi iºlemlerden çýkar. Bu
iºlemler sadece float ve double deðiºkenleri için tanýmlýdýr. Tamsayý deðiºkenler sýfýra
bölünemezler.
1.12 ALIªTIRMALAR
1. Not defteri programýný veya diðer herhangi bir editörü kullanarak [Link]
programýný incele. Konsole (MS DOS veya UNIX console) ortamýnda aºaðýdaki komutlarý
kullanarak çalýºtýr :
javac [Link]
java Hosgeldiniz
import [Link].*;
class Hosgeldiniz
{
public static void main (String args[])
{
[Link]("Java Sinifina Hos Geldiniz!")
}
}
javac [Link]
appletviewer [Link]
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class HosgeldinizApplet extends Applet
{
public void paint(Graphics g)
{ [Link]("Java sinifina hos geldiniz!",25,25); }
}
3. Not defteri programýný kullanarak [Link] programýný incele. Konsole (MS Dos)
ortamýnda aºaðýdaki komutlarý kullanarak calýºtýr :
javac [Link]
java ikitamsayitopla
class ikitamsayitopla
{
public static void main (String args[]) throws IOException
{
int sayi1,sayi2;
int toplam=0;
//
Text m=new Text();
[Link]("Bir tam sayi giriniz : ");
sayi1=[Link]();
[Link]("Ikinci bir tam sayi girermisiniz : ");
sayi2=[Link]();
toplam=sayi1+sayi2;
[Link]("Iki tam sayinin toplami : "+toplam);
}
}
5. [Link]
javac [Link]
appletviewer [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
int toplam;
int sayi1,sayi2;
toplam=0;
//
toplam=sayi1+sayi2;
[Link](15,10,270,20);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
javac tamsayitoplaApplet .java
appletviewer [Link]
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.21 [Link] appletinin sonuçlari
7. [Link]
javac [Link]
appletviewer [Link]
import [Link].*;
int toplam;
int sayi1,sayi2;
toplam=0;
//
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi2=[Link]([Link](" Ikinci bir tam sayi giriniz : "));
toplam=sayi1+sayi2;
[Link](15,10,270,20);
[Link]
7. [Link]
javac [Link]
java tamsayitoplaSWFrame
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*; // java pencereyi dinleme sýnýfýný çaðýrýr
//sinif degiskenleri
JTextArea cikti;
int sayi;
int toplam;
public tamsayitoplaSWFrame()
Container cerceve=getContentPane();
kutugirdisi=new JTextField(10);
cikti=new JTextArea(6,30);
[Link](cikti);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
toplam=0;
[Link](this);
sayi=[Link]();
// sayi=[Link]( [Link]() );
[Link]("");
});
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
5. Not defteri programýný kullanarak [Link] programýný incele. Konsole (MS Dos)
ortamýnda aºaðýdaki komutlarý kullanarak calýºtýr :
javac [Link]
java dortArtýIslem
class dortArtiIslem
{
public static void main (String args[]) throws IOException
{
int sayi1,sayi2;
//
DataInputStream cin=new DataInputStream([Link]);
[Link]("Bir tam sayi giriniz : ");
sayi1=[Link](cin);
[Link]("Ikinci bir tam sayi giriniz : ");
sayi2=[Link](cin);
[Link]("Iki tam sayinin toplami : "+(sayi1+sayi2));
[Link]("Iki tam sayinin farki : " +(sayi1-sayi2));
[Link]("Iki tam sayinin carpimi : "+(sayi1*sayi2));
[Link]("Iki tam sayinin bolumu : "+(sayi1/sayi2));
[Link]("Iki tam sayinin kalani : "+(sayi1%sayi2));
// Matematik tipi degisken islemleri :
// + : topla
// - : cikar
// * : carp
// / : bol
// % : bolumun kalani
// += : kendisi ve sag tarafindaki ile topla
// sayi1+=3 ve sayi1=sayi1+3 ayni islemdir
// -= : kendisinden sag tarafindakini cikar
// sayi1-=3 ve sayi1=sayi1-3 ayni islemdir
// *= : kendisi ve sag tarafindakini carp
// sayi1*=3 ve sayi1=sayi1*3 ayni islemdir
// /= : kendisini sag tarafindakine bol
// sayi1/=3 ve sayi1=sayi1/3 ayni islemdir
// %= : kendisini sag tarafindakine bol kalanini ver
// sayi1%=3 ve sayi1=sayi1%3 ayni islemdir
// ++ : kendisine bir ekle
// sayi1++ ve sayi1=sayi1+1 ayni islemdir
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// ++ : kendisine bir ekle
// ++sayi1 ve sayi1=sayi1+1 ayni islemdir
// -- : kendisinden bir cikar
// sayi1-- ve sayi1=sayi1-1 ayni islemdir
// -- : kendisinden bir cikar
// --sayi1 ve sayi1=sayi1-1 ayni islemdir
boolean mantik1,mantik2;
mantik1=true; // dogru
mantik2=false;//yanlis
[Link]("dogru ve yanlis : "+(mantik1 && mantik2));
[Link]("dogru veya yanlis : "+(mantik1 || mantik2));
mantik1=( sayi1 sayi2 );
mantik2=( sayi1 < sayi2 );
// Boolean (mantik) tipi degisken islemleri :
// : buyuktur
// < : kucuktur
// == : esittir
// = : buyuk veya esittir
// <= : kucuk veya esittir
// ! : mantigi tersine cevirme
// != : esit degildir
// && : ve
// || : veya
mantik1=( sayi1 sayi2 );
mantik2=( sayi1 < sayi2 );
[Link]("sayi1 buyuktur sayi2 : "+mantik1);
[Link]("sayi 1 kucuktur sayi2 : "+mantik2);
}
}
appletviewer [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.34 : [Link] programý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// |
// |
// |
// V y ekseni
[Link]("Su ana kadarki sayilarin toplami : "+toplam,25,50);
[Link]("Su ana kadarki sayilarin aritmetik ortalamasi :
"+aritmetikOrtalama,25,65);
[Link]("Su ana kadarki sayilarin geometrik ortalamasi :
"+geometrikOrtalama,25,80);
}
}
[Link]
7. Not defteri programýný kullanarak bessayý[Link] proðramýný incele. Konsole (MS Dos)
ortamýnda aºaðýdaki komutlarý kullanarak calýºtýr :
javac bessayý[Link]
java bessayýtopla
class bessayitopla
{
public static void main (String args[]) throws IOException
{
double sayi;
double toplam=0;
int saydirici=0;
//
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Text cin=new Text();
while( saydirici < 5)
{
[Link]("Bir tam sayi giriniz : ");
sayi=[Link]();
toplam+=sayi;
saydirici++;
}
[Link]("sayilarin toplami : "+toplam);
}
}
8 . Not defteri programýný veya herhangi bir editör programý kullanarak [Link]
programýný incele. Konsole (MS Dos) ortamýnda aºaðýdaki komutlarý kullanarak calýºtýr :
javac [Link]
java StringDegisken
class StringDegisken
{
public static void main (String args[]) throws IOException
{
String s1,s2,s3,s4;
int i1;
String s;
s1="Ali ";
s2="Veli ";
s3="49";
s4=" Elli";
s=s1+s2+s3+s4;
[Link](s);
i1=49;
s=s1+s2+i1+s4;
[Link](s);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Ali Veli 49 Elli
Ali Veli 49 Elli
9 . alýstýrma 7 deki bessayi [Link] programýný iyice anladýktan sonra birden yüze (100)
kadar sayýlarýn ortalamasini hesaplayan birdenyü[Link] program ve sinifini
(Konsole) yaz ve calistir.
10. If yapýsýný kullanma programý, [Link] , Ýki String türü deðiºkeni Applet
TextField girdi alanýndan girer ve birbiriyle karºýlaºtýrýr. Sonuçlarý Applet ortamýnda yazdýrýr.
Bu program applet olarak dizayn edilmiºtir. programý çalýºtýrýnýz ve sonuçlarýný applet
ortamýnda alýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//if deyiminin kullanimi
import [Link]; // java applet sinifini cagir
import [Link].*; // java pencere kullanma sinifini cagir
import [Link].*; // java pencereyi dinleme sinifini cagir
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// sayi 1 i girdi kutusundan oku
sayi1=[Link]([Link]());
// sayi 2 i girdi kutusundan oku
sayi2=[Link]([Link]());
repaint();
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi = 4
sayi = 8
sayi = 16
sayi = 32
sayi = 64
sayi = 128
sayi = 256
sayi = 512
sayi = 1024
import [Link];
import [Link];
int saydirici=1;
int x=25;
do {
[Link]([Link](saydirici),x,25);
x += 15;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
13. [Link] programýný incele ve çalýºtýr. Bu program for döngü yapýsý kullanarak bir
sayý dizisini applet ortamýnda yazdýrmaktadýr.
import [Link].*;
class foryapisi
int toplam=0;
for(int sayi=1;sayi<=100;sayi++)
{ toplam+=sayi;}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
14. [Link] programýný incele ve çalýºtýr. Bu program döngü yapýsý kullanarak
faiz oranlarýný hesaplamaktadýr.
16. Bir java konsol programý ( [Link]) yazarak On kiºilik bir sýnýftaki kiºilerin aðýrlýklarýný
girdi olarak giriniz.
her sýnýfta kaç kiºi olduðunu yazdýrýnýz. Dosyanýzýn adý [Link], sýnýfýnýzýn adý : kilo
olacaktýr. Bilmediðiniz yapýlarý örnek problemleri inceleyerek öðrenebilirsiniz.
class kilo
{
public static void main (String args[]) throws IOException
{
double kilo; //
Text cin=new Text();
[Link]("kilonuzu giriniz : ");
kilo=[Link]();
if( kilo <= 40)
{ [Link]("zayif"); }
else if( kilo40 && kilo<80 )
{ [Link]("normal"); }
else
{ [Link]("sisman"); }
}
}
program çýktýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kilonuzu giriniz : 45
normal
kilonuzu giriniz : 95
sisman
import [Link];
import [Link];
int x,y;
y=15;
[Link]("*",x,y);
[Link]("*",x,y+45);
x=15;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("*",x,y);
[Link]("*",x+135,y);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
import [Link];
import [Link];
{ int i;
int x=0;
for(i=1;i <= 11;i++) //i degeri birden 11 a kadar degisir
{
x += 15; // x degeri her i icin 15 artiyor
[Link]("*",x,x);
[Link]("*",x,(180-x));
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
import [Link];
import [Link];
public class yildiz2whileApplet extends Applet
{
public void paint(Graphics g)
{
int i=1;
int x=0;
while(i++ <= 11) //i degeri birden 11 a kadar degisir
{
x += 15; // x degeri her i icin 15 artiyor
[Link]("*",x,15); // x lineer degisken y 15
[Link]("*",15,x); // x 15 y lineer deðiºken
[Link]("*",x,165); // x lineer deðiºken y 165
[Link]("*",165,x); // x 165 y lineer deðisken
[Link]("*",x,x); // çiz
[Link]("*",x,(180-x)); // çiz
}
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.29 [Link] çýktýsý
import [Link];
import [Link];
public class yildiz1forApplet extends Applet
{
public void paint(Graphics g)
{
int i;
int x=25;
for(i=1;i <= 10;i++) //i degeri birden 10 a kadar degisir
{
[Link]("*",x,x);
x += 15; // x degeri her i icin 15 artiyor
}
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.30 [Link] çýktýsý
ºeklindedir.
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
23. Pisagor üçlüsü : bir dik üçgende üç kenarýn da tam sayý olmasý mümkündür. Bu tür sayý
setine pisagor üçlüsü adý verilir. Pisagor üçlüsünde ilk iki sayýnýn karelerinin toplamý üçüncü
sayýnýn karesine eºit olmalýdýr. Birincidikkenar, ikincidikkenar ve hipotenüs tam sayý pisagor
üçlülerini üçlü for döngüsü kulanarak bulan bir program yazýnýz.
**********
*********
********
*******
******
*****
****
***
**
*
Program 1.26 [Link] programý. Bu program üçgen bir yýldýzý alaný çizdirir.
import [Link];
import [Link];
public class H3A1 extends Applet
{
public void paint(Graphics g)
{
int x,y;
for(x=15;x <= 150;x+=15)
{
for(y=15;y <= x;y+=15)
{
[Link]("*",x,y);
}
}
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.31 yýldýz üçgeni çizen [Link] çýktýsý
**********
* *
* *
**********
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]("*",15,y);
[Link]("*",150,y);
}
}
}
26. Java konsol programý kullanarak aºaðýdaki ºekli konsolda çizdiriniz. x ekseni ve y
eksenindeki toplam yýldýz sayýsýný ekrandan giriniz.
**********
* *
* *
**********
27. Java konsol programý [Link] programýný oluºturunuz ve bir sayinin faktoriyelini
hesaplayiniz.
import [Link].*;
import Text;
class faktoriyel
{
public static void main(String args[]) throws IOException
{
int faktoriyel=1;
Text cin=new Text();
int faktoriyelsayi;
[Link]("Bir tamsayi giriniz:");
faktoriyelsayi=[Link]();
for(int sayi=1;sayi<=faktoriyelsayi;sayi++)
{ faktoriyel*=sayi;}
[Link](faktoriyelsayi+" faktoriyel: "+faktoriyel);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
28. Java konsol programý kullanarak asaðýdaki formulü hesaplayýnýz:
ex = 1 + x /1! + x2 / 2! + x3 / 3! + x 4 / 4! + ..
not : e=2.7182818
Program 1.29 [Link] programý. For döngüsü kullanarak exponent hesaplar.
import [Link].*;
import Text;
class H3A4
{
public static void main(String args[]) throws IOException
{
double faktoriyel=1;
double x;
double us=1;
double exponent=1;
Text cin=new Text();
[Link]("Bir sayi giriniz:");
x=[Link]();
for(double sayi=1;sayi<=200;sayi++)
{
faktoriyel*=sayi;
us*=x;
exponent+=us/faktoriyel;
}
[Link]("exp("+x+") = "+exponent);
[Link]("gercek exp("+x+") = "+[Link](x));
}
}
29. Alýºtýrma 28 deki exponent hesabýný for döngüsü yerine while döngüsü kullanarak
gerçekleºtiriniz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
30. Hata fonksiyonu erf(x) aºaðýdaki formülle tanýmlanabilir.
Bir konsol programý yazýnýz. Text sýnýfý kullanarak dýºarýdan x deðerini okuyunuz. For
döngüsü kullanarak formülü hesaplayýnýz ve sonucunu yazdýrýnýz.
31. gerçek sayý faktoriyel fonksiyonu ?'nýn 1.05 noktasýndaki deðeri (1.05) in deðeri
0.9735 olarak bilinmektedir. f onksiyonu da faktoriyel gibi
x *x+1 x
32. [Link]
Program 1.30 [Link]
import [Link].*;
class H1OD1
{
public static void main(String args[])
{
// Bu program konsolda(MS DOS)
// "Java Programlama dili"
// cok zevkli bir ders
// yazdirir
[Link]("\"Java Programlama dili\"\ncok zevkli bir ders");
}
}
33. [Link]
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H1OD2 extends Applet
{
public void paint(Graphics g)
{
// Bu program apletde(pencere)
// "Java Programlama dili"
// cok zevkli bir ders
// yazdirir
[Link](("\"Java Programlama dili \"",25,25);
[Link]("cok zevkli bir ders");",25,40);
}
}
Yanlýºlarýnýzý düzeltiniz
34. [Link]
Ýki gerçek sayinin(double) (bu sayilar 2 ve 5 olsun) farklarýný Konsol ortamýnda (MS DOS)
hesaplayacak java programýný yazýp iºletiniz
35. [Link]
Ýki gerçek sayinin(double) bölümlerini Konsol ortamýnda (MS DOS) hesaplayacak java
programýný yazýp iºletiniz. Sayýlar ekrandan Text sýnýfýný kullanarak girilecektir (okunacaktýr)
36. [Link]
Ýki gerçek sayinin(double) çarpýmlarýný Applet(window) ortamýnda hesaplayacak java
programýný yazýp iºletiniz.
37. [Link]
Beº gerçek sayinin(double) çarpýmlarýný Konsol ortamýnda (MS DOS) hesaplayacak java
programýný yazýp iºletiniz. Sayýlar ekrandan Text sýnýfýný kullanarak girilecektir (okunacaktýr)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
38. [Link] : if -elseif -else yapisi ve boolean deðiºken örneði, konsol programý.
Programý incele ve çalýºtýr.
import [Link].*;
class H2AL1
// karsilatirmalar yapar
// ve sonucu yazdirir
boolean b1;
boolean b2;
boolean b3;
double sayi1;
double sayi2;
String s1,s2;
b1=true;
b2=false;
b3=b1&&b2;
[Link](b1+"&&"+b2+" = "+b3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(b3)
else if(!b3)
sayi1=[Link]();
sayi2=[Link]();
b3=(sayi1>sayi2);
if(sayi1>sayi2)
[Link](sayi1+">"+sayi2+" = "+b3);
else if(sayi1<sayi2)
[Link](sayi1+"<"+sayi2+" = "+(sayi1<sayi2));
else
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](sayi1+"=="+sayi2+" = "+(sayi1<sayi2));
s1=[Link]();
s2=[Link]();
b3=[Link](s2);
if([Link](s2))
else
39. H2AL2 : while döngüsü örneði applet programý, 10 dan 30 a kadar sayýlarý applete
yazdýrýr. Programý incele ve çalýºtýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 1.33 : [Link], while döngüsü örneði applet programý, 10 dan 30 a kadar
sayýlarý applete yazdýrýr.
import [Link];
import [Link].*;
// Bu program apletde(pencere)
int i=0;
double x=10.0;
while(x<=20.0)
[Link](" "+(x+=1.0),i+=30,25);
40. H2AL3 : do - while döngüsü örneði applet programý. Programý incele ve çalýºtýr.
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
// Bu program apletde(pencere)
int i=0;
double x=10.0;
do
[Link](" "+(x+=2.0),i+=30,25);
} while(x<=20.0)
41. H2AL4 : for döngüsü örneði, applet programý . Programý incele ve çalýºtýr.
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int i=0;
for(double x=10.0;x<=20.0;x+=3.0)
[Link](" "+x,i+=30,25);
42. H2AL6 : iç içe iki döngü, applet programý . Programý incele ve çalýºtýr.
Problem 1.36 [Link] : for döngüsü. Bu problem iki applet ortamýnda boyutlu bir
matrix yazdýrýr.
import [Link];
import [Link].*;
// Bu program apletde(pencere)
// 11 12 13 14
// 21 22 23 24
// 31 32 33 34
// 41 42 43 44 yazdirir
for(int i=1;i<5;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int j=1;j<5;j++)
[Link](""+i+j,i*25,j*25);
[Link]
43. H2AL7 : sayi1 den sayi2 e n er ner sayilarin toplami, applet programi
Problem 1.37 [Link] : for döngüsü. Bu problem sayi1 den sayi2 e n er ner
sayilarin toplamýný hesaplar .
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int sayi1,sayi2,sayi3;
int toplam;
t1=new TextField(5);
t2=new TextField(5);
t3=new TextField(5);
//pencereye ekle
add(t1);
add(s1);
add(t2);
add(s2);
add(t3);
add(s3);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](""+sayi1+"den "+sayi2+"e kadar sayilarin "+
toplam=0;
sayi1=[Link]();
sayi2=[Link]();
sayi3=[Link]();
for(int i=sayi1;i<=sayi2;i+=sayi3)
toplam+=i;
repaint();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 1.33 deðiºken sýnýrlarla toplama yapan [Link] programýnýn applet çýktýsý
44. H2OD1
while döngüsü ve konsol programý kullanarak 1 den n e kadar olan sayýlarýn aritmetik
ortalamasýný hesaplayiniz. n sayisi konsoldan girilecektir.
Aritmetik ortalama (1+2+3+..+n)/n formülüyle hesaplanýr.
import [Link].*;
class H2OD1
int n;
int sayi=1;
double ort=0;
[Link]("n : ");
n = [Link] ();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
while(sayi<=n)
ort=(ort + sayi)/sayi;
sayi++;
45. H2OD2
For döngüsü ve "*" karekterini kullanarak 5*4 yýldýz dikdortgenini applet olarak çizdiriniz
*****
*****
*****
*****
Problem 1.39 [Link] : for döngüsü. Bu problem 5*4 yýldýz dikdortgenini applet
olarak çizdir
import [Link];
import [Link];
int x,y;
for(y=1;y<6;y++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(x=1;x<5;x++)
[Link] ("*",20*x,20*y);}
46. H2OD3
do- while döngüsü kullanarak 1 den n e kadar olan sayýlarýn küplerinin toplamýný ve aritmetik
ortalamasýný applet programý olarak hesaplatýnýz. n sayýsý applet kutu girdisinden girilecektir.
Problem 1.40 [Link] : 1 den n e kadar sayýlarýn küplerinin toplamýný applet olarak
çizdir
import [Link];
import [Link].*;
import [Link].*;
int sayi1;
int toplam;
double ort;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
TextField t1; //girdi alanlari (kutulari)
t1=new TextField(5);
//pencereye ekle
add(s1);
add(t1);
add(s2);
[Link](this);
toplam=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi1=[Link]();
int i=1;
do
toplam+=i*i*i;
}while(++i<=sayi1);
ort=(double)toplam/(double)sayi1;
repaint();
46. H2OD3_2000
do- while döngüsü kullanarak 1 den n e kadar olan sayýlarýn küplerinin toplamýný ve aritmetik
ortalamasýný swing applet (JApplet) programý olarak hesaplatýnýz. n sayýsý JApplet kutu
girdisinden girilecektir.
import [Link].*;
import [Link].*;
import [Link].*;
{ int sayi1;
int toplam;
double ort;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JLabel s1,s2; //yazý alanlari sinifi
JTextArea ciktiAlani;
Container c=getContentPane();
[Link](new FlowLayout());
Color renk=[Link]();
ciktiAlani=new JTextArea();
[Link](renk);
[Link](s1);
[Link](t1);
[Link](s2);
[Link](ciktiAlani);
[Link](this);
sayi1=[Link]([Link]());
int i=1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
do {
toplam+=i*i*i;
while(++i<=sayi1);
ort=(double)toplam/(double)sayi1;
repaint();
[Link]
do- while döngüsü kullanarak 1 den n e kadar olan sayýlarýn küplerinin toplamýný ve aritmetik
ortalamasýný swing applet (JApplet) programý olarak hesaplatýnýz. n sayýsý
[Link]() girdisinden girilecektir.
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H2OD3_2000 extends JApplet
int n, i = 1;
int toplam = 0;
long toplam3 = 0;
double ortalama;
toplam3 += i*i*i;
toplam += i;
i++;
ortalama = (double)toplam / n;
[Link](15,10,370,20);
[Link](15,50,370,20);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
47. H2OD4
herhangi bir döngü yapýsý ve konsol programý kullanarak, n=200 deðeri için
not: ! (faktoriyel) sayýnýn birer eksilerek bire kadar çarpýldýðý diziye denir. Örneðin 4!=4*3*2*1
import [Link].*;
import Text;
class H2OD4
double faktoriyel=1;
double x;
double us=1;
double exponent=1;
x=[Link]();
for(double sayi=1;sayi<=200;sayi++)
faktoriyel*=sayi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
us*=(-1)*x;
exponent+=us/faktoriyel;
[Link]("exp(-"+x+") = "+exponent);
c:\co\java\prog>exp(-1.0) = 0.36787944117144245
48. H2OD5
Bir bilgisayar konsol bilgisayar programý yazýnýz. bu program kullanýcýnýn ismini ve boyunu
sorsun. eðer boyu 1.50 cm nin altýndaysa "o kullanýcýismi siz pek kýsaymýºsýnýz"
yazsýn,eðer kullanýcý boyu 1.90 cm nn üzerindeyse "o kullanýcýismi boyunuzda ne kadar
uzunmuº" yazsýn. kullanýcý boyu bu deðerlerin arasýndaysa "merhaba kullanýcýismi
sistemimize hosgeldiniz" yazsýn.
import [Link].*;
import Text;
class H2OD5
int boy;
String isim;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Text cin=new Text();
isim=[Link]();
boy=[Link]();
if(boy<=150)
else if(boy>=190)
else
49. H2OD5_2000
Bir bilgisayar konsol bilgisayar programý yazýnýz. bu program kullanýcýnýn ismini ve boyunu
sorsun. eðer boyu 1.50 cm nin altýndaysa "o kullanýcýismi siz pek kýsaymýºsýnýz"
yazsýn,eðer kullanýcý boyu 1.90 cm nn üzerindeyse "o kullanýcýismi boyunuzda ne kadar
uzunmuº" yazsýn. kullanýcý boyu bu deðerlerin arasýndaysa "merhaba kullanýcýismi
sistemimize hosgeldiniz" yazsýn. Çýktý için java swing JOPtionPane kullanýnýz.
import [Link];
class H2OD5_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
int boy;
String isim;
boy=[Link](
if(boy<=150)
"boy : "+boy,JOptionPane.PLAIN_MESSAGE);
else if(boy>=190)
"boy : "+boy,JOptionPane.PLAIN_MESSAGE);
else
[Link](null,
"boy : "+boy,JOptionPane.PLAIN_MESSAGE);
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
[Link]
[Link]
Ýmport [Link];
class H2AL1_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
// karºýlaºtýrmalar yapar
// ve sonucu yazdirir
boolean b1;
boolean b2;
boolean b3;
double sayi1;
double sayi2;
String s1,s2;
b1=true;
b2=false;
b3=b1&&b2;
[Link](null,""+b1+"&&"+b2+" = "+b3,
if(b3)
else if(!b3)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"if yapisinin ici",JOptionPane.PLAIN_MESSAGE);
b3=(sayi1>sayi2);
if(sayi1>sayi2)
[Link](null,""+sayi1+">"+sayi2+" = "+b3,
else if(sayi1<sayi2)
[Link](null,
""+sayi1+"<"+sayi2+" = "+(sayi1<sayi2),
else
[Link](null,""+sayi1+"=="+sayi2+" = "+(sayi1==sayi2),
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s1=[Link]("birinci String'i oku : ");
b3=[Link](s2);
if([Link](s2))
else
[Link](0);
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Bu program
double x=10.0;
String s="";
do
s=s+" "+(x+=1.0);
while(x<=20.0);
[Link](null,s,
[Link](0);
[Link]
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String args[])
// Bu program
String s="";
for(double x=10.0;x<=30.0;x+=1.0)
s=s+" "+x;
[Link](null,s,
[Link](0);
import [Link];
class H2AL5_2000
char not;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Text cin=new Text();
int A=0;
int B=0;
int C=0;
int D=0;
int E=0;
int F=0;
while(true)
String s="";
if(not=='z') {[Link](0);}
switch(not)
++A;
break;
++B;
break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
++C;
break;
++D;
break;
++E;
break;
++A;
break;
default:
break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s=s+"B lerin sayýsý :"+B+"\n";
[Link](null,s,
[Link]
[Link]
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H2AL6_2000
// Bu program
// 11 12 13 14
// 21 22 23 24
// 31 32 33 34
// 41 42 43 44 yazdirir
String s="";
for(int i=1;i<5;i++)
for(int j=1;j<5;j++)
s=s+" "+i+j;
s=s+"\n";
[Link](null,s,
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
55 H2AL7_2000: sayi1 den sayi2 e n er ner sayilarin toplami, swing Japplet programi,
JTextArea çýktýsý ile
Ýmport [Link].*;
import [Link].*;
import [Link].*;
{ int sayi1,sayi2,sayi3;
int toplam;
double ort;
JTextArea ciktiAlani;
Container c=getContentPane();
[Link](new FlowLayout());
Color renk=[Link]();
s1=new JLabel("den");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s2=new JLabel("e kadar ");
Font f=[Link]();
Color r1=[Link]();
ciktiAlani=new JTextArea();
[Link](renk);
[Link](r1);
[Link](renk);
[Link](r1);
[Link](renk);
[Link](r1);
[Link](f);
[Link](f);
[Link](f);
[Link](r1);
[Link](renk);
[Link](f);
[Link](t1);
[Link](s1);
[Link](t2);
[Link](s2);
[Link](t3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](s3);
[Link](ciktiAlani);
[Link](this);
sayi1=[Link]([Link]());
sayi2=[Link]([Link]());
sayi3=[Link]([Link]());
int i;
for(i=sayi1;i<=sayi2;i+=sayi3)
toplam+=i;
repaint();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
56 H2AL8_2000: sayýnýn e inci kuvvetinin hesaplanmasý (for döngüsü örneði) JoptionPane
konsol programý
import [Link];
class H2AL8_2000
double faktoriyel=1;
double x;
double us=1;
double exponent=1;
for(double sayi=1;sayi<=200;sayi++)
faktoriyel*=sayi;
us*=x;
exponent+=us/faktoriyel;
[Link](null,"exp("+x+") = "+exponent,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"exp(x) hesap örneði",JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
import [Link];
class H2AL9_2000
int i;
double pi=0;
int artieksi=-1;
artieksi*=-1;
pi+=4/(2.0*i-1.0)*artieksi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
58 H2OD1_2000
for döngüsü ve konsol programý kullanarak 1 den n e kadar olan sayýlarýn aritmetik
ortalamasýný hesaplayiniz. n sayisi swing JOptionPane olarak girilecektir.
import [Link].*;
import [Link];
class H2OD1_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n;
int toplam=0;
double ortalama;
toplam += i;
ortalama = (double)toplam / n;
[Link](0);
59 H2OD2_2000
while döngüsü ve "*" karekterini kullanarak 7*4 yýldýz dikdortgenini swing JOptionPane veya
swing JApplet kullanarak çizdiriniz
*******
*******
*******
*******
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class H2OD2T_2000
int i = 0,j;
String s = "";
j=0;
while(j++ < 7)
s += "* ";
s += "\n";
,JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for döngüsü ve "*" karekterini kullanarak grafik ortamýnda swing JApplet ve paint metodunu
kullanarak aºaðýdaki ºekli çizdiriniz
*******
import [Link].*;
import [Link].*;
int yer = 0;
[Link]("*",80,i*20+20);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]("*",j*20+20,80);
[Link]
Gerçek problemlerin boyutlarý genelde birinci bölümde gördüðümüz problemlere göre çok
daha büyüktür. Bu yüzden genelde programlar küçük parçalara bölünerek daha kolaylýkla
anlaºýlýr ºekle getirilmeye çalýºýlýr. Buna böl parçala ve yönet tekniði de diyebiliriz. Bu küçük
parçalara javada metot adi verilir. Java programlarý yeni metotlarý içeren java
sýnýflarýyla(class) java sýnýf kütüphanelerinde yer alan metotlarýn birleºmesinden oluºur. Java
kütüphanesinde matematik iºlemlerinden grafik, ses, giriº çýkýº iºlemleri, yanlýº kontrolu gibi
birçok konularda yazýlmýº metotlar mevcuttur. Java metotlar kolleksiyonu Java API Adýný alir.
Java sýnýf kütüphanesi adi da verilir. ªüphesiz bunun dýºýnda java metodlar kolleksiyonlarýnýn
olduðu çeºitli diðer kütüphaneler de mevcutur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] : (java applet paketi) Java applet paketi applet grafik ortamýný saðlar (grafik
programlarýnýn internet browser programlarý aracýlýðýyla görüntülenebilmesinin temellerini
oluºturur.). Bu sýnýfa paralel olarak Java 1.2 de grafik applet arayüz birimi
[Link] geliºtirilmiºtir.
[Link] : ( java window araçlarý paketi) Bu sýnýf grafik arayüzleri tanýmlamaya yara. Java
1.2 de paralel sýnýf [Link] geliºtirilmiºtir.
[Link] : ekle ve çalýºtýr türü programlar arasýnda geçiº yapabilen paketlerden oluºur.
[Link] : java programlarýna çince, japonca ve kore dilinde girdi girebilmek için
tanýmlanmýº bir arabirimdir.
[Link] : java programlarýndan yazýcýlara yazým için bilgi aktaran paketleri içerir.
[Link] : java fasulyeleri paketi, bu paketin detaylarý için ilgili bölümü inceleyiniz.
[Link] : dosya ve ekrandan girdi ve çýktý yapmak için gerekli program paketleri tanýmlanýr.
[Link] : bu paket birçok temel program içerir Bunlardan biri olan Math paketi aºaðýda
açýklanacaktýr. Lang paketi java programlarýnca otomatik olarak kullanýlýr. Ýmport deyimiyle
iave edilmesi gerekmez.
[Link] : bu paket java programýyla garbage collector (çöp toplayýcýsý) denilen otomatik
kullanýlmayan hafýza temizleme programýyla iliºkiyi saðlar.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] : bu sýnýf deðiºebilir hassasiyette arimetik iºlemler yapmak için gereken tanýmlarý
ve sýnýflarý içerir.
[Link] : sayý karekter ve string tarih gibi iºlemlerle ilgili programlar demeti içerir. Örneðin
çok dilli programlar yazmayý saðlayan internalisation paketi bu paket içinde yer alýr.
Java API dosyalarýndaki metotlarin sadece isimlerinin listesi yaklaºýk 200 sayfa boyutunda
bir liste tuttuðundan burada sadece yeri geldiðine programlarý kullanýrken örneklerde gerekli
API isimlerini göreceðiz. ªu ana kadar kullandýðýmýz java programlarýnda [Link],
[Link], [Link] [Link], [Link] ve [Link] API paketlerini
kullandýk. [Link] paketi appletleri oluºturma, appletlere giriº çýkýslarý ve dosyalarý applet
içerisinde çalýºtýrmayý saðlar. [Link] pencere(window) ortamýndaki tüm programlama
sýnýflarýný ve metotlarýný içerir. Java swing ([Link]) paketi yine ayný tür pencere(window)
ortamýnda programlama için gerekli girdi çýktý grafik ortamlarýný içerir. awt grafik ortamýna
göre daha zengin ve geliºmiº bir kolleksiyondur. Bu metotlarý ilerideki bölümlerde daha
detaylý inceleyeceðiz. [Link] paketi javaya dýºarýdan(dosya,ekran v.b) bilgi giriº çýkýºýný
ayarlar.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java metodlarýnýn tamamýnýn listesini (Ýngilizce olarak) Java doküman kütüphanesindeki api
alt gurubunda bulabilirsiniz. Java döküman kütühanesi [Link] adresinden
çekilebilir.
Java dilinde en çok kullanýlan API sýnýflarýndan birisi Math sýnýfýdýr. Bu sýnýf(class) [Link]
paketinde yer alýr. [Link] paketi java programý açýlýrken otomatik olarak çaðýrýlýr. Bütün
diðer paketler import deyimi kullanýlarak programa ilave edilirler. Math sýnýfýnda tanýmlanan
metotlarýn bazýlarý ªekil 2.1 de listelenmiºtir. Tablodaki x veya y deðiºkenleri double
deðiºken türündendir. Math sýnýfýnda(class) iki tane de sabit tanýmlanmýºtýr. Bu sabitlerden
birisi [Link] 3.14159265358979323846 (pi) sayýsýna eºittir. Diðeri Math.E
2.7182818284590452354 (e) sayýsýna eºittir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
random() Raslantýsal sayý (0 ile 1 [Link]() = 0 ila bir arasýnda her
arasinda) sayý çýkabilir
class matematik1SW
double x,y;
String s="";
x=[Link]([Link]
y=[Link]([Link]
// [Link](3.2)=3.2 [Link](-3.2)=3.2
s+="[Link]("+x+") = "+[Link](x)+"\n";
// [Link](9.2)=10 [Link](-9.8)=-9
s+="[Link]("+x+") = "+[Link](x)+"\n";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// [Link](9.2)=9 [Link](-9.8)=-10
s+="[Link]("+x+") = "+[Link](x)+"\n";
// [Link] pi sayisi
s += "[Link] = "+[Link]+"\n";
s += "[Link]("+x+") = "+[Link](x)+"\n";
s += "[Link]("+x+") = "+[Link](x)+"\n";
s += "[Link]("+x+") = "+[Link](x)+"\n";
// asin,acos,atan : radyan
s += "[Link]("+y+") = "+[Link](y)+"\n";
s += "[Link]("+y+") = "+[Link](y)+"\n";
s += "[Link]("+y+") = "+[Link](y)+"\n";
s += "Math.E = "+Math.E+"\n";
s += "[Link]("+x+") = "+[Link](x)+"\n";
s += "[Link]("+x+","+y+" ) = "+[Link](x,y)+"\n";
s += "[Link]("+x+" ) = "+[Link](x)+"\n";
s += "[Link]("+x+" ) = "+[Link](x)+"\n";
// [Link](x,y) [Link](x,y)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s += "[Link]("+x+","+y+" ) = "+[Link](x,y)+"\n";
s += "[Link]("+x+","+y+" ) = "+[Link](x,y)+"\n";
[Link](null,s,
[Link](0);
[Link]
2.2 METOTLAR
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Metotlar java programlarýnýn ana parçalarýdýr. Metotlar sýnýflarýn(class) içinde yer alan küçük
program parçacýklarýdýr. Metotlarýn çoðunda deðiºken parametreler metotlar ve sýnýflar
arasýnda iletiºimi saðlarlar. Ayrýca her metotun kendine özgü deðiºkenleri de vardýr. Metot
yapýsýnýn ana sebebi programlarý modüler hale getirmektir. Ayný zamanda ayný program
parçacýðýnýn tekrarlanmasýný önlemeyi de saðlar. Her metot çaðrýldýðý proðram parçacýðýna
belli bir deðiºkeni aktarabilir. Metotlarýn tanýmlarýnda aktardýklarý deðiºken türü tanýmlanýr.
Eðer metot hiçbir deðiºken aktarmýyorsa void sözcüðü yle tanýmlanýr. Metotlarýn genel
tanýmý aºaðýdaki gibidir. Parantez içindeki terimler kullanýlmýyabilir.
(public) (static) sýnýf deðiºken türü sýnýf ismi( sýnýf deðiºken girdi listesi)
{
sýnýf içinde geçerli degiºken tanýmlarý
double z = 2.5;
double r ;
int i = 3;
r = metotornegi(i,z);
[Link](“r = “+r);
r = 34 sonucuna ulaºýlýr. ªimdi ayný metotun statik metot olarak bir appletin içinde
kullanýlmasýný görelim.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 2.2 : [Link] programýnda kare statik metotunun kullanýlmasý
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
[Link]
iºleminde çaðýrýlmýºtýr. Bilgisayar kare(sayi) ifadesini gördüðünde metotun içine gider, orada
tanýmlanan tüm iºlemleri yaptýktan sonra return kelimesinin karºýsýndaki iºlemleri çaðýrýldýðý
yere geri iletir. Metotorneði1 java programýnda çaðýrýlan kare(sayi) metotunda sadece
sayýnýn kendisiyle çarpýmý return kelimesinin karºýsýna yazýldýðýndan, kare(sayý ) ifadesi
sayý*sayý ifadesiyle eºdeðerdir. Burada kare metotundandaki deðiºken adýnýn sayý deðil x
olarak verildiðini de burada not edelim. Sayý deðiºkeni metotun giriºinde x degiºkenine
yüklenir. Gerekli iºlemler metotda yapýldýktan sonra sadece metotun sonuçlarý return
deyimiyle metodun deðiºken türü olarak (bu metod için double ) geri döner.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Text cin=new Text();
Terimi Text sýnýfýndan(class) cin nesnesini tanýmlar. Nesne(object) tanýmý yaparken ayný
metotlarda olduðu gibi deðiºken veya nesneleri girdi olarak tanýmlamamýz mümkündür.
Diðer bir örnek olarak yine daha önceki örnek problemlerde kullandýðýmýz Label
sýnýfýndan(class) kutubasligi nesnesinin tanýmýný ve TextField sýnýfýndan(class) kutugirdisi
nesnesini gösterebiliriz.
kutugirdisi=new TextField(5);
nesne(object) ismi = new Sýnýf (class) ismi(deðiºken veya nesne girdi listesi)
Nesne tanýmýný daha iyi anlamak için metotornegi2 sýnýfýný yazdýðýmýz programý biraz
deðiºtirerek metotornegi3 ve metotornegi3a sýnýflarýný olusturalým ve kare metotumuzu
metotornegi3a sýnýfýna yerlestirelim.
class metotornegi3a
{
// sayinin karesi dinamik metotu
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double kare(double x)
{
return x*x;
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](sayi+"nin karesi = "+ [Link](sayi),25,50);
}
}
class metotornegi6
{
// sayinin karesi dinamik metotu
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
2.4 METOTLARIN KENDÝ KENDÝNÝ ÇAÐIRMASI (RECURSION)
Bazý problemlerin çözümünde bir metotun kendi kendini çaðýrmasý yararlý olabilir. Java bir
metotun kendi kendini çaðýrmasýna izin verir. Burada dikkatli olunmasý gereken nokta bu
kendi kendine çaðýrýlma döngüsünün sonsuza kadar sürmesinin bir kontrol yapýsý
kullanýlarak engellenmesidir. Kendi kendini çaðýran programlarda mutlaka bir döngü çýkýº
ºartý tanýmlanmalýdýr.
import [Link].*;
import Text;
class faktoriyel
{
public static void main(String args[]) throws IOException
{
int faktoriyel=1;
Text cin=new Text();
int faktoriyelsayi;
[Link]("Bir tamsayi giriniz : ");
faktoriyelsayi=[Link]();
for(int sayi=1;sayi<=faktoriyelsayi;sayi++)
{ faktoriyel*=sayi;}
[Link](faktoriyelsayi + " faktoriyel: " + faktoriyel);
}
}
deðiºik giriº çýkýº opsiyonlarýný biraz daha anlamak için ayný programýn JOPtionPane
kullanýlarak yazýlmýº eºdeðerini de verelim :
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class faktoriyelSW
int faktoriyel=1;
int faktoriyelsayi;
for(int sayi=1;sayi<=faktoriyelsayi;sayi++)
{ faktoriyel*=sayi;}
JOptionPane.PLAIN_MESSAGE);
[Link](0);
ªimdi ayný programýn faktoriyel metodu ayrý yazýlmýº fakat yine for döngüsü kullanan
ºekillerine göz atalým. Program 2.10 ve 2.11 de birbirinin ayný olu, program 2.10 da çýktý
[Link] deyimiyle alýnýrken 2.11 de çýktý [Link]
metodu kullanýlarak aktarýlmýºtýr.
import [Link].*;
import Text;
class faktoriyel1
{
public static long faktoriyel(int x)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
long faktoriyel=1;
for(int sayi=1;sayi<=x;sayi++)
{ faktoriyel*=sayi;}
return faktoriyel;
}
public static void main(String args[]) throws IOException
{
Text cin=new Text();
int faktoriyelsayi;
[Link]("Bir tamsayi giriniz:");
faktoriyelsayi=[Link]();
[Link](faktoriyelsayi+" faktoriyel:" + faktoriyel(faktoriyelsayi));
}
import [Link];
class faktoriyel1SW
{ long faktoriyel=1;
for(int sayi=1;sayi<=x;sayi++)
{ faktoriyel*=sayi;}
return faktoriyel;
{ int faktoriyelsayi;
faktoriyelsayi=[Link](
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](0);
Program 2.12 : kendi kendini çaðýran (recursive) faktoriyel metotunu kullarak faktoriyel
hesaplayan [Link] programý
import [Link].*;
import Text;
class faktoriyel2
{
public static long faktoriyel(int x)
{
if( x <= 1 )
return 1;
else
return x * faktoriyel( x – 1);
}
Program 2.13 : kendi kendini çaðýran (recursive) faktoriyel metotunu kullarak faktoriyel
hesaplayan
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
class faktoriyel2SW
if( x <= 1 )
return 1;
else
{ int faktoriyelsayi;
JoptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 2.3 : kendi kendini çaðýran (recursive) faktoriyel metotunu kullarak faktoriyel
hesaplayan
5! = 5 * 4! = 4 * 3! = 3 * 2! = 2 * 1! = 1
sonuç 120 olarak ana programa gönderilecektir. Kendi kendini çaðýran metodlar mutlak bir
gereksinim olmadýkça tercih edilmez. Bu tür programlamada hem sonsuz döngülerin
görülmesi daha güç olabilir, hemde for, while gibi döngüler kullanýlarak programlamaya göre
programlar daha yavaº çalýºýr. Gerçek uygulamalarda kendi kendini çaðýran programlar
genellikle bir döngü yapýsý kurmadan çok tek kerelik çaðýrmalarý gerçekleºtirmek için
kullanýlýrlar.
Java ayný adlý metotlarýn ayný sýnýf içerisinda kullanýlmasýna izin verir. Ayný sýnýfta(class)
kullanýlan metotlarýn girdi deðiºkenlerinin deðiºken türlerinin veya deðiºken sayýlarýnýn farklý
olmasý gerekir. Java ayný isimli ve ayni degiºken türlü iki metotu birbirinden ayýramaz.
Örneðin
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Veya
Public int Bmetodu(double Cdeðiºkeni)
Java tarafýndan ayýrt edilir ve birlikte ayný sýnýfýn (class) içinde yer alabilir. Eðer birbirinin tam
olarak eºiti metotlar deðiºik sýnýflarda yer alýyorsa bunun herhangi bir sakýncasý yoktur.
Program 2.11'de [Link] programý görülmektedir. Bu programda daha önceki
programlarda da kullandýðýmýz kare metotunu int ve double girdi deðiºkenleriyle iki kere ayný
sýnýfýn içerisinde tanýmlayacaðýz.
import [Link];
import [Link];
int kare(int x)
{
return x*x;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double kare(double x)
{
return x*x;
}
[Link]
Bu programda parantez içerisinde 7 (tamsayý) verildiðinde java tamsayi metotu kare(int x),
7.5(gerçek sayý) verildiðinde gerçeksayi metotu kare(double x) i çaðýrýr.
import [Link];
import [Link].*;
JTextArea ciktiAlani;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ciktiAlani=new JTextArea();
Container c=getContentPane();
[Link](ciktiAlani);
int x1=7;
double x2=7.0;
x1=5;
x2=5.0;
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
double exponent=1.0;
for(int i=1;i<=x;i++)
exponent*=Math.E;
return exponent;
[Link]
ªekil 2.5 Gerçek ve tamsayý deðiºkenleri çaðýran ayný adlý metodlarýn çaðýrýlmasý
örneði
Metotlarýn içinde kullanýlan deðiºkenler sadece metotlara aittir. O metotun dýºýnda tanýmlarý
yoktur. Eðer deðiºkenler metotlarýn dýºýnda sýnýf(class) deðiºkenleri olarak tanýmlanýrsa
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
metota da aynen aktarýlýrlar. Sýnýf deðiºkeniyle ayný isimde bir deðiºken mettotta da
tanýmlanmýºsa bu deðiºken metotun içinde kullanýlan metotun deðiºkenidir
import [Link];
import [Link];
double x ;
int y ;
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class metotvesinifdeg1 extends Applet
{
//buradaki deðiºkenler tüm sýnýfa aittir
double x ;
int y ;
Program 2.17 deki metotvesinifdeg1 sýnýfýndaki metot1 metotunun içinde ise yerel
deðiºkenler x ve y tanýmlanmýºtýr. Bu yüzden metot1 in içindeki x ve y deðiºkenlerinin
deðiºmesi paint metotundaki drawString metotu tekrar çaðýrýldýðýnda x ve y nin deðerlerinin
deðiºmediði görülür.
Nesne tanýmý yapýldýðýnda Bilgisayar bu nesne için bir adres yaratýr. Yeni adres yarat komutu
new komutudur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// java kutuphanelerinde tanimli bir sinifin cagirilip
// nesne olarak tanimlanmasi ve adres paylasimi
class Point1
{
public static void main(String args[])
{
//Point sinifi x,y koordinatli bir nokta tanimlar
Point nokta1,nokta2;
nokta1=new Point(100,100);
nokta2=nokta1;
// nokta1 ve nokta2 bilgisayarda ayni
// adres kutusunu paylasiyor
[Link]("nokta1 ve nokta2 ayni degerleri tasiyor");
[Link]("ve ayný bilgisayar adresini paylasiyor");
[Link]("nokta 1 : "+nokta1.x+" , "+nokta1.y);
[Link]("nokta 2 : "+nokta2.x+" , "+nokta2.y);
nokta1.x=200;
nokta1.y=200;
[Link]("nokta1 in degeri degistirildi");
[Link]("nokta 1 : "+nokta1.x+" , "+nokta1.y);
[Link]("nokta 2 : "+nokta2.x+" , "+nokta2.y);
// nokta1 ve nokta2 nin degerleri ayni fakat bilgisayarda
// degisik adreslerde tanimlanmis
nokta1=new Point(100,100);
nokta2=new Point(100,100);
[Link]("nokta1 ve nokta2 ayni degerleri tasiyor");
[Link]("fakat ayni bilgisayar adresini paylasmiyor");
[Link]("nokta 1 : "+nokta1.x+" , "+nokta1.y);
[Link]("nokta 2 : "+nokta2.x+" , "+nokta2.y);
nokta1.x=200;
nokta1.y=200;
[Link]("nokta1 in degeri degistirildi");
[Link]("nokta 1 : "+nokta1.x+" , "+nokta1.y);
[Link]("nokta 2 : "+nokta2.x+" , "+nokta2.y);
}
}
[Link] da verilen
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Point nokta1,nokta2;
nokta1=new Point(100,100);
nokta2=nokta1;
nokta1=new Point(100,100);
nokta2=new Point(100,100);
deyimi ile ise nokta1 ve nokta2 için iki ayrý adres yaratýlmýºtýr. Bu yüzden nokta1 deðiºtiðinde
nokta2 eski deðerinde kalýr.
Ayný adresin iki deðiºken tarafýndan kullanýlmasý ancak gerektiði zaman ve çok dikkat
sarfederek yapýlmalýdýr. Gereksiz yere kullanýlmasýndan kesin olarak kaçýnýlmalýdýr.
Program güvenlik ve kontrol problemleri yaratabildiði gibi, istemediðimiz deðiºken
deðerlerinin silinmesi sonucunu da verebilir.
2.7 ALISTIRMALAR
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
return 1+(int)([Link]()*6);
H4A1b sinifinda(class) java konsol ana metotu (public void main) yazarak zar degerini
yazdiriniz.
class H4A1b
{
public static void main (String args[]) throws IOException
{
[Link]("zar degeri : "+[Link]());
}
}
H4A1c sinifinda java konsol ana metotunda (public void main) metotunda yüz(100) kere zar
attýrarak ortalamasýný hesaplayýnýz.
Not : for veya while döngüsü kullanabilirsiniz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
toplam+=[Link]();
}
ortalama=toplam/100.0;
[Link]("100 zarin ortalamasi = "+ortalama);
}
H4A1d sinifinda java konsol ana metotunda (public void main) bin(1000) kere zar attýrarak
her rakamýn kac kere geldigini bulunuz ve yazdýrýnýz.
Not : switch – case deyimi bu tür programlar için idealdir
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
break;
case 5:
zar5++;
break;
case 6:
zar6++;
break;
}
zaratimsayisi++;
}
H4A1bSW sinifinda(class) java konsol ana metotu (public void main) yazarak zar degerini
yazdiriniz. Yazdýrma iºlemini java swing sýnýfýndan JoptionPane sýnýfýný kullanarak yaptýrýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import H4A1a;
class H4A1bSW
[Link](0);
H4A1cSW sinifinda java konsol ana metotunda (public void main) metotunda yüz(100) kere
zar attýrarak ortalamasýný hesaplayýnýz. Yazdýrma iºlemini java swing sýnýfýndan JoptionPane
sýnýfýný kullanarak yaptýrýnýz.
Not : for veya while döngüsü kullanabilirsiniz.
import H4A1a;
class H4A1cSW
double ortalama;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double toplam=0;
for(int sayi=0;sayi<100;sayi++)
toplam+=[Link]();
ortalama=toplam/100.0;
JOptionPane.PLAIN_MESSAGE);
[Link](0);
H4A1dSW sinifinda java konsol ana metotunda (public void main) bin(1000) kere zar
attýrarak her rakamýn kac kere geldigini bulunuz ve yazdýrýnýz. Yazdýrma iºlemini java swing
sýnýfýndan JoptionPane sýnýfýný kullanarak yaptýrýnýz.
Not : switch – case deyimi bu tür programlar için idealdir
import H4A1a;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
int zardegeri;
int zar1,zar2,zar3,zar4,zar5,zar6;
int zaratimsayisi=0;
zar1=0;
zar2=0;
zar3=0;
zar4=0;
zar5=0;
zar6=0;
while(zaratimsayisi<1000)
zardegeri=[Link]();
switch(zardegeri)
case 1:
zar1++;
break;
case 2:
zar2++;
break;
case 3:
zar3++;
break;
case 4:
zar4++;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
break;
case 5:
zar5++;
break;
case 6:
zar6++;
break;
zaratimsayisi++;
String s="";
[Link](null,s
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
3.
import [Link].*;
import [Link];
import [Link].*;
public class zarApplet extends Applet implements ActionListener
{
int toplamzaratisi=0;
int toplam=0;
TextField ilkzar,ikincizar;
Button salla; //zar atma düðmesi
int zar1,zar2;
public static int zar()
{
return 1+(int)([Link]()*6);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
salla=new Button("Zari salla ve at");
add(salla);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
zar1=zar();
zar2=zar();
[Link]([Link](zar1));
[Link]([Link](zar2));
toplam+=(zar1+zar2);
toplamzaratisi++;
repaint();
}
import [Link].*;
import [Link];
import [Link].*;
import H4A2b;
public class H4A2c extends Applet implements ActionListener
{
int toplamzaratisi=0;
int toplam=0;
TextField ilkzar,ikincizar;
Button salla; //zar atma d�gmesi
int zar1,zar2;
H4A2b z=new H4A2b();
public void init()
{
//programi baslat
ilkzar=new TextField(10); // Textfield sinifi ilkzar nesnesini yarat
add(ilkzar); // ilk zar nesnesini pencereye ekle
ikincizar=new TextField(10);// Textfield sinifi ikincizar nesnesini yarat
add(ikincizar); // ikinci zar nesnesini pencereye ekle
salla=new Button("Zari salla ve at");
add(salla);
[Link](this);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e)
{
zar1=[Link]();
zar2=[Link]();
[Link]([Link](zar1));
[Link]([Link](zar2));
toplam+=(zar1+zar2);
toplamzaratisi++;
repaint();
}
[Link]
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
y+=15;
}
}
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 2.29 Fibobachi testi, swing applet programý [Link]
import [Link].*;
import [Link].*;
import [Link].*;
Container c=getContentPane();
[Link](new FlowLayout());
[Link](cikti);
[Link]([Link]());
String s="";
for(long i=0;i<=15;i++)
s+="Fibonachi("+i+") = "+fibonachi(i)+"\n";
[Link](s);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public long fibonachi(long sayi)
[Link]
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
public fibonnachitesti1SWF()
Container c=getContentPane();
[Link](new FlowLayout());
[Link](cikti);
[Link]([Link]());
String s="";
for(long i=0;i<=15;i++)
s+="Fibonachi("+i+") = "+fibonachi(i)+"\n";
[Link](s);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else return fibonachi(sayi - 1)+fibonachi(sayi - 2);
[Link](new BasicWindowMonitor());
[Link](150,350);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
8. [Link] programýný inceleyiniz ve applet ortamýnda çalýºtýrýnýz.
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
JLabel rakametiketi,sonucetiketi;
JTextField rakam,sonuc;
Container c=getContentPane();
[Link](new FlowLayout());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
rakam=new JTextField(10);
[Link](this);
sonuc=new JTextField(10);
[Link](false);
[Link](rakametiketi);
[Link](rakam);
[Link](sonucetiketi);
[Link](sonuc);
long sayi;
long fibonachisayisi;
sayi=[Link]([Link]());
showStatus("Fibonachi hesaplanýyor....");
fibonachisayisi=fibonachi(sayi);
showStatus("Fibonachi hesaplandi....");
[Link]([Link](fibonachisayisi));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else return fibonachi(sayi - 1)+fibonachi(sayi - 2);
[Link]
10. Bir kürenin hacmini hesaplayacak bir applet programý yazýnýz. Kürenin hacmi
küreHacmi isimli metot tarafýndan hesaplansýn. Applet bir girdi alanýna kürenin yariçapýný
sorsun ve yarýçap girildiðinde yeni küre hacmi ekranda gösterilsin.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
kutubasligi=new Label("Kurenin yaricapini (m)giriniz : ");
add(kutubasligi);
kutugirdisi=new TextField(10);
add(kutugirdisi);
yaricap=0;
hacim=0;
[Link](this);
}
//=====================================================
// girdi alanindaki olan olaylari dinleme metotu
// Her yeni rakam girildiginde bu metot cagirilir
public void actionPerformed(ActionEvent e)
{
Double sayi1=new Double([Link]() );
yaricap=[Link]();
hacim=kureninhacmi(yaricap);
[Link](" ");//kutudaki rakami sil
repaint();//pencereyi yeniden paint metotuna gore ciz
}
//=====================================================
// paint (boya=pencereye ciz metotu)
public void paint(Graphics g)
{
[Link](yaricap+" m capindaki kurenin hacmi : "+hacim+" m^3",25,50);
}
//=====================================================
//kurenin hacmini hesaplama metotu
public double kureninhacmi(double r)
{
return (4.0/3.0)*[Link]*r*r*r;
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
11. Bir dik üçgenin hipotenüsünü hesaplayan bir applet programý yazýnýz. Program dik
üçgenin iki dik kenarýný applet de girsin ve hipotenus metotuyla hesaplasýn ve sonucu
applete yazdýrsýn.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
dikkenar1=[Link]();
Double sayi2=new Double([Link]() );
dikkenar2=[Link]();
//[Link](" ");//kutudaki rakami sil
repaint();//pencereyi yeniden paint metotuna gore ciz
}
//=====================================================
// paint (boya=pencereye ciz metotu)
public void paint(Graphics g)
{
[Link](" hipotenus = "+hipotenus(dikkenar1,dikkenar2),25,80);
}
//=====================================================
//ucgenin hipotenusunu hesaplama metotu
public double hipotenus(double dk1,double dk2)
{
return [Link](dk1*dk1+dk2*dk2);
}
}
[Link]
ªekil 2.13 Bir dik üçkenin hipotenüsünü hesaplayan [Link] applet çýktýsý
12. H3OD5_2000
iki kenar ve aralarýndaki açý (derece cinsinden ) verildiðinde üçgenin üçüncü kenarýný
hesaplayacak
double aciderece)
metodunu yazýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
not:karsikenar=[Link](birinciyan*birinciyan+ikinciyan*ikinciyan-
2*birinciyan*ikinciyan*[Link](aradakiaçý derece));
bu metodu H3OD5_2000 sýnýfý JoptionPane konsol programý main metodunda kullanýnýz (iki
yan kenar ve aradaki açý derece cinsinden verilecek, üçüncü kenar hesaplanarak
yazýlacak)
import Mathd;
double kenar;
kenar=[Link](a*a+b*b-2*a*b*[Link](t));
return kenar;
double sayi1;
double sayi2;
double sayi3;
sayi1=[Link]([Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
("birinci kenarý giriniz : "));
sayi2=[Link]([Link]
sayi3=[Link]([Link]
[Link](null,
JoptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
13. H3AL2 sýnýfýnda static double exp(double x) metodunu yaz ve ayný sýnýf içinde
çaðýrarak ekrandan girilen bir x deðeri için sonucu konsol ortamýnda hesaplattýr.
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double exp(double x)
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
double sayi;
sayi=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
14. H3AL2_2000 sýnýfýnda static double exp(double x) metodunu yaz ve ayný sýnýf içinde
çaðýrarak ekrandan JoptionPane kullanýlarak girilen bir x deðeri için sonucu konsol
ortamýnda hesaplattýr.
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double sayi;
sayi=[Link]([Link]
[Link](null,"exp("+sayi+") = "+exp(sayi),
[Link](0);
[Link]
import [Link].*;
import H3AL2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args) throws IOException
double sayi;
sayi=[Link]();
import H3AL2_2000;
double sayi;
sayi=[Link]([Link]
[Link](null,"exp("+sayi+") = "+H3AL2_2000.exp(sayi),
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"H3AL2_2000.exp() statik metodu",JoptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
17. H3AL4 sýnýfýnda yazýlan double exp(double x) metodunu ayný sýnýfda çaðýrarak
ekrandan girilen bir x deðeri için sonucu konsol ortamýnda hesaplattýr.
import [Link].*;
double faktoriyel=1;
double us=1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
double sayi;
sayi=[Link]();
18. H3AL4_2000 sýnýfýnda yazýlan double exp(double x) metodunu ayný sýnýfda çaðýrarak
ekrandan girilen bir x deðeri için sonucu JOPtionPage kullanarak konsol ortamýnda
hesaplattýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H3AL4_2000
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
double sayi;
sayi=[Link]([Link]
[Link](null,"exp("+sayi+") = "+[Link](sayi),
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"H3AL4_2000, exp() dinamik metodu",JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
import [Link].*;
class H3AL5a
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
double sayi;
sayi=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link]; // giriº çýký
class H3AL5a
double faktoriyel=1;
double us=1;
double exponent=1;
for(double i=1;i<=300;i++)
faktoriyel*=i;
us*=x;
exponent+=us/faktoriyel;
return exponent;
double sayi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi=[Link]([Link]
[Link](null,"exp("+sayi+") = "+[Link](sayi),
[Link](0);
import [Link].*;
import H3AL5a;
double sayi;
sayi=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
import H3AL5a;
double sayi;
sayi=[Link]([Link]
[Link](null,"exp("+sayi+") = "+[Link](sayi),
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
23 . H3OD1
Math kütüphanesinde aºaðýdaki metotlar tanýmlanmýºtýr.
public static native double sin(double a)
a radyan cinsinden
public static native double cos(double a)
a radyan cinsinden
public static native double tan(double a)
a radyan cinsinden
public static native double asin(double a)
sonuç deðeri : -pi/2 den pi/2 ye kadar.
public static native double acos(double a)
sonuç deðeri 0 dan pi’ ye kadar
public static native double atan(double a)
sonuç deðeri : -pi/2 den pi/2 ye kadar.
public static native double atan2(double a,
double b)
sonuç deðeri : -pi den pi ye kadar
not :
derece=radyan/[Link]*180;
class Mathd
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double sind(double a)
double pi=[Link];
double r=(a/180.0)*pi;
double sind=[Link](r);
return sind;
double pi=[Link];
double r=(a/180.0)*pi;
double cosd=[Link](r);
return cosd;
double pi=[Link];
double r=(a/180.0)*pi;
double tand=[Link](r);
return tand;
double asind=[Link](b)*180.0/[Link];
return asind;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
double acosd=[Link](b)*180/([Link]);
return acosd;
double atand=[Link](b)*180/([Link]);
return atand;
double atand=Math.atan2(a,b)*180.0/([Link]);
return atand;
import [Link];
import [Link].*;
import [Link].*;
import Mathd;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double a;
double b;
Label s1;
TextField t1;
Label s2;
TextField t2;
t1=new TextField(15);
t2=new TextField(15);
add(s1);
add(t1);
add(s2);
add(t2);
[Link](this);
[Link](this);
a=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double sayi2=new Double([Link]() );
b=[Link]();
[Link]("");
[Link]("");
repaint();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 2.18 Bir derece cinsinden trigonometrik fonksiyonlarý hesaplayan [Link]
çýktýsý
24. H3OD2
Bir konsol programý oluºturunuz. Bu programa 0-1 arasýnda bir girdi giriniz. Mathd sýnýfýndan
atand,acosd ve asind statik metotlarýný kullanarak bu metotlarýn sonuçlarýný konsol
ortamýnda çýktýya yazdýrýnýz.
import [Link].*;
import Text;
import Mathd;
double a;
a=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("acos("+a+"): " + [Link](a)+" derece");
25. H3OD3
kendi kendini çaðýran (recursive), tabanýn kuvvetinci kuvvetini hesaplayacak ( taban^kuvvet,
2^3=8 gibi)
public static pow(double taban, double kuvvet)
metotunu H3OD3 sýnýfýnda, konsol programý olarak yazýnýz. main metotunda dýºarýdan bir
sayý okuyarak bu metot yardýmýyla sonucu hesaplayýnýz.
not: [Link](taban,1) çaðýrýmý taban deðerini geri verecektir.
import [Link].*;
if(y<0) return 0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args) throws IOException
double sayi1;
double sayi2;
sayi1=[Link]();
sayi2=[Link]();
26. H3OD4
döngü yapýsýyla hesap yapan, tabanýn kuvvetinci kuvvetini hesaplayacak ( taban^kuvvet,
2^3=8 gibi)
public pow(double taban, double kuvvet)
H3OD4a sýnýfýnda yazýnýz. H3OD4 sýnýfýnda bir applet programý oluºturarak H3OD4a
sýnfýndaki pow metotu yardýmýyla verilen bir sayýnýn verilen bir kuvvetini hesaplayýnýz. ve
appletde çýktý olarak yazdýrýnýz.
import [Link];
import [Link].*;
import [Link].*;
class H3OD4a
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double k=1.0;
if(b<0)
for(int i=0;i<(int)(-b);i++)
{k*=a;}
k=1.0/k;
else if(b==0)
k=1.0;
else if(b>0)
for(int i=1;i<=(int)b;i++)
{k*=a;}
return k;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double a;
double b;
Label s1;
TextField t1;
Label s2;
TextField t2;
t1=new TextField(10);
t2=new TextField(10);
add(s1);
add(t1);
add(s2);
add(t2);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
a=[Link]();
b=[Link]();
[Link]("");
[Link]("");
repaint();
27. H3OD4_2000
döngü yapýsýyla hesap yapan, tabanýn kuvvetinci kuvvetini hesaplayacak ( taban^kuvvet,
2^3=8 gibi)
public pow(double taban, double kuvvet)
H3OD4a sýnýfýnda yazýnýz. H3OD4_2000 sýnýfýnda bir siwng JApplet programý oluºturarak
H3OD4a sýnfýndaki pow metotu yardýmýyla verilen bir sayýnýn verilen bir kuvvetini
hesaplayýnýz. ve appletde çýktý olarak yazdýrýnýz.
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class H3OD4a
double k=1.0;
if(b<0)
for(int i=0;i<(int)(-b);i++)
{k*=a;}
k=1.0/k;
else if(b==0)
k=1.0;
else if(b>0)
for(int i=1;i<=(int)b;i++)
{k*=a;}
return k;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H3OD4_2000 extends JApplet implements ActionListener
double a;
double b;
JLabel s1;
JTextField t1;
JLabel s2;
JTextField t2;
JTextArea cikti;
cikti=new JTextArea();
Container c=getContentPane();
[Link](new FlowLayout());
t1=new JTextField(10);
t2=new JTextField(10);
[Link](s1);
[Link](t1);
[Link](s2);
[Link](t2);
[Link](cikti);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
a=[Link]([Link]() );
b=[Link]([Link]() );
[Link]("");
[Link]("");
repaint();
[Link]
28. H3OD5
iki kenar ve aralarýndaki açý (derece cinsinden ) verildiðinde üçgenin üçüncü kenarýný
hesaplayacak
public static double ucgenkarsýkenar(double birinciyan, double ikinciyan,
double aciderece)
metotunu yazýnýz.
not : karsikenar=[Link](birinciyan*birinciyan+ikinciyan*ikinciyan-
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
2*birinciyan*ikinciyan*[Link](aradakiaçý derece));
bu metotu H3OD5 sýnýfý konsol programý main metotunda kullanýnýz (iki yan kenar ve aradaki
açý derece cinsinden verilecek, üçüncü kenar hesaplanarak yazýlacak)
import [Link].*;
import Mathd;
double kenar;
kenar=[Link](a*a+b*b-2*a*b*[Link](t));
return kenar;
double sayi1;
double sayi2;
double sayi3;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi1=[Link]();
sayi2=[Link]();
sayi3=[Link]();
Bu formülü hesaplayacak olan statik erf metodunu yazýnýz ve java swing çýktýsý verecek bir örnekte
deneyiniz.
30. Bir konsol programý yazýnýz. Text sýnýfý kullanarak dýºarýdan x deðerini, celcius,
fahrenheight cinsinden girilen deðerin celcius eºitini hesaplasýn. Bunun için
C=5/9*(F-32)
formülünü kullanabilirsiniz.
Ýkinci metot, fahrenheight, derece celcius cinsinden girilen deðerin fahrenheight eºdeðerini
hesaplasýn.
31. Bir applet programý yazýnýz. Bu programýn içindeki kubunhacmi metodu kübün hacmini
hesaplasýn. Applet kullanýcýya kübün kenar uzunluðunu sorsun ve hacmini versin. okuyunuz.
erf statik metodu yaratarak formülü hesaplayýnýz. Ana programda erf metodunu çaðýrýnýz ve
sonucunu yazdýrýnýz. Hata analizi yaparak döngüyü kaç terim için hesaplamanýz gerektiðine
karar veriniz.
32. Sýcaklý[Link] programýný denemek için bir swing JApplet programý yazýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
33. mesafe metodunu yazýnýz. Bu metod iki noktanýn (x1,y1) ve (x2,y2) arasýndaki
mesafeyi hesaplasýn. Bu metodu bir konsol test programýnda deneyin.
34. Bir tam sayý eðer kendisinden baºka bir tam sayýyla bölünemiyorsa, asal sayý adýný
alýr. Örneðin 2,3,5,7,11..
Asal sayýlarý bulan bir metot yazýnýz. Bu metotu bir applette kullanarak 1 den 1000 e kadar
olan sayýlar arasýndaki asal sayýlarý belirleyiniz.
35. Üç (gerçek veya tamsayý) sayýnýn arasýndan minimum olaný bulan minimum3 metodunu
yazýnýz ve bir konsol programýnda test ediniz
36. Üç sayýnýn (gerçek veya tamsayý) arasýndan maksimum olaný bulan maksimum3
metodunu yazýnýz ve bir konsol programýnda test ediniz
37. tekmi isimli boolean bir metot yazýnýz. bu metot eðer girilen sayý tekse true deðeri, sayý
çiftse false deðeri versin. Bu metodu bir applet programýnda test ediniz.
import [Link].*;
import [Link];
import [Link].*;
Label rakametiketi,sonucetiketi;
TextField rakam,sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void init()
rakam=new TextField(10);
[Link](this);
sonuc=new TextField(10);
[Link](false);
add(rakametiketi);
add(rakam);
add(sonucetiketi);
add(sonuc);
double sayi;
double sayisi;
sayi=[Link]();
sayisi=hacim(sayi);
showStatus("hesaplandi....");
[Link]([Link](sayisi));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double sayi2=new Double([Link]() );
sayisi=[Link]();
return (4.0/3.0)*[Link]*[Link](x,3);
Sýnýf (Class) deyince herhangi bir nesnenin genel tanýmlanmasýný anlýyoruz. Bu sýnýflardan
deðiºkenler tanýmlandýklarýnda nesneleri oluºtururlar. Örneðin kalem dediðimizde genel bir
sýnýfý anlatýyoruz. Alinin cebindeki kýrmýzý kalem ise belirli bir nesnedir. Sýnýfýn genel tanýmý
ºu ºekilde yapýlabilir :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class sýnýfýn_ismi
{
//sýnýfa ait deðiºken listesi
deðiºken_türü deðiºken_ismi;
deðiºken_türü deðiºken_ismi;
.........
//sýnýfa ait metot listesi
Sýnýf (class) tanýmýnda metotlarýn (veya deðiºkenlerin) bulunmasý ºart deðildir. Bulunduklarý
takdirde bunlar o sýnýfa ait veya sinifin üyesi metotlar olarak düºünülür. Ýlk sýnýf örneði olarak
içinde hiçbir metotun yer almadýðý bir kutu sýnýfý tanýmlýyalým. Bir kutuyu üç geometrik boyutu
(eni,boyu,yüksekliði) cinsinden tanýmlayabiliriz.
class Kutu
{
double en;
double boy;
double yukseklik;
}
Üstte bahsettiðimiz gibi sýnýf yeni bir deðiºken türü yaratýr. Yukardaki sýnýfýn yarattýðý
deðiºken türünün adý Kutu’dur. Kutu deðiºkenini baºka bir proðramda tanýmlarken
budeðiºken türünden bir nesne yaratýlýr. Örneðin
kutu1, kutu türünde tanýlanmýº bir nesnedir. Bu nesnenin kendisinin de en boy ve yükseklik
olmak üzere üç alt deðiºkeni mevcuttur. Eðer bir programda kutu1 deðiºkeni tanýmlanmýºsa,
bu deðiºkenin alt degiºkenlerine ºu ºekilde ulaºýlabilir :
[Link]=1.0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªimdi Kutu sýnýfýndan nesneyi kullanacak ufak bir kututestý sýnýfý oluºturalým ve Kutu sýnýfýný
bu sýnýfta kullanalým.
class Kutu
double en;
double boy;
double yukseklik;
class kututesti
double hacim;
String s="";
[Link]=10.0;
[Link]=20.0;
[Link]=30.0;
hacim=[Link]*[Link]*[Link];
[Link](null,s,
[Link](0);}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
java kututesti
[Link]
Sonucunu verir. kutu1 nesnesi yaratýldýðýnda bilgisayar belleðinde kutu1 için bir adres
tanýmlanýr. New Kutu() deyimi verildiðinde ise bilgisayrýn belleginde en,boy ve yükseklik
deðiºkenleri için yer ayrýlýr ve bu yerlerin adresleriyle kutu1 nesnesinin adresi arasýnda
baðlantý saðlanýr. Bunu grafik olarak anlatalým :
Boy
Yükseklik
Not: null terimi bilgisayar beleðinin boº olduðunu gösterir. Yukardaki grafikte ilk olarak
Kutu kutu1;
tanýmý yapýldýðýnda bilgisayar belleðinde 1 byte boyutunda bir yer tanýmlar. Ve bu yere boº
anlamýna gelen null degerini yükler. Ýkinci durumda ise ( kutu1=new Kutu() tanýmýnda) kutu1
nesne adresindeki kutuda en,boy,yükseklik deðiºkenlerinin adresleri kaydedilmiºtir. Bu adres
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
aracýlýðýyla en boy ve yükseklik deðiºkenlerine benimkutum degiºkeni üzerinden ulaºýlabilir.
Diðer deyimle en,boy,yükseklik kutu1 nesnesinin alt deðiºkenleridir.
Ýkinci bir programda Kutu sýnýfý iki nesne tanýmlama gereði duyduðumuzu varsayalým. Buna
örnek olarak ªekil 3.2.1 de [Link] programý tanýmlanmýºtýr.
Program 3.1 : Kurucu metot örneði, Kutu sýnýfý iki nesne tanýmlayan [Link] programý
class Kutu
double en;
double boy;
double yukseklik;
class kututesti1
double hacim;
String s="";
[Link]=10.0;
[Link]=20.0;
[Link]=30.0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
hacim=[Link]*[Link]*[Link];
[Link]=5.0;
[Link]=10.0;
[Link]=15.0;
hacim=[Link]*[Link]*[Link];
[Link](null,s,
[Link](0);
Bu programýn çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
göndermezler. Ýsimleri de herzaman sýnýf(class) ismiyle ayný olur. Program 3.1 deki programý
kurucu (constructor) metotu kullanarak tekrar yazalým.
Program 3.2 : Kurucu metot örneði, Kutu sýnýfý iki nesneyi kurucu(constructor) metotu
yardýmýyla tanýmlayan [Link] programý
class Kutu
double en;
double boy;
double yukseklik;
en=e;
boy=b;
yukseklik=y;
class kututesti2
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double hacim;
String s="";
hacim=[Link]*[Link]*[Link];
hacim=[Link]*[Link]*[Link];
[Link](null,s,
[Link](0);
Bu program bir öncekinin ayný sonucu verir. Fakat burada bir önceki programda yapýlan
Tanýmý yerini
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Tekrar yukarýda incelediðimiz kutu sýnýfýný göz önüne alalým. Hacim bir kutunun özellikleri
arasýnda yer alýr, ve her zaman kutunun hacminin hesaplanmasý gerekebilir. Bu yüzden
hacim iºlemini Kutu sýnýfýnýn içinde tanýmlamak daha ideal olacaktýr. ªekil 3.3.1 deki
[Link] programýnda hacim hesaplarýný yapan hacim metotu Kutu sýnýfýnýn içinde
tanýmlanmýºtýr.
Program 3.3 : Kurucu metot örneði, Kutu sýnýfý iki nesneyi kurucu(constructor) metotu
yardýmýyla tanýmlayan ve hacmi hacim() metotuyla hesaplayan [Link]
programý
class Kutu
double en;
double boy;
double yukseklik;
en=e;
boy=b;
yukseklik=y;
double hacim()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
return en*boy*yukseklik;
class kututesti3
double hacim;
String s="";
[Link](null,s,
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.3 [Link]
Bir önceki bölümde metot yazýmý konusunda anlattýklarýmýzýn hepsini buraya ilave edebiliriz.
Bazen bir metotun içinde o metotun ait olduðu sýnýftan yaratýlacak nesneyi veya o nesnenin
bir alt deðiºkenini tanýmlamak gerekir. Nesne daha tanýmlanmadýðindan direk olarak nesne
ismini kullanamayýz. Bunun yerina java this deyimini kullanýr. This deyimi bilhassa sýnýfa ait
deðiºken isimlerinin aynýsý metotda kullanýlmýºsa da iºe yarar. Bu durumda tüm sýnýfa ait
deðiºkenler [Link]ðiºken_ismi komutuyla çaðýrýlabilir. geçen bölümde sýnýf ve metota ait
deðiºkenleri izlerken [Link] ve [Link] isimlerinde iki örnek
problemi incelemiºtik.
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int y;
x=5.5;
y=6;
//tum sinifa at degiskenler this kelimesi ile birlikte kullanilabilirler
[Link]("metot1 in dis degiskenleri this ile ulasim : x = "+this.x+" y = "+this.y,25,25);
[Link]("metot1 in ic degiskenleri : x = "+x+" y = "+y,25,40);
}
Sýnýfa ait her deðiºkeni baºýna this. getirerek kullanabiliriz. Fakat this kullanýmý mutlaka
gerekli deðilse kullanýlmamasý tavsiye edilir.
ºeklinde this deðiºkenini kullanarak da yazýlabilirdi. Burada girdi deðiºkeni ile sýnýf
deðiºkeninin adý ayný verilmiºtir. This sol taraftaki deðiºkenin sýnýf deðiºkeni olduðunu
bilgisayara bildirmektedir.
Yukarda incelediðimiz kutu metodu. Program 3.5 de daha detaylý yazýlmýºtýr. Burada en boy
ve yükseklik deðiºkenleri private olarak tanýmlanmýºtýr. Private olarak tanýmlanan
deðiºkenlere dýºarýdan direk olarak
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Kutu x=new Kutu(3.0,5.0,7.0);
[Link]=8.0;
gibi direk ulaºým mevcut deðildir. Bu deðiºkenlere ulaºým (deðerlerini deðiºtirme veya
çaðýrma) ancak ulaºým metodlarý adýný verdiðimiz metodlar aracýlýðýyla yapýlabilir.
Program 3.5 : Kurucu metot örneði, Kutu sýnýfý iki nesneyi kurucu(constructor) metotu
yardýmýyla tanýmlayan ve hacmi hacim() metotuyla hesaplayan ve diðer metod
tanýmlarýnýn da bulunduðu [Link] programý.
class Kutu
en=e;
boy=b;
yukseklik=y;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
en=e;
boy=b;
yukseklik=y;
{return en;}
{return boy;}
{return yukseklik;}
return en*boy*yukseklik;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"Hacim = "+hacim()+"\n");
class kututesti4
double hacim;
String s="";
s+=[Link]();
s+=[Link]();
[Link](null,s,
[Link](0);
Bu programýn çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.4 [Link]
Ýkinci bir örnek olarak dörtiºlemhesapmakinasi sýnýfýna bakalým. Burada da sýnýf deðiºkenleri
protected olarak tanýmlanmýºtýr. Aºaðýda dort iºlem (toplama cýkarma carpma bolme yapan
dortislemhesapmakinasi sýnýfýný görüyorsunuz.
public dortislemhesapmakinasi(double y)
{
//constructor
sonuc=y;
hafiza=0;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return sonuc;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double isaretdegistir()
{
sonuc=-sonuc;
return sonuc;
}
Bu sýnýfta (class) sýnýf deðiºkeni sonuc deðerlerinin deðiºtirilmesi için gir metotu yazýlmýºtýr.
Bunun sebebi programlarda sýnýfa ait deðiºkenlere dýºarýdan direk ulaºýmýn önlenmesini
saðlamaktýr. Ýyi programlama ºartlarýndan birisi sýnýfýn deðiºkenlerine sadece o sýnýfýn
metotlarý üzerinden ulaºmaktýr. Herkese serbest ulaºým verilmez. Hatta bunu saglamak için
deðiºkenlerin baºýna sadece bu sýnýfa aittir dýºarýdan kullanýlamaz anlamýndaki private
sözcügü getirilebilir . private sözcüðü yerine ancak dýºarda bu sýnýftan yaratýlana yeni
sýnýflar (akraba sýnýflar) kullanabilir, yabancý sýnýflar kullanamaz anlamýndaki protected
sözcüðü de sýk olarak kullanýlýr. Protected sözcügü ayný directorydeki diðer dosyalarý da
(public) gibi kabula eder, fakat baºka direktorylerdeki dosyalar için private olarak davranýr.
ºeklinde ulaºýlamaz. Ayný iºlemi yapmak için aºaðýdaki üç yoldan birini kullanabiliriz.
veya
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
dortislemhesapmakinasi h = new dortislemhesapmakinasi(2.0);
Sýnýf deðiºkenlerinin dýº dünyadan gizlenmesi niçin gereklidir? Bunun en önemli sebebi
program güvenliðinin saðlanmasýdýr. Deðiºkenlere dýºarýdan direk müdahale edilebilirse,
deðerleri de deðiºtirilebilir. Örneðin deðiºkeni bir banka hesabý veya ºirketin özel hesabý
olarak düºünebiliriz. Dýº dünyadan gizlenmemiº bir deðiºkenin deðeri deðiºtirilebilir. Private
veya protected deðiºkenler ise ancak metotlar üzerinden deðiºtirilebilir, burada yeterli
güvenlik önlemlerini almak mümkündür.
Bir sýnýfýn kurulmasýnda o sýnýfla direk olarak iliºkisi olan bir sýnýftan onun tüm metotlarý ve
deðiºkenleri kalýtým (inheritance ) yoluyla yeni kurulan bir sýnýfa aktarýlabilir. Kalýtým için
sýnýf(class) tanýmýnda extends kelimesi kullanýlýr. Eðer bir sýnýftan daha alt sýnýflara kalýtým
yoluyla aktarma yapýlacaksa private deðiºken türü yerini protected deðiºken türüne býrakýr.
Protected private deyiminin aynýdýr. Fakat kalýtýmla deðiºkenlerin aktarýldýðý alt sýnýflara
deðiºkenleri görme izni verir. Private terimi ise kalýtýmla aktarýlan alt sýnýflardan bile o
deðiºkenleri saklar.
Program 3.6 da nokta sýnýfý tanýmlanmýºtýr. Program 3.7 de ise nokta sýnýfýndan kalýtým
yoluyla yaratýlan daire sýnýfýný görüyoruz. Programda da görüleceði gibi daire sýnýfýnýn tanýmý
terimiyle yapýlmýºtýr. Ayrýca daire sýnýfýnýn kurucusu yazýlýrken nokta sýnýfýnýn kurucusu direk
olarak super (a,b); terimiyle çaðýrýlmýºtýr.
"Java dilindeki bir sýnýf sadece bir tane baºka sýnýfýn metot ve deðiºkenlerini kalýtým
yoluyla aktarabilir. "
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class nokta
{
protected double x, y;
public nokta(double a, double b)
{
noktagir(a,b);
}
Program 3.7 : [Link] programý ve daire sýnýfýnýn tanýmý. Daire sýnýfý nokta sýnýfýndan
Kalýtým (inheritance) yoluyla türetilmiºtir.
import nokta;
public daire()
{
//daire kalýtým yaptigi nokta sýnýfýnýn kurucu metotunu
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// super deyimi ile cagirabilir.
super(0,0);
yaricapgir(0);
}
3.7 SINIFLARI BAªKA BIR SINIFTA NESNE OLARAK ÇAÐIRARAK BiR ARAYA
GETiRME (COMPOSITION)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Sýnýftaki deðiºken ve metotlarý kalýtým yoluyla aktarabildiðimiz gibi, sadece üst sýnýfa ait bir
nesne (object) tanýmýný alt sýnýfta tanýmlýyarak ta yapabiliriz. Buna nesne yoluyla aktarým
(ingilizce composition) diyoruz.
Program 3.8 : 1 [Link] programý ve daire sýnýfýnýn tanýmý. Nokta sýnýfý daire1
sýnýfýnda merkez adlý nesne olarak tanýmlanmýstýr.
import nokta;
public daire1()
{
merkez=new nokta(0,0);
yaricapgir(0);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return 3.14159*yaricap*yaricap;
}
daire1 programýnda
Yukarýda nokta ve daire sýnýflarýný tanýmlamýºtýk. Baska bir sýnýftan kalýtým yoluyla türeyen
sýnýfýn(dairenin noktadan kalýtým yoluyla türemesi gibi), üst sýnýfýn adresi(tanýmý) üzerinden
programýn içinde aktarýmý mümkündür.
Program 3.9 : [Link] sýnýfýnda üst sýnýf üzerinden adres referansý kullanýmý
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java dili kullanýlmayan nesneleri silmek için arka planda çalýºan bir sisteme sahiptir. Bu
yüzden C++ gibi dillerde dinamik nesne tanýmlarýnda mutlaka yer almasý gereken nesneyi
silme metotlarý javada o kadar gerekli deðildir. Fakat eðer kendiniz metlaka bir nesneyi acil
olarak silmek isteseniz finalize() isimli bir metotu sýnýfýnýzda tanýmlayýp kullanabilirsiniz.
Örnek olarak aºaðýdaki metotu verebiliriz.
3.10 ALIªTIRMALAR
Program 3.10 [Link], bu program nokta sýnýfýndan (Program 3.5) kalýtým yoluyla
türüyen daire sýnýfýnýn(Program 3.6) kullanýlmasýný göstermektedir.
import [Link].*;
import daire;
class dairetest
[Link]("nokta : "+[Link]() );
[Link]("daire : "+[Link]() );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("dairenin alan� : "+[Link]());
[Link](1.5,2.5);
[Link](1.0);
nokta : [1.0,2.0]
import daire;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class dairetest_2000
String s="";
s+="nokta : "+[Link]()+"\n";
s+="daire : "+[Link]()+"\n";
[Link](1.5,2.5);
[Link](1.0);
[Link](null,s,
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.6 daire testi 2000 JoptionPage çýktýsý
5. Nokta sýnýfýný kullanarak dogru sýnýfýný yarat. Doðru iki noktayla tanýmlanýr. Dogru sýnýfýnýn
kurucu metotunu, boyunu hesaplayan boy metotunu, uç noktalarýný String deðiºkeni olarak
tanýmlayan toString metotunu ve gerekli olan diðer metotlarý tanýmla. Konsol programý olarak
dogrutesti sýnýfý oluºturarak bu sýnýfýn içinde cokdogrubirdogru isimli bir nesne oluºtur be
bu nesnenin baslangýç ve bitiº noktalarýyla boyunu yazdýr. Girdi deðerlerini program içinde
sabit olarak tanýmla.
import nokta;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString()
{
return "("+[Link]()+","+[Link]()+")";
}
import [Link].*;
import nokta;
([1.0,1.0],[2.0,2.0])
6. Nokta sýnýfýný kullanarak dikdortgen sýnýfýný yarat. Dikdörtgen iki noktayla tanýmlanýr.
Dikdortgen sýnýfýnýn kurucu metotunu, çevresini hesaplayan çevre metotunu, Alanýný
hesaplayan alan metotonu, dikdortgeni tanýmlayan iki noktayý String deðiºkeni olarak
tanýmlayan toString metotunu ve gerekli olan diðer metotlarý tanýmla. Applet programý olarak
dikdortgentesti sýnýfý oluºturarak bu sýnýfýn içinde cokguzelbirdikdortgen isimli bir nesne
oluºtur be bu nesnenin baslangýç ve bitiº noktalarýyla boyunu yazdýr. Girdi deðerlerini
program içinde sabit olarak tanýmla.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link];
import nokta;
class dikDortgen
{
protected nokta n1,n2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
[Link]
7. dogrutesti1 sýnýfýný yaz. Bu sýnýfta dogruyu tanýmlýyan noktalarý (toplam iki nokta) swing
JoptionPane konsol programýna ekrandan deðiºken olarak gir. Dogrunun iki noktasýný ve
doðru boyunu ekrana çýktý olarak yazdýr.
9. Hesapmakinesi sýnýfýný yarat. Bu sýnýf iki gerçek deðiºkeni sýnýf deðiºkeni olarak
tanýmlasýn. Topla,cýkar,carp ve bol metotlarýný yaz ve bu iºlemleri metotlarýn içinde tanýmla.
bir test programýný yaz ve bu sýnýf hesapmakinesi sýnýfýný kullanarak dýºarýdan girilen iki
gercek sayýnýn dört iºlemini hesapla. dortislemhesapmakinasi programý Program 3.5 de
verilmiºtir.
import dortislemhesapmakinasi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H4AL1 extends Applet implements ActionListener
TextField sonucgirdisi;
TextField kutugirdisi;
Button Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
double sayi;
dortislemhesapmakinasi D;
D=new dortislemhesapmakinasi();
sonucgirdisi=new TextField(30);
[Link](false);
add(sonucgirdisi);
kutugirdisi=new TextField(30);
Gir=new Button("gir");
Arti=new Button("+");
Eksi=new Button("-");
Carpi=new Button("*");
Bolu=new Button("/");
M=new Button("M");
MR=new Button("MR");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
MArti=new Button("M+");
MEksi=new Button("M-");
Isaret=new Button("+/-");
C=new Button("C");
add(Gir);
add(Arti);
add(Eksi);
add(Carpi);
add(Bolu);
add(M);
add(MR);
add(MArti);
add(MEksi);
add(Isaret);
add(C);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
[Link]([Link]());
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
[Link]("");
[Link]
10. Hesapmakinesi sýnýfýný için. bir JApplet test programý yaz ve bu sýnýf hesapmakinesi
sýnýfýný kullanarak dýºarýdan girilen iki gercek sayýnýn dört iºlemini hesapla .
dortislemhesapmakinasi programý yukarýda verilmiºtir.
import dortislemhesapmakinasi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Dört iºlem hesap makinasý
JTextField sonucgirdisi;
JTextField kutugirdisi;
JButton Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
double sayi;
dortislemhesapmakinasi D;
D=new dortislemhesapmakinasi();
Container c=getContentPane();
[Link](new FlowLayout());
sonucgirdisi=new JTextField(30);
[Link](false);
[Link](sonucgirdisi);
kutugirdisi=new JTextField(30);
Gir=new JButton("gir");
Arti=new JButton("+");
Eksi=new JButton("-");
Carpi=new JButton("*");
Bolu=new JButton("/");
M=new JButton("M");
MR=new JButton("MR");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
MArti=new JButton("M+");
MEksi=new JButton("M-");
Isaret=new JButton("+/-");
C=new JButton("C");
[Link](Gir);
[Link](Arti);
[Link](Eksi);
[Link](Carpi);
[Link](Bolu);
[Link](M);
[Link](MR);
[Link](MArti);
[Link](MEksi);
[Link](Isaret);
[Link](C);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
[Link]([Link]());
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
[Link]("");
10. Hesapmakinesi sýnýfýný için. bir JFrame test programý yaz ve bu sýnýf hesapmakinesi
sýnýfýný kullanarak dýºarýdan girilen iki gercek sayýnýn dört iºlemini hesapla.
dortislemhesapmakinasi programý yukarýda verilmiºtir.
import dortislemhesapmakinasi;
import BasicWindowMonitor;
JTextField sonucgirdisi;
JTextField kutugirdisi;
JButton Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double sayi;
dortislemhesapmakinasi D;
public H4AL1SWF_2000()
D=new dortislemhesapmakinasi();
Container c=getContentPane();
[Link](new FlowLayout());
sonucgirdisi=new JTextField(30);
[Link](false);
[Link](sonucgirdisi);
kutugirdisi=new JTextField(30);
Gir=new JButton("gir");
Arti=new JButton("+");
Eksi=new JButton("-");
Carpi=new JButton("*");
Bolu=new JButton("/");
M=new JButton("M");
MR=new JButton("MR");
MArti=new JButton("M+");
MEksi=new JButton("M-");
Isaret=new JButton("+/-");
C=new JButton("C");
[Link](Gir);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](Arti);
[Link](Eksi);
[Link](Carpi);
[Link](Bolu);
[Link](M);
[Link](MR);
[Link](MArti);
[Link](MEksi);
[Link](Isaret);
[Link](C);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
[Link]([Link]());
[Link]([Link]());
else
[Link]("");
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args)
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
11. Bayaðý kesirler sanýrým ilk okulda sizleri epey zorlamýºtýr. Daha fazla aklýmýzý
karýºtýrmalarýný önlemek amacýyla bayagikesir sýnýfýný tanýmlayalým. Bu sýnýf bayaðý
kesirlerin dört iºlemini ve sadeleºtirilmelerini yapabilme kapasitesinde olsun. Ayný zamanda
bayaðý kesirleri yazdýran toString metotunu da tanýmlayalým. Bu metot [2/3] veya 3[5/4]
ºeklinde bayaðý kesirleri yazdýrabilsin.
Bayaðý kesirleri sadeleºtirirken en büyük ortak bölen hesabý gerekebilir. Bu amaçla asaðýdaki
metot verilmiºtir.
not : sadeleºtirme iºlemi pay ve paydayý en büyük ortak bölene bölerek yapýlýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 3.18 : [Link],bayagikesir sýnýfý tanýmý
//===========================================
// bayagikesir sinifi tanimi
// Dr. Turhan Coban
//===========================================
import [Link].*;
// sinif bayagikesir
// bu sinif bayagikesir sayilarin matematik
// islemlerini tanimlar
//
class bayagikesir {
// sinif degiskenleri
int pay;
int payda;
// kurucu metotlar
public bayagikesir()
{
pay=0;
payda=1;
}
public bayagikesir(bayagikesir c )
{
pay=[Link]();
payda=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
// giriº- çýkýº metodlarý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int Payda()
{
return payda;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double toDouble()
{
//bayagikesir sayinin gercek sayi esidi
return ((double)pay/(double)payda);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sadelestir();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static bayagikesir topla(bayagikesir sol, int sag) throws bayagikesirException
{
// bir bayagikesir ve bir Pay say�n�n toplam�n� return deyimiyle bayagikesir olarak
// aktarýr
int r1=[Link]() + sag*[Link]();
int i1=[Link]();
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
}
//===================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return sonuc;
}
//===================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bayagikesir sonuc;
sonuc=new bayagikesir((int)([Link]()*[Link]()),(int)([Link]()*[Link]()));
[Link]();
return sonuc;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean esit_degildir(bayagikesir sol,bayagikesir sag)
{
// not esittir comparison of two bayagikesir numbers
return [Link]() != [Link]();
}
//--------------------------------------------------------------------------------------------
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link]; // java applet sinifini cagir
import [Link].*; // java pencere kullanma sinifini cagir
import [Link].*; // java pencereyi dinleme sinifini cagir
import bayagikesir;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
showStatus("Hesaplandi");
repaint();//pencereyi yeniden paint metotuna gore ciz
}
//=====================================================
// paint (boya=pencereye ciz metotu)
public void paint(Graphics g)
{
[Link]("ilk sayi : "+[Link](),25,80);
[Link]("ikinci sayi : "+[Link](),25,95);
try{
[Link]("iki sayinin toplami : "+[Link]([Link](k1,k2)),25,110);
[Link]("iki sayinin farki : "+[Link]([Link](k1,k2)),25,125);
[Link]("iki sayinin carpimi : "+[Link]([Link](k1,k2)),25,140 );
[Link]("iki sayinin bolumu : "+[Link]([Link](k1,k2)),25,155 );
}
catch (bayagikesirException e)
{
showStatus([Link]());
}
}
}
[Link]
Program 3.20 :Bayagýkesir sýnýfý Java swing applet test programý bkTesti_2000.java
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*; // java pencere kullanma sinifini cagir
import bayagikesir;
//
//=====================================================
// sinif degiskenleri
//=====================================================
k1=new bayagikesir(1,2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
k2=new bayagikesir(2,4);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](kutubasligi1);
kutugirdisi1=new JTextField(5);
[Link](this);
[Link](kutugirdisi1);
kutugirdisi2=new JTextField(5);
[Link](this);
[Link](kutugirdisi2);
[Link](kutubasligi2);
kutugirdisi3=new JTextField(5);
[Link](this);
[Link](kutugirdisi3);
kutugirdisi4=new JTextField(5);
[Link](this);
[Link](kutugirdisi4);
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Integer sayi1,sayi2,sayi3,sayi4;
sayi1=new Integer([Link]() );
sayi2=new Integer([Link]() );
sayi3=new Integer([Link]() );
sayi4=new Integer([Link]() );
showStatus("Hesaplaniyor....");
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
showStatus("Hesaplandi");
String s="";
[Link](s);
//=====================================================
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.10 bkTesti_2000 swing JApplet çýktýsý
Program 3.21 :Bayagýkesir sýnýfý test programý bkTestiSWF_2000.java swing Frame test
programý
import bayagikesir;
import BasicWindowMonitor;
//
//=====================================================
// sinif degiskenleri
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JTextField kutugirdisi3; // JTextfield sinifi degiskeni (nesnesi) kutugirdisi2
//=====================================================
public bkTestiSWF_2000()
k1=new bayagikesir(1,2);
k2=new bayagikesir(2,4);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](kutubasligi1);
kutugirdisi1=new JTextField(5);
[Link](this);
[Link](kutugirdisi1);
kutugirdisi2=new JTextField(5);
[Link](this);
[Link](kutugirdisi2);
[Link](kutubasligi2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutugirdisi3=new JTextField(5);
[Link](this);
[Link](kutugirdisi3);
kutugirdisi4=new JTextField(5);
[Link](this);
[Link](kutugirdisi4);
cikti=new JTextArea(toString());
[Link]([Link]());
[Link](cikti);
//=====================================================
String s="";
return s;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Integer sayi1,sayi2,sayi3,sayi4;
sayi1=new Integer([Link]() );
sayi2=new Integer([Link]() );
sayi3=new Integer([Link]() );
sayi4=new Integer([Link]() );
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
[Link](toString());
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.11 bkTestiSWF_2000 swing JFrame çýktýsý
Kompleks sýnýfý örnek olarak burada verilmiºtir. Problem 11 ve 12 ile ilgili önemli bir nokta
bunlarýn gerçek hayatta kullanýlabilecek sýnýflar olmalarýdýr. Sadece bir eksersiz olarak
kullanýlmak amacýyla deðil, bu sýnýflara ihtiyacýmýz olduðunda bize hizmet vermek amacýyla
ve tüm detay metodlarý düºünülerek yazýlmýºlardýr. Bu sýnýflar her zaman kütüphanenizde
kalabilecek ve gerektiðinde direk olarak gerçek programlarýnýzda kullanýlabilecek özelliklerde
sýnýflardýr:
/===========================================
// kompleks sinifi tanimi
// Dr. Turhan Coban
//===========================================
import [Link].*;
// sinif kompleks
// bu sýnýf kompleks sayýlarýn matematik
// iºlemlerini tanýmlar
//
class kompleks {
// sýnýf degiskenleri
double ger; // kompleks sayýnýn gerçek kýsmý
double imaj; // kompleks sayýnýn imajineri kýsmý
// kurucu metotlar
public kompleks()
{
ger=0;
imaj=0;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ger=numer;
imaj=0;
}
public kompleks(kompleks c )
{
ger=[Link]();
imaj=[Link]();
}
// giriº - çýkýº metotlarý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ger=nr;
imaj=ni;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ger = ger - sag;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static kompleks topla(double sol, kompleks sag)
{
// bir kompleks ve bir gercek say�n�n toplam�n� return deyimiyle kompleks olarak
// aktar�r
double r1=([Link]() + sol);
double i1=[Link]();
kompleks sonuc;
sonuc=new kompleks(r1,i1);
return sonuc;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return sonuc;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
b=b+gercek()+" ";
}
return b;
}
};
//kompleks sinifinin taniminin sonu
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
add(kutubasligi2);
kutugirdisi3=new TextField(5);
[Link](this);
add(kutugirdisi3);
kutugirdisi4=new TextField(5);
[Link](this);
add(kutugirdisi4);
}
//=====================================================
// girdi alanindaki olan olaylari dinleme metotu
// Her yeni rakam girildiginde bu metot cagirilir
public void actionPerformed(ActionEvent e)
{
Double sayi1=new Double([Link]() );
Double sayi2=new Double([Link]() );
Double sayi3=new Double([Link]() );
Double sayi4=new Double([Link]() );
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
repaint();//pencereyi yeniden paint metotuna gore ciz
}
//=====================================================
// paint (boya=pencereye ciz metotu)
public void paint(Graphics g)
{
[Link]("ilk sayi : "+[Link](),25,80);
[Link]("ikinci sayi : "+[Link](),25,95);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// pencere ilk basladiginda
// degiskenler buradaki degerleri alirlar
public void init()
{
k1=new kompleks();
k2=new kompleks();
kutubasligi1=new Label("Birinci kompleks sayiyi giriniz : ");
add(kutubasligi1);
kutugirdisi1=new TextField(5);
[Link](this);
add(kutugirdisi1);
kutugirdisi2=new TextField(5);
[Link](this);
add(kutugirdisi2);
kutubasligi2=new Label("Ikinci kompleks sayiyi giriniz : ");
add(kutubasligi2);
kutugirdisi3=new TextField(5);
[Link](this);
add(kutugirdisi3);
kutugirdisi4=new TextField(5);
[Link](this);
add(kutugirdisi4);
}
//=====================================================
// girdi alanindaki olan olaylari dinleme metotu
// Her yeni rakam girildiginde bu metot cagirilir
public void actionPerformed(ActionEvent e)
{
Double sayi1=new Double([Link]() );
Double sayi2=new Double([Link]() );
Double sayi3=new Double([Link]() );
Double sayi4=new Double([Link]() );
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
repaint();//pencereyi yeniden paint metotuna gore ciz
}
//=====================================================
// paint (boya=pencereye ciz metotu)
public void paint(Graphics g)
{
[Link]("ilk sayi : "+[Link](),25,80);
[Link]("ikinci sayi : "+[Link](),25,95);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.12 Kompleks sýnýfý testi [Link] applet çýktýsý
Program 3.23 : kompleks sýnýfýný test eden java swing applet programý
kompleksTesti_2000.java
import kompleks;
//
//=====================================================
// sinif degiskenleri
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JTextField kutugirdisi2; // JTextfield sinifi degiskeni (nesnesi) kutugirdisi2
//=====================================================
k1=new kompleks(1,2);
k2=new kompleks(2,4);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](kutubasligi1);
kutugirdisi1=new JTextField(5);
[Link](this);
[Link](kutugirdisi1);
kutugirdisi2=new JTextField(5);
[Link](this);
[Link](kutugirdisi2);
[Link](kutubasligi2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutugirdisi3=new JTextField(5);
[Link](this);
[Link](kutugirdisi3);
kutugirdisi4=new JTextField(5);
[Link](this);
[Link](kutugirdisi4);
[Link]([Link]());
[Link](cikti);
String s="";
return s;
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e)
Double sayi1,sayi2,sayi3,sayi4;
sayi1=new Double([Link]() );
sayi2=new Double([Link]() );
sayi3=new Double([Link]() );
sayi4=new Double([Link]() );
showStatus("Hesaplanýyor....");
[Link]([Link](),[Link]());
[Link]([Link](),[Link]());
showStatus("Hesaplandý");
[Link](toString());
//=====================================================
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 3.24 : kompleks sýnýfýný test eden kompleksTestiSWF_2000.java JFrame
programý
import kompleks;
import BasicWindowMonitor;
//
//=====================================================
// sinif degiskenleri
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// degiskenler buradaki degerleri alirlar
public kompleksTestiSWF_2000()
k1=new kompleks(1,2);
k2=new kompleks(2,4);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](kutubasligi1);
kutugirdisi1=new JTextField(5);
[Link](this);
[Link](kutugirdisi1);
kutugirdisi2=new JTextField(5);
[Link](this);
[Link](kutugirdisi2);
[Link](kutubasligi2);
kutugirdisi3=new JTextField(5);
[Link](this);
[Link](kutugirdisi3);
kutugirdisi4=new JTextField(5);
[Link](this);
[Link](kutugirdisi4);
cikti=new JTextArea(toString());
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](cikti);
//=====================================================
String s="";
return s;
Double sayi1,sayi2,sayi3,sayi4;
sayi1=new Double([Link]() );
sayi2=new Double([Link]() );
sayi3=new Double([Link]() );
sayi4=new Double([Link]() );
[Link]([Link](),[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link](),[Link]());
[Link](toString());
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import dortislemhesapmakinasi;
double arasonuc;
double arasonuc2;
public bilimselhesapmakinasi1(double y)
//constructor
super(y);
arasonuc=0;
arasonuc2=0;
public bilimselhesapmakinasi1()
super();
arasonuc=0;
arasonuc2=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double topla(double x)
if(arasonuc2==0) {sonuc+=x;}
else {sonuc+=[Link](arasonuc2,x);arasonuc2=0;}
return sonuc;
if(arasonuc2==0) {sonuc-=x;}
else {sonuc-=[Link](arasonuc2,x);arasonuc2=0;}
return sonuc;
if(arasonuc2==0) {sonuc*=x;}
else {sonuc*=[Link](arasonuc2,x);arasonuc2=0;}
return sonuc;
if(arasonuc2==0) {sonuc/=x;}
else {sonuc/=[Link](arasonuc2,x);arasonuc2=0;}
return sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
if(arasonuc2==0) {sonuc=x;}
else {sonuc=[Link](arasonuc2,x);arasonuc2=0;}
arasonuc=sonuc;
return arasonuc;
arasonuc=x;
arasonuc2=x;
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
arasonuc=x*x;
return arasonuc;
arasonuc=1.0/x;
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double tan(double x)
arasonuc=[Link](x);
return arasonuc;
arasonuc=180.0/[Link]*x;
return arasonuc;
arasonuc=[Link]/180.0*x;
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double asin(double x)
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
arasonuc=[Link];
return arasonuc;
arasonuc=[Link](x)/[Link](10.0);
return arasonuc;
arasonuc=-x;
return arasonuc;
return ""+arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 3.26 : [Link] programý
import dortislemhesapmakinasi;
dortislemhesapmakinasi DH;
double arasonuc;
double arasonuc2;
public bilimselhesapmakinasi2(double y)
//constructor
DH=new dortislemhesapmakinasi(y);
arasonuc=0;
arasonuc2=0;
public bilimselhesapmakinasi2()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
DH=new dortislemhesapmakinasi();
arasonuc=0;
arasonuc2=0;
if(arasonuc2==0) {[Link]([Link]()+x);}
else {[Link]([Link]()+[Link](arasonuc2,x));arasonuc2=0;}
return [Link]();
if(arasonuc2==0) {[Link]([Link]()-x);}
else {[Link]([Link]()-[Link](arasonuc2,x));arasonuc2=0;}
return [Link]();
if(arasonuc2==0) {[Link]([Link]()*x);}
else {[Link]([Link]()*[Link](arasonuc2,x));arasonuc2=0;}
return [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double bol(double x)
if(arasonuc2==0) {[Link]([Link]()/x);}
else {[Link]([Link]()/[Link](arasonuc2,x));arasonuc2=0;}
return [Link]();
if(arasonuc2==0) {[Link](x);}
else {[Link]([Link](arasonuc2,x));arasonuc2=0;}
return [Link]();
arasonuc=[Link]();
return arasonuc;
arasonuc=x;
arasonuc2=x;
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
arasonuc=[Link](x);
return arasonuc;
arasonuc=x*x;
return arasonuc;
arasonuc=1.0/x;
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double sin(double x)
{birde acele
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=180.0/[Link]*x;
return arasonuc;
arasonuc=[Link]/180.0*x;
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double acos(double x)
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
arasonuc=[Link](x);
return arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double pi()
arasonuc=[Link];
return arasonuc;
arasonuc=[Link](x)/[Link](10.0);
return arasonuc;
arasonuc=-x;
return arasonuc;
return ""+arasonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sýnýfýný kullanarak yapan [Link] programýný yazýnýz. [Link] ve
[Link] programlarýnýn temel farklarýný (miras-inheritance ve nesne-
object yoluyla aktarma-composition) izah ediniz
import bilimselhesapmakinasi1;
TextField sonucgirdisi;
TextField kutugirdisi;
Button Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
Button Pow,Cos,Sin,Tan,RtoD,DtoR,Acos,Asin,Atan,Exp,Kok,Kare,birBoluX;
Button Ln,Log10,Oku,PI;
double sayi;
bilimselhesapmakinasi1 D;
D=new bilimselhesapmakinasi1();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sonucgirdisi=new TextField(25);
[Link](false);
add(sonucgirdisi);
kutugirdisi=new TextField(25);
M=new Button("M");
MR=new Button("MR");
MArti=new Button("M+");
MEksi=new Button("M-");
Isaret=new Button("+/-");
C=new Button("C");
Pow=new Button("x^y");
Cos=new Button("cos");
Sin=new Button("sin");
Tan=new Button("tan");
RtoD=new Button("R->D");
DtoR=new Button("D->R");
Acos=new Button("acos");
Asin=new Button("asin");
Atan=new Button("atan");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Exp=new Button("exp");
Ln=new Button("ln");
Log10=new Button("log10");
Kok=new Button("x^0.5");
Kare=new Button("x^2");
PI=new Button("pi");
add(Gir);
add(Oku);
add(Arti);
add(Eksi);
add(Carpi);
add(Bolu);
add(M);
add(MR);
add(MArti);
add(MEksi);
add(Isaret);
add(C);
add(Pow);
add(Cos);
add(Sin);
add(Tan);
add(DtoR);
add(Acos);
add(Asin);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
add(Atan);
add(RtoD);
add(birBoluX);
add(Exp);
add(Ln);
add(Log10);
add(Kok);
add(Kare);
add(PI);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
if([Link]()==Oku) [Link]();
if([Link]()==PI) [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if([Link]()==Arti) [Link](sayi);
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]()==MR || [Link]()==M ||
[Link]()==MArti||[Link]()==MEksi)
[Link]([Link]());
else if([Link]()==Cos ||
[Link]()==Sin||[Link]()==Tan||[Link]()==RtoD ||
[Link]()==Asin||[Link]()==Atan||[Link]()==Exp ||
[Link]()==Log10||[Link]()==Isaret ||[Link]()==Kok ||
[Link]()==PI)
[Link]([Link]());
else
[Link]("");
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 3.15 [Link] bilimsel hesap makinasý simulasyonu
import bilimselhesapmakinasi1;
TextField sonucgirdisi;
TextField kutugirdisi;
Button Gir,Arti,Eksi,Carpi,Bolu,M,MR,Marti,MEksi,Isaret,C;
Button Pow,Cos,Sin,Tan,RtoD,DtoR,Acos,Asin,Atan,Exp,Kok,Kare,birBoluX;
Button Ln,Log10,Oku,PI;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double sayi;
bilimselhesapmakinasi1 D;
D=new bilimselhesapmakinasi1();
sonucgirdisi=new TextField(40);
[Link](false);
add(sonucgirdisi);
kutugirdisi=new TextField(40);
M=new Button("M");
MR=new Button("MR");
Marti=new Button("M+");
Meksi=new Button("M-");
Isaret=new Button("+/-");
C=new Button("C");
Pow=new Button("x^y");
Cos=new Button("cos");
Sin=new Button("sin");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Tan=new Button("tan");
RtoD=new Button("R->D");
DtoR=new Button("D->R");
Acos=new Button("acos");
Asin=new Button("asin");
Atan=new Button("atan");
Exp=new Button("exp");
Ln=new Button("ln");
Log10=new Button("log10");
Kok=new Button("x^0.5");
Kare=new Button("x^2");
PI=new Button("pi");
[Link](new GridLayout(5,8));
[Link](Gir);
[Link](Oku);
[Link](Arti);
[Link](Eksi);
[Link](Carpi);
[Link](Bolu);
[Link](M);
[Link](MR);
[Link](MArti);
[Link](MEksi);
[Link](Isaret);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](C);
[Link](Pow);
[Link](Cos);
[Link](Sin);
[Link](Tan);
[Link](DtoR);
[Link](RtoD);
[Link](birBoluX);
[Link](Acos);
[Link](Asin);
[Link](Atan);
[Link](Kok);
[Link](Kare);
[Link](Exp);
[Link](Ln);
[Link](Log10);
[Link](PI);
add(m);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
String ss=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
if([Link]()==Oku) [Link]();
if([Link]()==PI) [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if([Link]()==Asin) [Link](sayi);
[Link]([Link]());
if([Link]()==MR || [Link]()==M ||
[Link]()==MArti||[Link]()==MEksi)
[Link]([Link]());
else if([Link]()==Cos ||
[Link]()==Sin||[Link]()==Tan||[Link]()==RtoD ||
[Link]()==Asin||[Link]()==Atan||[Link]()==Exp ||
[Link]()==Log10||[Link]()==Isaret ||[Link]()==Kok ||
[Link]()==PI)
[Link]([Link]());
else
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("");
[Link]
import [Link].*;
import [Link].*;
import bilimselhesapmakinasi1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// bilimsel hesap makinasi
JTextField sonucgirdisi;
JTextField kutugirdisi;
JButton Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
JButton Pow,Cos,Sin,Tan,RtoD,DtoR,Acos,Asin,Atan,Exp,Kok,Kare,birBoluX;
JButton Ln,Log10,Oku,PI;
double sayi;
bilimselhesapmakinasi1 D;
D=new bilimselhesapmakinasi1();
Container c=getContentPane();
[Link](new BorderLayout());
sonucgirdisi=new JTextField();
[Link](false);
[Link]([Link]);
[Link](new Font("SansSerif",[Link],14));
[Link](new GridLayout(2,1));
kutugirdisi=new JTextField(40);
[Link](new Font("SansSerif",[Link],14));
[Link](sonucgirdisi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kutugirdisi);
[Link](e,[Link]);
M=new JButton("M");
MR=new JButton("MR");
MArti=new JButton("M+");
MEksi=new JButton("M-");
Isaret=new JButton("+/-");
C=new JButton("C");
Pow=new JButton("x^y");
Cos=new JButton("cos");
Sin=new JButton("sin");
Tan=new JButton("tan");
RtoD=new JButton("R->D");
DtoR=new JButton("D->R");
Acos=new JButton("acos");
Asin=new JButton("asin");
Atan=new JButton("atan");
Exp=new JButton("exp");
Ln=new JButton("ln");
Log10=new JButton("log10");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Kok=new JButton("x^0.5");
Kare=new JButton("x^2");
PI=new JButton("pi");
[Link](new GridLayout(5,8));
[Link](Gir);
[Link](Oku);
[Link](Arti);
[Link](Eksi);
[Link](Carpi);
[Link](Bolu);
[Link](M);
[Link](MR);
[Link](MArti);
[Link](MEksi);
[Link](Isaret);
[Link](C);
[Link](Pow);
[Link](Cos);
[Link](Sin);
[Link](Tan);
[Link](DtoR);
[Link](RtoD);
[Link](birBoluX);
[Link](Acos);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](Asin);
[Link](Atan);
[Link](Kok);
[Link](Kare);
[Link](Exp);
[Link](Ln);
[Link](Log10);
[Link](PI);
[Link](m,[Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
if([Link]()==Oku) [Link]();
if([Link]()==PI) [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if([Link]()==Arti) [Link](sayi);
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]()==MR || [Link]()==M ||
[Link]()==MArti||[Link]()==MEksi)
[Link]([Link]());
else if([Link]()==Cos ||
[Link]()==Sin||[Link]()==Tan||[Link]()==RtoD ||
[Link]()==Asin||[Link]()==Atan||[Link]()==Exp ||
[Link]()==Log10||[Link]()==Isaret ||[Link]()==Kok ||
[Link]()==PI)
[Link]([Link]());
else
[Link]("");
[Link](new WindowAdapter() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void windowClosing(WindowEvent e) {[Link](0);}
});
[Link]().add("Center", applet);
[Link]();
[Link]();
[Link](new Dimension(450,220));
[Link]();
[Link]
14. H4O2
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import vektor3D;
import Text;
class H4O2
double xi,xj,xk;
double Fi,Fj,Fk;
nokta3D n1;
vektor3D v1;
vektor3D v2;
xi=[Link]();
xj=[Link]();
xk=[Link]();
n1=new nokta3D(xi,xj,xk);
Fi=[Link]();
Fj=[Link]();
Fk=[Link]();
v1=new vektor3D(n1,Fi,Fj,Fk);
Fi=[Link]();
Fj=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Fk=[Link]();
v2=new vektor3D(xi,xj,xk,Fi,Fj,Fk);
[Link](v2);
[Link]("toplam = \n"+[Link]());
public nokta3D()
xi=0;
xj=0;
xk=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public nokta3D(double yi,double yj,double yk)
xi=yi;
xj=yj;
xk=yk;
public nokta3D(nokta3D y)
xi=[Link];
xj=[Link];
xk=[Link];
xi=yi;
xj=yj;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
xk=yk;
xi=yi;
xj=yj;
xk=yk;
xi=[Link];
xj=[Link];
xk=[Link];
return xi;
return xj;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return xk;
xi+=[Link];
xj+=[Link];
xk+=[Link];
[Link](y2);
return x;
xi-=[Link];
xj-=[Link];
xk-=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link](y2);
return x;
return this;
return [Link](xi*xi+xj*xj+xk*xk);
return xi/R();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double cosaj()
return xj/R();
return xk/R();
boolean b=((xi==[Link])&&(xj==[Link])&&(xk==[Link]));
return b;
return (this.R()>v.R());
return (this.R()<v.R());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String s="";
if(xi!=0)
s+=xi+" i ";
if(xj>0 )
else if(xj<0)
if(xk>0 )
else if(xk<0)
return s;
import nokta3D;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double xi,xj,xk;
public dogru3D()
P0=new nokta3D();
P1=new nokta3D();
xi=0;
xj=0;
xk=0;
P0=new nokta3D(yi0,yj0,yk0);
P1=new nokta3D(yi1,yj1,yk1);
[Link](P1);
xi=[Link]();
xj=[Link]();
xk=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
P0=new nokta3D(y0);
P1=new nokta3D(y1);
[Link](P1);
xi=[Link]();
xj=[Link]();
xk=[Link]();
[Link](yi,yj,yk);
[Link](y);
[Link](yi,yj,yk);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void P1Gir(nokta3D y)
[Link](y);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double xiOku()
return xi;
return xj;
return xk;
return [Link](xi*xi+xj*xj+xk*xk);;
return xi/R();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return xj/R();
return xk/R();
boolean b=((xi==[Link])&&(xj==[Link])&&(xk==[Link]));
return b;
return (this.R()>v.R());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean kucuktur(dogru3D v)
return (this.R()<v.R());
s=s+"P1 = "+[Link]()+"\n";
return s;
import dogru3D;
import nokta3D;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public vektor3D()
super();
Fi=0;
Fj=0;
Fk=0;
super(yi0,yj0,yk0);
Fi=Fi0;
Fj=Fj0;
Fk=Fk0;
Fi=F*[Link]();
Fj=F*[Link]();
Fk=F*[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public vektor3D(double Fi0,double Fj0,double Fk0)
super();
Fi=Fi0;
Fj=Fj0;
Fk=Fk0;
public vektor3D(vektor3D y)
xi=[Link];
xj=[Link];
xk=[Link];
Fi=[Link];
Fj=[Link];
Fk=[Link];
super(y0);
Fi=Fi0;
Fj=Fj0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Fk=Fk0;
Fi=F*[Link]();
Fj=F*[Link]();
Fk=F*[Link]();
xi=yi;
xj=yj;
xk=yk;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void FGir(double Fi0,double Fj0,double Fk0)
Fi=Fi0;
Fj=Fj0;
Fk=Fk0;
xi=[Link];
xj=[Link];
xk=[Link];
Fi=[Link];
Fj=[Link];
Fk=[Link];
return Fi;
return Fj;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double FkOku()
return Fk;
return this;
return [Link](Fi*Fi+Fj*Fj+Fk*Fk);
/*
return [Link](xi*xi+xj*xj+xk*xk);
*/
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double cosFi()
return Fi/F();
return Fj/F();
return Fk/F();
if(noktaEsittir(v))
Fi+=[Link];
Fj+=[Link];
Fk+=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
vektor3D x;
x=new vektor3D(v1);
[Link](v2);
return x;
if(noktaEsittir(v))
Fi-=[Link];
Fj-=[Link];
Fk-=[Link];
[Link](v2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return x;
if(noktaEsittir(v))
double Fi1=Fi;
double Fj1=Fj;
double Fk1=Fk;
Fi=(Fj1*[Link]-Fk1*[Link]);
Fj=-(Fi1*[Link]-Fk1*[Link]);
Fk=(Fi1*[Link]-Fj1*[Link]);
double s=0.0;
if(noktaEsittir(v))
s=Fi*[Link]+Fj*[Link]+Fk*[Link];
return s;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean esittir(vektor3D v)
boolean b=((xi==[Link])&&(xj==[Link])&&(xk==[Link]));
return b;
boolean b=((xi==[Link])&&(xj==[Link])&&(xk==[Link]));
return b;
return (this.F()>v.F());
return (this.F()<v.F());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString()
return s;
14. H4OD3_2000
import vektor3D;
import vektorpanel;
import BasicWindowMonitor;
//
//=====================================================
// sinif degiskenleri
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JTextArea cikti; // JTextArea sýnýfý deðiºkeni (nesnesi) cikti
//=====================================================
public H4OD3_2000()
k[0]=new vektor3D(1.0,1.0,1.0,2.0,2.0,2.0);
k[1]=new vektor3D(1.0,1.0,1.0,3.0,3.0,3.0);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](new GridLayout(2,1));
[Link](p[0],[Link]);
[Link](p[1],[Link]);
[Link](p1);
cikti=new JTextArea(toString());
[Link]([Link]());
[Link](cikti);
p[1].F[2].addActionListener(this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//=====================================================
String s="";
for(int i=0;i<2;i++)
s+="Vektör "+(i+1)+"\n";
s+=k[i].toString();
k[0].topla(k[1]);
s+=k[0].toString();
return s;
for(int i=0;i<2;i++)
k[i].vektorGir([Link](p[i].x[0].getText()),
[Link](p[i].x[1].getText()),
[Link](p[i].x[2].getText()),
[Link](p[i].F[0].getText()),
[Link](p[i].F[1].getText()),
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](p[i].F[2].getText()));
[Link](toString());
//=====================================================
[Link](new BasicWindowMonitor());
[Link](300,200);
[Link](true);
[Link]
ªekil 3.18 vektor3D sýnýfýný test eden H4OD3_2000 java frame programý
Program 3.35 : vektor3D sýnýfýný test eden swing JFrame, H4OD3_2000 .java
programýnda kullanýlan vektorpanel alt sýnýfý ([Link] programý)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
public vektorpanel()
[Link](new GridLayout(2,4));
xisim=new JLabel("xi,xj,xk");
x[0]=new JTextField(5);
x[1]=new JTextField(5);
x[2]=new JTextField(5);
Fisim=new JLabel("Fi,Fj,Fk");
F[0]=new JTextField(5);
F[1]=new JTextField(5);
F[2]=new JTextField(5);
[Link](xisim);
for(int i=0;i<3;i++)
[Link](x[i]);
[Link](Fisim);
for(int i=0;i<3;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](F[i]);
[Link](new GridLayout(2,4));
xisim=new JLabel(isim1);
x[0]=new JTextField(5);
x[1]=new JTextField(5);
x[2]=new JTextField(5);
Fisim=new JLabel(isim2);
F[0]=new JTextField(5);
F[1]=new JTextField(5);
F[2]=new JTextField(5);
[Link](xisim);
for(int i=0;i<3;i++)
[Link](x[i]);
[Link](Fisim);
for(int i=0;i<3;i++)
[Link](F[i]);
for(int i=0;i<3;i++)
this.x[i].setText(""+xi[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<3;i++)
this.F[i].setText(""+Fi[i]);
15. H4O3
Üç noktadan bir düzlem geçtiðini biliyoruz. düzlemin formülü z=a*x+b*y+c dir (a,b,c sabit). 3
noktadan geçen düzlemi tanýmlayan [Link] programýný ve duzlem sýnýfýný yazýnýz.
not: birim vektorler xi, x doðrultusunda, xj y doðrultusunda ve xk z doðrultusundadýr.
[Link] konsol türü örnek test programýnda yarattýðýnýz bir düzlem nesnesinin(object)
baºlangýç kordinatlarýna uzaklýðýný (baºlangýç noktasýndan geçen ve düzleme dik olan bir
doðrunun boyunu) hesaplayýnýz.
import duzlem;
import vektor3D;
import nokta3D;
class H4O3
double a,b,c;
a = (-7.0/3.0);
b = (5.0/3.0);
c = (2.0/3.0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
nokta3D P0=new nokta3D(2,-1,3);
[Link](P1);
double sonuc=[Link](v1)/v.F();
[Link]("duzlem d = "+[Link]());
[Link]("nokta P0 = "+[Link]());
H4OD4_2000
not : public static kompleks pow(kompleks sol) metodu kompleks sayýnýn üssünü
hesaplar.
return pow(sol,0.5);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
import kompleks;
import BasicWindowMonitor;
//
//=====================================================
// sinif degiskenleri
//=====================================================
public H4OD4_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
k1=new kompleks(1.0,1.0);
Container c=getContentPane();
[Link](new FlowLayout());
[Link](kutubasligi1);
kutugirdisi1=new JTextField(5);
[Link](this);
[Link](kutugirdisi1);
kutugirdisi2=new JTextField(5);
[Link](this);
[Link](kutugirdisi2);
cikti=new JTextArea(toString());
[Link]([Link]());
[Link](cikti);
//=====================================================
String s="";
return s;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]([Link]([Link]()),
[Link]([Link]()));
[Link](toString());
//=====================================================
[Link](new BasicWindowMonitor());
[Link](500,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Boyutlu deðiºkenler ayný degiºken türü veya sýnýf türünden birden fazla nesne veya
deðiºkenin tek bir isimle tanýmlanmasýdýr. Boyutlu deðiºkenlere referans indeks numarasý
kullanýlarak ulaºýlýr. Genel olarak bir boyutlu deðiºkenler
Deðiºken_türü deðiºken_ismi[];
veya
Deðiºken_türü[] deðiºken_ismi;
ªeklinde tanýmlanýr. Birinci tanýmýn kullanýlmasý daha yaygýndýr. Ýki taným arasýnda bilgisayar
açýsýndan bir fark mevcut deðildir. Bir örnek verecek olursak
int[] ayýn_gunleri;
Bu tanýmlar her ne kadar haftanýn_gunleri nin boyutlu bir deðiºken olduðunu belirtiyorsa da
kesin boyutunu bildirmemektedir. Boyutlu deðiºkenin tam boyutunu tanýmlamak ve bilgisayar
hafýzasýndaki yerini tam olarak saptamak için
Deðiºken_ismi=new Deðiºken_türü[deðiºken_boyutu];
Ayýn_gunleri=new int[12];
Boyutlu deðiºkeni bir kere tanýmladýktan sonra onun içindeki her alt deðere indeksi üzerinden
ulaºmak mümkündür.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Örnegin:
ayýn_gunleri[0] = 31;
ayýn_gunleri[1] = 28;
Küçük bir örnek sýnýfta bu kavramý daha açýk olarak vermeye çalýºalým.
import [Link].*;
class boyut
{
public static void main(String args[] )
{
int ayin_gunleri[];
ayin_gunleri=new int[12];
ayin_gunleri[0]=31;
ayin_gunleri[1]=28;
ayin_gunleri[2]=31;
ayin_gunleri[3]=30;
ayin_gunleri[4]=31;
ayin_gunleri[5]=30;
ayin_gunleri[6]=31;
ayin_gunleri[7]=31;
ayin_gunleri[8]=30;
ayin_gunleri[9]=31;
ayin_gunleri[10]=30;
ayin_gunleri[11]=31;
[Link]("Nisan ayi "+ayin_gunleri[3]+" gun ceker");
}
}
Bu programý daha kýsa olarak yazmak için ªekil 4.1.2 de görülen ºekilde bütün deðiºkenlerin
deðerlerini ayný anda tanýmlýyabiliriz.
import [Link].*;
class boyut1
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String args[] )
{
int ayin_gunleri[]={31,28,31,30,31,30,31,31,30,31,30,31};
[Link]("Nisan ayi "+ayin_gunleri[3]+" gun ceker");
}
}
Program 4.3’de boyut kavramýnýn for döngüsüyle birlikte kullanýºýný görüyorsunuz. Boyutlu
deðiºkenin toplam boyutuna da sayý.length deðiºkeniyle ulaºýyoruz. Daha önceki
birçokprogramlama dilinde bu mümkün deðildir ve boyutlu deðiºkenin boyutunun bildirilmesi
gerekir. Program 4.3 ün çýktýsýný step step takip ederek ve bir hesap makinasý kullanarak
hesaplayýnýz.
ªimdi de bir applet örneðinde tek boyutlu deðiºkenleri kullanalým. Daha önce [Link]
programýný incelemiºtik. ªimdi bu programa her bir zar yüzeyinin atýlýº frekanslarýný
ekleyelim. Toplam altý yüz olduðundan birden altýya kadar her sayýnýn kaç kere geldiðini
saydýrmamýz gerekir. Bunun için bir boyutlu zarfrekansi deðiºkenini tanýmlayacaðýz.
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class zarfrekansiApplet extends Applet implements ActionListener
{
int toplamzaratisi=0;
int toplam=0;
TextField ilkzar,ikincizar;
Button salla; //zar atma dügmesi
int zar1,zar2;
int zarfrekansi[];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import BasicWindowMonitor;
int toplamzaratisi=0;
int toplam=0;
JTextField ilkzar,ikincizar;
JTextArea cikti;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int zar1,zar2;
int zarfrekansi[];
return 1+(int)([Link]()*6);
public zarfrekansiSWF()
//programi baslat
zarfrekansi=new int[6];
Container c=getContentPane();
[Link](new FlowLayout());
[Link](salla);
[Link](this);
cikti=new JTextArea();
[Link]([Link]());
[Link](cikti);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e)
String s="";
zar1=zar();
zar2=zar();
[Link]([Link](zar1));
[Link]([Link](zar2));
toplam+=(zar1+zar2);
toplamzaratisi++;
zarfrekansi[zar1-1]++;
zarfrekansi[zar2-1]++;
for(int i=0;i<6;i++)
[Link](s);
repaint();
//=====================================================
[Link](new BasicWindowMonitor());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](450,200);
[Link](true);
[Link]
Nesne tipi deðiºkenler için de ayný normal basit deðiºkenlerde olduðu gibi boyut tanýmý
yapýlýr. Normal boyut tanýmý yapýldýktan sonra, boyuttaki her nesne teker teker tanýmlanýr.
Örneðin :
Dogru3 n[];
n=new dogru3[3];
n[0]=new dogru3(1,1,1,2,2,2);
n[1]=new dogru3(2,2,2,3,3,3);
n[2]=new dogru3(3,3,3,4,4,4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
gibi.
Ýki ve daha fazla boyutlu deðiºkenler de tanýmlamak mümkündür. Ýki boyutlu deðiºkenler en
fazla tablo veya matris gibi satýr ve sütun olmak üzere iki boyutta gösterilmesi gereken
büyüklükleri oluºturmak için kullanýlý[Link] iki boyutlu deðiºkenleri direk olarak açamaz. Tek
boyutlu deðiºkenlerin yine tek boyutlu degiºkenini açar. Sonuç olarak iki boyut saðlanmýº
olur. Örnek verecek olursak
Int b[][]=new int[3][4]. Genel olarak ilk parantes satýr sayýsý, ikinci parantez sütun sayýsý
olarak kabul edilir. Buna göre b deðiºkenini ºöyle düºünebiliriz :
Iki boyutlu deðiºken de bir boyutlu deðiºkenlerde olduðu gibi degerleri direk olarak
yüklüyebiliriz, ve yükleme sýrasýnda boyutlarý da tayin edebiliriz.
Örneðin :
1 2
3 4
b[0][0] b[0][1]
b[1][0] b[1][1]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Ýki boyutlu deðiºkenlerin kullanýlmasýný göstermek amacýyla bir örnek problem verelim:
import [Link];
import [Link];
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 4.3 Ýki boyutlu deðiºkenler örnegi [Link] doyasýnýn appletviewer ile
görünümü
import [Link];
int a1[][]={{1,2,3},{4,5,6}};
int a2[][]={{1,2},{4}};
s=s+ikiboyutyazdir(a1);
s=s+" a2 : \n";
s=s+ikiboyutyazdir(a2);
[Link](null,s);
[Link](0);
String s="";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<[Link];i++)
for(int j=0;j<a[i].length;j++)
s+=[Link](a[i][j])+" ";
s+="\n";
return s;
JoptionPane çýktýsý :
[Link]
ªekil 4.4 Ýki boyutlu deðiºkenler örnegi ikiboyut_2000 doyasýnýn JoptionPane çýktýsý
olarak
görünümü
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 4.8 : Ýki boyutlu deðiºkenler örnegi : ikiboyutSWF_2000.java
import [Link].*;
import [Link].*;
import [Link].*;
import BasicWindowMonitor;
JTextArea cikti;
public ikiboyutSWF_2000()
Container c=getContentPane();
[Link](new FlowLayout());
int a1[][]={{1,2,3},{4,5,6}};
int a2[][]={{1,2},{4}};
s=s+ikiboyutyazdir(a1);
s=s+" a2 : \n";
s=s+ikiboyutyazdir(a2);
cikti=new JTextArea(s);
[Link]([Link]());
[Link](cikti);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static String ikiboyutyazdir(int a[][])
String s="";
for(int i=0;i<[Link];i++)
for(int j=0;j<a[i].length;j++)
{s+=[Link](a[i][j])+" ";}
s+="\n";
return s;
//=====================================================
[Link](new BasicWindowMonitor());
[Link](200,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 4.5 Ýki boyutlu deðiºkenler örnegi ikiboyutSWF_2000 doyasýnýn JFrame çýktýsý
olarak
görünümü
Boyutlara ulaºmak için yukarýdaki programlardan da görüleceði gibi for döngüsü kullandýk.
Boyutlu deðiºkenlere ulaºým. for döngülerinin en çok kullanýldýðý yerlerden biridir.
Boyutlu deðiºkenler aynen boyutsuz deðiºkenler gibi metotlara aktarýlýrlar. Örneðin eðer
sicakligidegistir(sýcaklik);
..........................
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
gibi.
double a[]={3.0,5.0,7.0}
for(int i=0;i<[Link];i++)
{b[i]=a[i];}
a=b;
//sýnýf deðiºkenleri
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
length=[Link];
a=new double[length];
for(int i=0;i<length;i++)
a[i]=x[i];
public doubleBoyut(int n)
a=new double[n];
length=[Link];
if(n>0)
int z=[Link]+n;
for(int i=0;i<[Link];i++)
{b[i]=a[i];}
a=b;
length=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void boyutEkle()
boyutEkle(1);
int z=[Link]-n;
if(z>1)
for(int i=0;i<z;i++)
b[i]=a[i];
a=b;
else
b[0]=a[0];
a=b;
length=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
boyutAzalt(1);
return a[i];
return a;
a[i]=x;
length=[Link];
a=new double[length];
for(int i=0;i<length;i++)
a[i]=x[i];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return ""+a[i];
String s="";
for(int i=0;i<length;i++)
s+=a[i]+" ";
s+="\n";
return s;
import [Link];
import doubleBoyut;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class boyutDegistir
double x[]={3.1,5.3,7.0,9.7,11.0,11.5,12.3};
s+=[Link]();
[Link](3);
s+=[Link]();
[Link](5);
s+=[Link]();
[Link](null,s,
JOptionPane.PLAIN_MESSAGE);
[Link](0);
Program çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 4.6 boyut deðiºtirme örneði boyutu deðiºtirilebilen doubleBoyut sýnýfýnýn
boyutDegistir sýnýfýnda JoptionPane çýktýsý olarak görünümü
4.6 ALIªTIRMALAR
//kurucu metotlar
public nokta3()
{
nokta3gir(0,0,0);
}
public nokta3(nokta3 n)
{
nokta3gir([Link](),[Link](),[Link]());
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x = a;
y = b;
z = c;
}
//kurucu metotlar
public nokta3()
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
nokta3gir(0,0,0);
}
public nokta3(nokta3 n)
{
nokta3gir([Link](),[Link](),[Link]());
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double Zoku()
{
return z;
}
public dogru3()
{
n1=new nokta3();
n2=new nokta3();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void n1gir(double x1,double y1,double z1)
{
n1.nokta3gir(x1,y1,z1);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double ac�_n1_xz()
{
// dogrunun n1 noktasýndan x z duzlemindeki açýsý
// radyan
return Math.atan2(Z(),X());
}
2. Sizin için kompleks sýnýfý yaratýlmýº ve bu sýnýfýn nasýl kullanýldýðýný açýklayan H8A1 applet
programý verilmiºtir. Bu iki programý incele. Ayrýca Aritmetik2 programýný incele ve boyutlu
deðiºkenlerin kullanýmýný öðren. Sonra 5 kompleks sayýnýn toplamýný hesaplayan bir konsol
programý yaz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]((double)[Link]);
[Link]("Ortalama = "+[Link]());
}
}
class H8A1a
{
public static void main(String args[]) throws IOException
{
kompleks sayi[]=new kompleks[5];
double n1,n2;
kompleks toplam=new kompleks();
int i;
Text cin=new Text();
for(i=0;i<[Link];i++)
{
[Link]("bir kompleks sayi giriniz : ");
n1=[Link](cin);
n2=[Link](cin);
sayi[i]=new kompleks(n1,n2);
[Link](sayi[i]);
}
[Link]((double)[Link]);
[Link]("Ortalama = "+[Link]());
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
3. Üç boyutlu nokta ve doðru tanýmlarý nokta3 ve dogru3 sýnýflarýnda verilmiºtir. 3 tane
dogruyu boyutlu deðiºken olarak H8A2 sýnýfýnda tanýmlayýn ve dogrularýn toplam boylarýný ve
baslangýç noktasýnýn xy xz ve yz düzlemlerinde yaptýðý açýlarý derece cinsinden yazdýrýn.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//bu sýnýf sinif degiskeni kompleksi boyutlu olarak çaðýrýr
import kompleks;
class H5AL3
double n1,n2;
int n=[Link]();
int i;
for(i=0;i<[Link];i++)
n1=[Link]();
n2=[Link]();
sayi[i]=new kompleks(n1,n2);
[Link](sayi[i]);
[Link]((double)[Link]);
[Link]("Ortalama = "+[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
13. H5O1 : java konsol programýnda toplam bayaðýkesir sayisini sorduktan sonra
ekrandan verilen sayýda bayaðý kesiri giriniz ve ortalamalarýný hesaplayýnýz.
import bayagikesir;
class H5O1
int n1,n2;
int n=[Link]();
int i;
for(i=0;i<[Link];i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("bir bayagikesir giriniz : ");
n1=[Link]();
n2=[Link]();
sayi[i]=new bayagikesir(n1,n2);
for(i=0;i<[Link];i++)
try{
[Link](sayi[i]);
catch (bayagikesirException e)
[Link]([Link]());
[Link]("Toplam = "+[Link]());
try{
[Link]([Link]);
catch (bayagikesirException e)
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("Ortalama = "+[Link]());
14. H5O3
Üç boyutlu n kompleks sayýyý java konsol programýnda toplam kompleks sayýlarýn
sayýsýný sorduktan sonra ekrandan verilen sayýda kompleks sayýyý giriniz. Kompleks
sayýlar girildikten sonra, kompleks sayýlarýn ortalamasýný hesaplayýnýz.
import kompleks;
class H5O3
double n1,n2;
int n=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int i;
for(i=0;i<[Link];i++)
n1=[Link]();
n2=[Link]();
sayi[i]=new kompleks(n1,n2);
for(i=0;i<[Link];i++)
[Link](sayi[i]);
[Link]("Toplam = "+[Link]());
[Link]([Link]);
[Link]("Ortalama = "+[Link]());
15 H5OD1_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*; //java girdi cikti sinifini cagir
import kompleks;
class H5OD1_2000
int n1,n2;
int n=[Link]();
int i;
for(i=0;i<[Link];i++)
n1=[Link]();
n2=[Link]();
sayi[i]=new kompleks(n1,n2);
for(i=0;i<[Link];i++)
[Link]([Link](sayi[i]));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]([Link]);
15. H5OD2_2000
//sýnýf deðiºkenleri
length=[Link];
a=new int[length];
for(int i=0;i<length;i++)
a[i]=x[i];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public intBoyut(int n)
a=new int[n];
length=[Link];
if(n>0)
int z=[Link]+n;
for(int i=0;i<[Link];i++)
{b[i]=a[i];}
a=b;
length=[Link];
boyutEkle(1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void boyutAzalt(int n)
int z=[Link]-n;
if(z>1)
for(int i=0;i<z;i++)
b[i]=a[i];
a=b;
else
b[0]=a[0];
a=b;
length=[Link];
boyutAzalt(1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return a[i];
return a;
a[i]=x;
length=[Link];
a=new int[length];
for(int i=0;i<length;i++)
a[i]=x[i];
return ""+a[i];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String s="";
for(int i=0;i<length;i++)
s+=a[i]+" ";
s+="\n";
return s;
import [Link];
import doubleBoyut;
int x[]={3,5,7,9,11};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s+=[Link]();
[Link]();
s+=[Link]();
[Link](2);
s+=[Link]();
[Link](null,s,
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
ªekil 4.7 intBoyut, boyutlu tam sayý boyut deðiºtirme eksersizi, H5OD2_2000.java,
JoptionPane çýktýsý
16. H5OD3_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String isim;
String Soysisim;
int not;
class ogrenci
isim=isimGir;
soyisim=soyisimGir;
not=notGir;
[Link]=isim;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]=soyisim;
[Link]=not;
isim=isimGir;
soyisim=soyisimGir;
not=notGir;
return isim;
return soyisim;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int notOku()
return not;
import ogrenci;
import ogrenciFrame;
class H5OD3_2000
int i,n;
int not;
double toplam = 0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ogrenci temp;
n=[Link]();
for(i=0;i<n;i++)
[Link]("isim : ");
isim = [Link]();
[Link]("soyisim : ");
soyisim=[Link]();
[Link]("not : ");
not=[Link]();
toplam += not;
toplam /= (double)n;
for(i=0;i<[Link];i++)
[Link](dizi[i].toString());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Turhan Çoban 25
Meral Çoban 75
Ali Velizade 99
Kavramý daha iyi verebilmek için bir örnek problem oluºturalým. Daha önce sýnýf kavramýný
açýklarken kullandýðýmýz nokta,daire sýnýflarýný hatýrlýyacaksýnýz. ªimdi bu sýnýflarýn üzerine
sekil isimli bir abstract sýnýf ekleyerek tekrar oluºturalým.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import sekilX;
protected double x, y;
x=a;
y=b;
x=a;
y=b;
return x;
return y;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return "["+x+","+y+"]";
import noktaX;
public daireX()
super(0,0);
yaricapgir(0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public daireX(double r, double a, double b)
super(a,b);
yaricapgir(r);
yaricap=r;
else
yaricap=0.0;
return yaricap;
return 3.14159*yaricap*yaricap;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString()
"; Yaricap="+yaricap;
import daireX;
public silindirX()
yukseklikoku(0);
super(r, a, b );
yukseklikoku( h);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void yukseklikoku (double h )
if(h>=0) yukseklik=h;
else yukseklik=0;
return 2* [Link]()+
2*[Link]*yaricap*yukseklik;
{return [Link]()+";yukseklik="+yukseklik;}
Program 5.4 : Abstract sýnýf ve indirek referanslamayý test eden abstracttesti sýnýfý
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class abstracttesti extends Applet
private noktaX n;
private daireX d;
private silindirX s;
n = new noktaX(7,11);
d = new daireX(3.5,22,8);
s = new silindirX(10,3.3,10,10);
a = new sekilX[3];
a[0]=n;
a[1]=d;
a[2]=s;
//direk cagirma :
[Link]([Link]()+": "+[Link](),25,25);
[Link]([Link]()+": "+[Link](),25,40);
[Link]([Link]()+": "+[Link](),25,55);
//indirek cag�rma
int y=85;
for(int i=0;i<[Link];i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](a[i].isim()+": "+a[i].toString(),25,y);
y+=15;
y+=15;
[Link]
ªekil 5.1 Abstract sýnýf ve indirek referanslamayý test eden abstractTesti sýnýfýnýn
sonuclarýnýn applet de görülmesi
import [Link];
import silindirX;
import noktaX;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import daireX;
noktaX n;
daireX d;
silindirX s;
sekilX a[];
n = new noktaX(7,11);
d = new daireX(3.5,22,8);
s = new silindirX(10,3.3,10,10);
a = new sekilX[3];
a[0]=n;
a[1]=d;
a[2]=s;
String st="";
st+=[Link]()+": "+[Link]()+"\n";
st+=[Link]()+": "+[Link]()+"\n";
st+=[Link]()+": "+[Link]()+"\n";
//indirek caðýrma
int y=85;
for(int i=0;i<[Link];i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
st+=a[i].isim()+": "+a[i].toString()+"\n";
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Örnekten de görüldügü gibi nokta, daire ve silindir abstract sekil sýnýfýnýn alt sýnýflarý olarak
oluºturulmuº, ve ayný zamanda bu sýnýflara indirek referans olarak kullanýlmýºtýr. Diðer bir
deyimle nokta daire ve silindirin adresleri sekil sýnýfý nesneye aktarýlmýº ve bu nesne
üzerinden üç sýnýfta indirek olarak kullanýlmýºtýr. Bu indirek kullanýmýn bize temel faydasý,
Programýmýza yeni sýnýflar eklediðimizde daha kolay ve az program deðiºtirerek uyumu
saðlayabilme yeteneðidir. Orneðin yukarýdaki program sýnýflarý gurubuna koni eklemek
istersek bütün yapacaðýmýz koni sýnýfýný tanýmladýktan sonra, sekil nesnesi a nýn boyutunu bir
arttýrarak ayný hesaplamaya koniyide ilave etmekten ibaret olacaktýr. Bu tür uygulamalar
bilgisayar kodunun deðiºim gereksinimini minimuma indirgediðinden nesne kokenli bilgisayar
programcýlýðýnýn onemli uygulamalarýndan biridir.
5.2 INTERFACE
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Abstract sýnýflarýn dezavantajý sadece bir sýnýfýn kalýtým yoluyla ve extends sozcüðü
kullanýlarak baðlanabilir olmasýdýr. Ve eðer baºka bir sýnýf halihazýrda o sýnýfa kalýtým yoluyla
baðlanmýºsa, bizim yeni bir sýnýfý üst sýnýf olarak kullanma olasýlýðýmýz yok olmuº demektir.
Fakat bazý uygulamalar için bu [Link] zaman interface kullanýrýz. Interface de
abstract sýnýf gibi kendi içinde bir iºlem yapmaz. Sadece öbür sýnýflarýn baðlanmasýný teºkil
eden bir adres noktasý olarak iº görür. Ýnterface’i bir baºka sýnýfa baðlamak gerektiðinde
extends yerine implements sözcüðü kullanýlýr. Abstract sýnýflar kendi baºýna bir bütün teºkil
edebilmelerine raðmen interface’in sadece kendi baºýna bir anlamý yoktur. Interface sýnýfýnda
yer alan tüm metod ve deðiºkenlerin alt sýnýflarda tanýmlanmasý gerekir.
import sekilY;
public class noktaY implements sekil
{
protected double x, y;
public noktaY(double a, double b)
{
noktagir(a,b);
}
public void noktagir(double a, double b)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x=a;
y=b;
}
public double Xoku()
{
return x;
}
public double Yoku()
{
return y;
}
public double alan() {return 0.0;}
public double hacim() {return 0.0;}
public String toString()
{
return "["+x+","+y+"]";
}
public String isimOku()
{
return "Nokta";
}
}
Görüldüðü gibi burada nokta sýnýfýnýn bir öncekinden farký implements kelimesinin kullanýlmýº
olamasý ve bos alan ve hacim metotlarýnýn bu dosyada yazýlmasýnýn gerekmesinden ibarettir.
Interface programla yapýlan ve alt sýnýflarda bu metodlarýn (veya deðiºkenlerin)
tanýmlanacaðýna dair yapýlan bir kontrattý[Link] ve silindirY sýnýflarýnda bir fark mevcut
degildir. Ýki seklin iºlemsel sonuçlarý arasýnda da bir fark mevcut deðildir.
import noktaY;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public daireY()
super(0,0);
yaricapgir(0);
super(a,b);
yaricapgir(r);
yaricap=r;
else
yaricap=0.0;
return yaricap;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return 3.14159*yaricap*yaricap;
"; Yaricap="+yaricap;
import daireY;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public silindirY()
super(0, 0, 0 );
yukseklikoku(0);
super(r, a, b );
yukseklikoku( h);
if(h>=0) yukseklik=h;
else yukseklik=0;
return 2* [Link]()+
2*[Link]*yaricap*yukseklik;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double hacim(){return [Link]()*yukseklik;}
{return [Link]()+";yukseklik="+yukseklik;}
Program 5.8 : interface sekilY’den türeyen sýnýflarý test eden ve indirek olarak
referanslýyan interfaceTesti_2000.java programý
import [Link];
import silindirY;
import noktaY;
import daireY;
noktaY n;
daireY d;
silindirY s;
sekilY a[];
n = new noktaY(7,11);
d = new daireY(3.5,22,8);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s = new silindirY(10,3.3,10,10);
a = new sekilY[3];
a[0]=n;
a[1]=d;
a[2]=s;
String st="";
st+=[Link]()+": "+[Link]()+"\n";
st+=[Link]()+": "+[Link]()+"\n";
st+=[Link]()+": "+[Link]()+"\n";
//indirek caðýrma
int y=85;
for(int i=0;i<[Link];i++)
st+=a[i].isim()+": "+a[i].toString()+"\n";
JOptionPane.PLAIN_MESSAGE);
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 5.2 interface sýnýf ve indirek referanslamayý test eden interfaceTesti_2000
sýnýfýnýn sonuclarýnýn JoptionPane çýktýsý olarak görülmesi
5.3 ALIªTIRMALAR
abstract class fx
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
abstract double f(double x);
// yapilmalidir.
// ornate.
double h0=0.0256;
int i,m;
int n=7;
double T[][];
T=new double[n][n];
double h[];
h=new double[n];
for(i=0;i<n;i++)
h[i]=0;
for(int j=0;j<n;j++)
T[i][j]=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
h[0]=h0;
double r=0.5;
for( i=1;i<n;i++)
h[i]=h0*[Link](r,i);
for(i=0;i<n;i++)
for(m=1;m<n;m++)
for(i=0;i<n-m;i++)
T[i][m]=(h[i]*h[i]*T[i+1][m-1] - h[i+m]*h[i+m]*T[i][m-1])/
(h[i]*h[i]- h[i+m]*h[i+m]);
double xx=T[0][n-1];
return xx;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//gauss-legendre denklemini kullanarak integral hesaplama
//
double s[],w[];
int i;
s=new double[30];
w=new double[30];
s[ 0] = .15532579626752470000E-02;
s[ 1] = .81659383601264120000E-02;
s[ 2] = .19989067515846230000E-01;
s[ 3] = .36899976285362850000E-01;
s[ 4] = .58719732103973630000E-01;
s[ 5] = .85217118808615820000E-01;
s[ 6] = .11611128394758690000E+00;
s[ 7] = .15107475260334210000E+00;
s[ 8] = .18973690850537860000E+00;
s[ 9] = .23168792592899010000E+00;
s[10] = .27648311523095540000E+00;
s[11] = .32364763723456090000E+00;
s[12] = .37268153691605510000E+00;
s[13] = .42306504319570830000E+00;
s[14] = .47426407872234120000E+00;
s[15] = .52573592127765890000E+00;
s[16] = .57693495680429170000E+00;
s[17] = .62731846308394490000E+00;
s[18] = .67635236276543910000E+00;
s[19] = .72351688476904450000E+00;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s[20] = .76831207407100990000E+00;
s[21] = .81026309149462140000E+00;
s[22] = .84892524739665800000E+00;
s[23] = .88388871605241310000E+00;
s[24] = .91478288119138420000E+00;
s[25] = .94128026789602640000E+00;
s[26] = .96310002371463720000E+00;
s[27] = .98001093248415370000E+00;
s[28] = .99183406163987350000E+00;
s[29] = .99844674203732480000E+00;
w[ 0] = .39840962480827790000E-02;
w[ 1] = .92332341555455000000E-02;
w[ 2] = .14392353941661670000E-01;
w[ 3] = .19399596284813530000E-01;
w[ 4] = .24201336415292590000E-01;
w[ 5] = .28746578108808720000E-01;
w[ 6] = .32987114941090080000E-01;
w[ 7] = .36877987368852570000E-01;
w[ 8] = .40377947614710090000E-01;
w[ 9] = .43449893600541500000E-01;
w[10] = .46061261118893050000E-01;
w[11] = .48184368587322120000E-01;
w[12] = .49796710293397640000E-01;
w[13] = .50881194874202750000E-01;
w[14] = .51426326446779420000E-01;
w[15] = .51426326446779420000E-01;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
w[16] = .50881194874202750000E-01;
w[17] = .49796710293397640000E-01;
w[18] = .48184368587322120000E-01;
w[19] = .46061261118893050000E-01;
w[20] = .43449893600541500000E-01;
w[21] = .40377947614710090000E-01;
w[22] = .36877987368852570000E-01;
w[23] = .32987114941090080000E-01;
w[24] = .28746578108808720000E-01;
w[25] = .24201336415292590000E-01;
w[26] = .19399596284813530000E-01;
w[27] = .14392353941661670000E-01;
w[28] = .92332341555455000000E-02;
w[29] = .39840962480827790000E-02;
int n=30;
double z=0;
double x,y;
for(i=0;i<n;i++)
x=(b+a)/2.0+(b-a)/2.0*s[i];
y=fi.f(x);
z+=(b-a)/2*w[i]*y;
for(i=0;i<n;i++)
x=(b+a)/2.0+(b-a)/2.0*(-s[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
y=fi.f(x);
z+=(b-a)/2.0*w[i]*y;
return z;
import [Link].*;
import H5AL1;
class f1 extends fx
double f(double x)
return x*x;
class f2 extends fx
double f(double x)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return [Link](x);
f1 b1;
b1=new f1();
[Link]("Integral : "+[Link](b1,0.0,1.0));
[Link]("Turev : "+[Link](b1,1.0));
f2 b2;
b2=new f2();
[Link]("Integral : "+[Link](b2,0.0,[Link]));
[Link]("Turev : "+[Link](b2,[Link]));
5. H5O2 :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double turev(fx fi,double x)
// yapilmalidir.
// ornate.
double h0=0.0256;
int i,m;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n=7;
double T[][];
T=new double[n][n];
double h[];
h=new double[n];
for(i=0;i<n;i++)
h[i]=0;
for(int j=0;j<n;j++)
T[i][j]=0;
h[0]=h0;
double r=0.5;
for( i=1;i<n;i++)
h[i]=h0*[Link](r,i);
for(i=0;i<n;i++)
double temp=x[k];
x[k]=x[k] + h[i];
double fiP=fi.f(x);
x[k]=temp - h[i];
double fiM=fi.f(x);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x[k]=temp;
for(m=1;m<n;m++)
for(i=0;i<n-m;i++)
T[i][m]=(h[i]*h[i]*T[i+1][m-1] - h[i+m]*h[i+m]*T[i][m-1])/
(h[i]*h[i]- h[i+m]*h[i+m]);
double xx=T[0][n-1];
return xx;
//
double s[],w[];
double tempxk=x[k];
int i;
s=new double[30];
w=new double[30];
s[ 0] = .15532579626752470000E-02;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s[ 1] = .81659383601264120000E-02;
s[ 2] = .19989067515846230000E-01;
s[ 3] = .36899976285362850000E-01;
s[ 4] = .58719732103973630000E-01;
s[ 5] = .85217118808615820000E-01;
s[ 6] = .11611128394758690000E+00;
s[ 7] = .15107475260334210000E+00;
s[ 8] = .18973690850537860000E+00;
s[ 9] = .23168792592899010000E+00;
s[10] = .27648311523095540000E+00;
s[11] = .32364763723456090000E+00;
s[12] = .37268153691605510000E+00;
s[13] = .42306504319570830000E+00;
s[14] = .47426407872234120000E+00;
s[15] = .52573592127765890000E+00;
s[16] = .57693495680429170000E+00;
s[17] = .62731846308394490000E+00;
s[18] = .67635236276543910000E+00;
s[19] = .72351688476904450000E+00;
s[20] = .76831207407100990000E+00;
s[21] = .81026309149462140000E+00;
s[22] = .84892524739665800000E+00;
s[23] = .88388871605241310000E+00;
s[24] = .91478288119138420000E+00;
s[25] = .94128026789602640000E+00;
s[26] = .96310002371463720000E+00;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s[27] = .98001093248415370000E+00;
s[28] = .99183406163987350000E+00;
s[29] = .99844674203732480000E+00;
w[ 0] = .39840962480827790000E-02;
w[ 1] = .92332341555455000000E-02;
w[ 2] = .14392353941661670000E-01;
w[ 3] = .19399596284813530000E-01;
w[ 4] = .24201336415292590000E-01;
w[ 5] = .28746578108808720000E-01;
w[ 6] = .32987114941090080000E-01;
w[ 7] = .36877987368852570000E-01;
w[ 8] = .40377947614710090000E-01;
w[ 9] = .43449893600541500000E-01;
w[10] = .46061261118893050000E-01;
w[11] = .48184368587322120000E-01;
w[12] = .49796710293397640000E-01;
w[13] = .50881194874202750000E-01;
w[14] = .51426326446779420000E-01;
w[15] = .51426326446779420000E-01;
w[16] = .50881194874202750000E-01;
w[17] = .49796710293397640000E-01;
w[18] = .48184368587322120000E-01;
w[19] = .46061261118893050000E-01;
w[20] = .43449893600541500000E-01;
w[21] = .40377947614710090000E-01;
w[22] = .36877987368852570000E-01;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
w[23] = .32987114941090080000E-01;
w[24] = .28746578108808720000E-01;
w[25] = .24201336415292590000E-01;
w[26] = .19399596284813530000E-01;
w[27] = .14392353941661670000E-01;
w[28] = .92332341555455000000E-02;
w[29] = .39840962480827790000E-02;
int n=30;
double z=0;
double y;
for(i=0;i<n;i++)
x[k]=(b+a)/2.0+(b-a)/2.0*s[i];
y=fi.f(x);
z+=(b-a)/2*w[i]*y;
for(i=0;i<n;i++)
x[k]=(b+a)/2.0+(b-a)/2.0*(-s[i]);
y=fi.f(x);
z+=(b-a)/2.0*w[i]*y;
x[k]=tempxk;
return z;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
6 . Program 5.10 da verilen polar sýnýfýný inceleyiniz. Polar sýnýfýnýn kompleks sýnýfýyla
oldukça benzer olduðunu gözlemleyebilirsiniz. Bu iki sýnýfýn temel özelliklerinden yararlanan
abstact bir sýnýf oluºturunuz, bu sýnýfýn alt sýnýflarý olarak polar ve kompleks sýnýflarýný
yeniden tanýmlayýnýz. Bir örnek programda abstract sýnýf üzerinden polar ve kompleks
sýnýflarý çaðýrarak kullanýnýz.
public polar()
R=0;
teta=0;
R=Ri;
teta=tetai;
public polar(polar y)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
R=[Link]();
teta=[Link]();
R=Ri;
teta=tetai;
R=Ri;
teta=tetai;
R=[Link](xi*xi+xj*xj);
teta=Math.atan2(xj,xi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return R;
return teta;
return R*[Link](teta);
return R*[Link](teta);
kartesienGir((xi()+[Link]()),(xj()+[Link]()));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void fark(polar y)
kartesienGir((xi()-[Link]()),(xj()-[Link]()));
return this;
boolean b=((R==[Link]())&&(teta==[Link]()));
return b;
return (this.R>[Link]());
return (this.R<[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
6.1 GÝRݪ
Daha önce applet çizerken [Link] kütüphanesi ndeki grafik (Graphics) sýnýfý ný
kullanmýºtýk. Ve grafik (Graphics) sinifinina ait drawString metotunu kullanarak applete yazý
yazdýrmýºtýk. ªimdi bu sýnýfýn diðer özelliklerini ve metotlarýný öðreneceðiz.
Graphics sýnýfý [Link] sýnýfýnýn altýnda yer alýr. Bu gurupta ayný zamanda grafik
çiziminin çeºitli fazlarýnda kullanýlan [Link], [Link]:Font, [Link],
[Link], [Link], [Link] yer alýr. Daha detaylý grafik çizme iºlemleri
tanýmlayabilen [Link]. Graphics2D paketi [Link] paketinden türetilmiºtir. Ayrýca
[Link], [Link], [Link] gibi temel grafik alt
programlarý da [Link] altýnda tanýmlanmýºtýr. Temel ºekilleri çizdirmeye yarayan
[Link], [Link].Line2D, [Link] de
[Link] altýnda tanýmlanýr. [Link].Arc2D, . [Link].Ellipse2D, .
[Link].Rectangle2D, . [Link].RoundRectangle2D gibi çizim paketleri de
[Link] paketinin alt paketleri olarak tanýmlanmýºtýr.
Graphics sýnýfý, yazý yazma, çizgi çizme, dikdörtgen, oval çizme gibi bir dizi metotu barýndýrýr.
Bunun dýºýnda awt kütüphanesinin önemli bir sýnýfý da Color sýnýfýdýr. Color sýnýfý rekleri
tanýmlar ve deðiºik renklerin kullanýmýna imkan verir. Font sýnýfý grafikte kullanýlan yazýlarýn
fontlarýnýn (yazý tipinin ve boyutunun) belirlenmesi amacýyla kullanýlýr. FontMetrics sýnýfý
fontlarýn boyutlarýnýn belirlenmesiyle ilgili metotlarý içerir. Polygon sýnýfý polygon çizimiyle
ilgili metotlarý barýndýrýr. Bu metodlarýn bir kýsmýný burada göreceðiz. Temel olarak Graphics
ve Graphics2D sýnýflarýný grafik çiziminde kullanacaðýz, Bu iºlemi yaparken de diðer tüm
yardýmcý grafik sýnýflarýndan yararlanacaðýz. Graphics2D sýnýfý daha yeni olarak tanýmlanmýº
ve Graphics sýnýfýndan türetilmiº bir sýnýftýr. Fakat çok daha komleks grafik çizim
kapasitelerini barýndýrýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java appletlerinde çizim yaparken ilk hatýrlamamýz gereken nokta, koordinat merkezinin
ekranýn sol üst köºesi olduðudur. X ekseni sola doðru, Y ekseni aºaðýya doðru gider.
[Link]
Y ekseninin alta doðru gitmesi konsol programlarýnda (ve ilk konsol programlama ortamý olan
satýr yazýcýlarýnda) satýrlarýn alta dogru ilerlemesi gibi tarihi bir nedene dayanmaktadýr. Bütün
bilgisayar diileri ve ekraný grafik programlamalarýnda standartdýr.
Graphics sýnýfý grafik çizimi için gerekli olan bir çok metotu içinde barýndýrýr. Grafik sýnýfý
[Link] sýnýfýnýn alt sýnýflarýndandýr. Grafik çizme amacýyla genellikle Graphics
sýnýfýndan bir nesne paint veya paintComponent metotunun içinde çaðýrýlýr. Paint
metotunun tanýmý ºöyledir
Bu taným Applet, Japplet,JFrame extend etmiº programlardan çaðýrýlabilir. Paint metodu tüm
bu üç sýnýfýn türetildiði Component sýnýfýnda tanýmlanmýºtýr. [Link] sýnýfý altýnda
tanýmlanan JComponent sýnýfýnda ise paintComponent metodu tanýmlanmýºtýr.
JComponentin alt metodu JPanel bu metodu kullanýr. Tanýmý paint metoduna benzer
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
paint veya paintComponent metodlarý Applet, Japplet, Frame, JFrame, Panel, JPanel
sýnýflarý tarafýndan direk olarak program açýldýðýnda çaðýrýlýr. Kullanýcý tarafýndan çaðýrýlmaz.
Tekrar kullanýcý tarafýndan çaðýrýlmasý gerektiðinde ise repaint metotu kullanýlýr ve repaint
metotu üzerinden indirek olarak paint metotu çaðýrýlýr. Bu metodun tanýmý :
ºeklindedir.
DrawChars bir boyutlu Char tipi deðiºken dizisini baºlangiçindeksi indeksinden baslayarak
yazýlacakharfsayýsý kadar kýsmýný x ve y koordinatlarýndan baºlýyarak çizer. DrawByte metotu
da drawChars metotu gibidir tek deðiºikliði Byte türü boyutlu deðiºken kullanmasýdýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link].*;
[Link](new Color(0,0,100));
[Link](new Font("SansSerif",[Link],24));
[Link](s,100,25);
[Link](c,2,3,100,50);
[Link](b,0,5,100,75);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.2 drawString drawChars drawBytes metotlarýný kullanan ciz programýnýn
Applet çýktýsý
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import renk;
public ciz2DSWF_2000()
setBackground(bg);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
setForeground(fg);
Graphics2D g2 = (Graphics2D)g;
[Link](new Font("TimesRoman",[Link],14));
[Link](s,100,50);
[Link](c,2,5,100,100);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.3 drawString drawChars metotlarýný kullanan ciz2DSWF_2000 programýnýn
swing JFrame çýktýsý
Programdan da görüleceði gibi paint metodu yine Graphics cinsinden çaðýrýlmakta , daha
sonra
Graphics2D g2 = (Graphics2D)g;
Appletlerde renk controlu Color sýnýfýný kullanarak yapýlýr. Renk olusumunda monitör ve
Televizyon sistemlerinde kullanýlan RG B ( Red- Green-Blue = Kýrmýzý- Yesil - Mavi ) sistemi
temel alýnýr. Bu üç renk monitorde 0-255 arasý deðerler alabilir. Üç rengin karýºýmý toplam
256*256*256 renk tanýmlar.
public Color( int kirmizi,int yesil,int mavi) //her renk 0-255 arasý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Tablo 6.1 Color sýnýfýnda tanýmlanmýº sabir renkler
Color sýnýfýnýn daha iyi anlaºýlabilmesi amacýyla Color sýnýfýnýn bir alt sýnýfý olan renk sýnýfýný
tanýmladýk.
Program 6.3 : Color sýnýfýnýn alt sýnýfý renk sýnýfýný tanýmlayan [Link] programý :
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public final static renk gri=new renk(128,138,128);
super(kirmizi,yesil,mavi);
super((float)kirmizi,(float)yesil,(float)mavi);
super(kirmizi,yesil,mavi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public renk(int RGB)
super(RGB);
public renk(renk r)
super([Link](),[Link](),[Link]());
return getRed();
return getGreen();
return getBlue();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getKYM()
return getRGB();
return (Color)this;
{return (renk)r;}
//metodlar
//getRed(),getGreen(),getBlue(),getRGB()
Renk sýnýfýný bir çok yerde Color sýnýfý yerine kullanabiliriz. Kullanamadýðýmýz durumlarda
cast iºlemcisi (Color) kullanýlabilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 6.4 : [Link]
import [Link].*;
import [Link];
import renk;
kirmizi=150;
yesil=255;
mavi=125;
setBackground([Link]);
[Link](new renk(kirmizi,yesil,mavi));
[Link]("ABCDEFGHIJKLMNOPQRSTUVWXYZ",50,33);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
Bu programda kirmizi deðeri 100, yesil deðeri 255 ve mavi degeri de 125 alýnmýº ve setColor
deyimiyle yeni renk tanýmlanmýºtýr. Arka plan rengi ise public void setBackground(Color c)
Ayný programýn JApplet eºidi olan, ayný zamanda java komutuyla kendi çerçevesini de
oluºturabilen bir eºdeðerini verelim. Renk2D sýnýfýnda Graphics2D sýnýfý kullanýlmaktadýr.
Grafik kalitesini karºýlaºtýrabilirsiniz.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void init()
kirmizi=100;
yesil=255;
mavi=125;
setBackground(new Color(0,0,255));
setForeground(new Color(kirmizi,yesil,mavi));
Graphics2D g2 = (Graphics2D) g;
[Link](new Color(kirmizi,yesil,mavi));
[Link]("ABCDEFGHIJKLMNOPQRSTUVWXYZ",50,33);
[Link](new WindowAdapter() {
});
[Link]().add("Center", applet);
[Link]();
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new Dimension(550,100));
[Link]();
[Link]
Swing sýnýfýnda renk seçimini yapabilmek amacýyla JColorChooser adlý bir program
tanýmlanmýºtýr. Bu programý kullanarak renk grafik kutusunun rengini deðiºtirebildiðimiz
renkSeciciSWF swing JFrame programý aºaðýda verilmiºtir.
import BasicWindowMonitor;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JButton renkdegistir;
Color r=[Link];
Container c;
public renkSeciciSWF_2000()
super("JColorChoser ");
c=getContentPane();
[Link](new FlowLayout()) ;
[Link](this);
[Link](renkdegistir);
if(r==null)
r=[Link];
[Link](r);
repaint();
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
//ana program
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
[Link] [Link]
[Link] [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.6-6.9 renkSeciciSWF_2000.java java swing frame programý ve JcolorChooser
renk seçme programý
metodu java kütüphanesinde yer almaktadýr. ShowDialog metodu bize Color sýnýfýndaki renk
deðiºkenini aktarmakta ve
[Link](r);
JFrame ve JApplet arasýndaki farký anlamaya biraz daha katkýda bulunmasý amacýyla ayný
programý bir de JApplet olarak verelim :
import BasicWindowMonitor;
JButton renkdegistir;
Color r=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Container c;
c=getContentPane();
[Link](new FlowLayout()) ;
[Link](this);
[Link](renkdegistir);
if(r==null)
r=[Link];
[Link](r);
repaint();
JFrame ve JApplet programlarýnýn en büyük farký JFrame ana programdan (main) çalýºtýðý
halde JApplet’in bir browser programýndan çalýºtýrýlýyor olmasýdýr. Burada da en dýº çerçeve
dýºýnda JFrame ile ayný görüntüyü elde ederiz.
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.10 renkSeciciSWA_2000.java programýnýn Appletviewer’daki çýktýsý
Appletlerde yazý kontrolu Font sýnýfý ný kullanarak yapýlýr. ªekil 5.3.1 de java 1.1.5 de
kullanýlabilecek tüm yazý stillerinin (font) listesini veren [Link] programýný görüyoruz.
Program 6.8 : [Link] programý, java kütüphanesinde mevcut olan yazý sitillerini
gösterir
import [Link].*;
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.11 [Link] programý, java kütüphanesinde mevcut olan yazý sitillerini gösterir
applet programýnýn sonuçlarý.
Program 6.9 : [Link] programý, java kütüphanesinde mevcut olan yazý sitillerini
gösterir
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
setBackground([Link]);
setForeground([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Graphics2D g2 = (Graphics2D) g;
String stilListesi[];
stilListesi=getToolkit().getFontList();
int y=15;
for(int i=0;i<[Link];i++)
[Link](stilListesi[i],15,y);
y+=15;
[Link](new WindowAdapter() {
});
[Link]().add("Center", applet);
[Link]();
[Link]();
[Link](new Dimension(550,300));
[Link]();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.12 : [Link] program çýktýsý
Bu yazý sitillerinden birisi asaðýda verilen yazý tiplerinden birisiyle beraber ve verilen belli bir
yazý boyutunda gösterilebilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 6.10 : [Link] programý, java kütüphanesindeki Font uygulamasýný
gösterir
import [Link].*;
import [Link];
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
kirmizi=100;
yesil=255;
mavi=125;
setBackground(new Color(0,0,255));
setForeground(new Color(kirmizi,yesil,mavi));
Graphics2D g2 = (Graphics2D) g;
[Link](new Color(kirmizi,yesil,mavi));
setBackground(new Color(0,0,255));
Font font=[Link]();
[Link](new Font([Link](),[Link],24));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("ABCDEFGHIJKLMNOPQRSTUVWXYZ",50,33);
[Link](new Font([Link](),[Link],12));
[Link](new WindowAdapter() {
});
[Link]().add("Center", applet);
[Link]();
[Link]();
[Link](new Dimension(550,200));
[Link]();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
6.5 ÇiZGi ÇiZiMi
Javada çizgi çizmek için kullanýlan temel metot Graphics sýnýfýnda drawLine metotu dur. Bu
metot Graphics sýnýfýnda tanýmlanmýºtýr. Kurucu metotu :
import [Link].*;
import [Link];
import [Link].*;
[Link](new Color(0,0,0));
[Link](new Font("SansSerif",[Link],24));
[Link](10,10,230,95);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import renk;
public cizgiSWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
super("çizgi çizimi");
setBackground(bg);
setForeground(fg);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](l);
[Link](new BasicStroke(1f,BasicStroke.CAP_ROUND,
[Link](l1);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](l);
[Link](new BasicStroke(1f,BasicStroke.CAP_ROUND,
[Link](l1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Noktalý çizgiyi çizer.
Burada bizim için yeni bir kavram olan noktalý çizgi çizmenin detaylarýna biraz göz atalým.
Noktalýçizgi oluºturmak için temel olarak setStroke metodunu kullanýyoruz. Bu metodun
içinde Basic Stroke metodu bir nesne yaratýyoruz. BasicStroke türü nesne çizgi kalýnlýðý, çizgi
baðlama sitili,çizgi ucu bitiº sitili ve çizgi-boºluk bilgisi içerir. Çizgi kalýnlýðý çizgi istikametine
dik olarak ölçülür. Çizgi kalýnlýðý 1f (buradaki f sayýnýn float temel deðiºken türü olduðunu
belitir) 0.35277 milimetreye eºittir. Yalnýz transformasyon kullanýldýðýnda bu deðiºebilir.
Transformasyonlara biraz sonra deðineceðiz.
Çizgi baðlama sitili iki çizginin birbirine baðlandýðý noktadaki ºeklini belirler. BasicStroke
sýnýfýnda 3 baðlanma sitili mevcuttur. Bunlar :
JOIN_BEVEL
JOIN_MITER
JOIN_ROUND
sitilleridir. Çizgi ucu bitiº sitilleri boº çizgi ucunun ºeklini belirtir. Yine
temel olarak 3 BasicStroke çizgi ucu bitiº sitili mevcuttur. Bunlar :
CAP_BUTT
CAP_ROUND
CAP_SQUARE
sitilleridir. Çizgi boºluk bilgisi birbirini takip eden ºeffaf ve görünür çizgi
parçacýklarý ve bunlarýn boylarýný tanýmlar. Bir ara boºluk deðiºkeni ve
çizgi boºluk çizgi boºluk olmak üzere bir seriden oluºur. Son olarak
son rakam serinin hangi elemanýndan çizime baºlanacaðýný gösterir
Örneðin:
[Link](new BasicStroke(1,BasicStroke.CAP_ROUND,
[Link](new BasicStroke(1,BasicStroke.CAP_ROUND,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java Graphics sýnýfýnda dikdörtgen çizmek için kullanýlan temel metot drawRect metotudur.
Bu metot Graphics sýnýfýnda tanýmlanmýºtýr. Bu metotlarýn tanýmý :
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
kullanýlýr.
[Link]([Link]);
[Link](dikdortgen2);
kullanýlabilir. Graphics2D de tek renk yerine deðiºen bir renk profiliyle boyamak da
mümkündür. Örneðin :
[Link](kirmizidanbeyaza);
[Link](dikdortgen4);
kodu dikdörtgeni kýrmýzýdan beyaza dönüºen bir spekturumla boyar. Tüm bu kodu bir örnek
problemde gösterelim :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public dikdortgenSWF_2000()
super("Dikdörtgen çizimi");
setBackground([Link]);
setForeground(siyah);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](dikdortgen1);
[Link](siyah);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](dikdortgen2);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](dikdortgen3);
[Link](kirmizidanbeyaza);
[Link](dikdortgen4);
GradientPaint kirmizidanmaviye=new
GradientPaint(250,150,kirmizi,350,190,[Link]);
[Link](kirmizidanmaviye);
[Link](dikdortgen5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](dikdortgen5);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,300);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](true);
Bu programýn çýktýsý :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Public abstract void fillRoundRect(
int x1, // üst tepe noktanýn x koordinatý
int y1, // üst tepe noktanýn y koordinatý
int en, // dikdörgenin geniºliði
int yukseklik, // dikdörtgenin yüksekliði
int koseeni, // yuvarlak kosenin eni
int koseyuksekligi )// yuvarlak kosenin yuksekligi
metotu da paralel olarak tanýmlanmýºtýr. Yine bir örnek problemde bu tanýmý kullanacak
olursak :
import [Link];
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new [Link](x,
y,dikdortgenEn,dikdortgenYukseklik,xKöºeYarýçapý,yKöºeYarýçapý));
[Link]([Link]);
RoundRectangle2D dikdortgen2=new
[Link](50,50,100,40,15,15);
[Link](dikdortgen2);
[Link]([Link]);
RoundRectangle2D dikdortgen2=new
[Link](50,50,100,40,15,15);
[Link](dikdortgen2);
kodu kullanýlabilir. Elbette bir önceki örnekte olduðu gibi spektrumlu boyama da mümkündür.
Tüm bu kodu bir örnek problemde gösterelim
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public yuvarlakKoseliDikdortgenSWF_2000()
setBackground([Link]);
setForeground(siyah);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](dikdortgen1);
[Link](siyah);
[Link](dikdortgen2);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
RoundRectangle2D dikdortgen3=new
[Link](50,150,100,40,15,15);
[Link](dikdortgen3);
[Link](kirmizidanbeyaza);
RoundRectangle2D dikdortgen4=new
[Link](250,50,100,40,15,15);
[Link](dikdortgen4);
GradientPaint kirmizidanmaviye=new
GradientPaint(250,150,kirmizi,350,190,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kirmizidanmaviye);
RoundRectangle2D dikdortgen5=new
[Link](250,150,100,40,15,15);
[Link](dikdortgen5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](dikdortgen5);
//=====================================================
yuvarlakKoseliDikdortgenSWF_2000 pencere=
new yuvarlakKoseliDikdortgenSWF_2000();
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.20 çeºitli köºesi yuvarlatýlmýº dikdörtgen çizimlerinin
yuvarlakKoselidikdortgenSWF_2000 JFrame çýktýsýnda görünümü
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new Font("SansSerif",[Link],12));
g.draw3DRect(10,10,100,100,true);
g.fill3DRect(120,10,100,100,true);
g.draw3DRect(10,120,100,100,false);
g.fill3DRect(120,120,100,100,false);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
public donmusDikdortgenSWF_2000()
setBackground([Link]);
setForeground(siyah);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](at);
[Link](dikdortgen1);
[Link](siyah);
[Link](dikdortgen2);
[Link](new AffineTransform());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](at1);
[Link](dikdortgen3);
[Link](new AffineTransform());
[Link](kirmizidanbeyaza);
[Link](at2);
[Link](dikdortgen4);
[Link](new AffineTransform());
GradientPaint kirmizidanmaviye=
new GradientPaint(250,150,kirmizi,350,190,[Link]);
[Link](kirmizidanmaviye);
[Link](dikdortgen5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](at3);
[Link](dikdortgen5);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new AffineTransform());
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
ªekli x,y noktasý etrafýnda açýDerece kadar saat akranýnýn tersi yönde döndürür.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekli x ekseninde xÇeliºi kadar, y ekseninde yÇekiºi kadar uzatýr (orijinal ºekilden elastik
ve üst köºesi tutturulmuº ºekilde)
AffineTransform at1=
[Link](xBoyutFaktörü,yBoyutFaktörü);
AffineTransform at3=
[Link](xTaºýmaFaktörü,yTaºýmaFaktörü);
[Link](new AffineTransform());
metodu çaðýrýlabilir.
Graphics sýnýfýOval çizimi için drawOval ve fillOval metotlarý kullanýlýr bu metotlarýn tanýmý
ºöyledir :
(x1,y1) koordinatýnýn ovalle iliºkisini daha iyi anlayabilmek için aºaðýdaki grafiði verebiliriz :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.23 Oval tanýmý koordinat sistemi
import [Link];
import [Link].*;
public class daireCiz extends Applet
{
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Graphics ile bir ovalin tamamýný deðilde sadece bir bölümünü çizmek dilenilirse, drawArc ve
fillArc metotlarý kullanýlabilir. Bu metotlarýn tanýmý :
import [Link];
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.25 [Link] apleti
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](elips1);
[Link](elips1);
metodunu kullanýrýz.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
final static Color beyaz=[Link];
public elipsSWF_2000()
super("Elips çizimi");
setBackground([Link]);
setForeground(siyah);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](elips1);
[Link](siyah);
[Link](elips2);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](elips3);
[Link](kirmizidanbeyaza);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](elips4);
GradientPaint kirmizidanmaviye=new
GradientPaint(250,150,kirmizi,350,190,[Link]);
[Link](kirmizidanmaviye);
[Link](elips5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](elips5);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.26 çeºitli oval (elips) çizimlerinin elipsSWF_2000JFrame çýktýsýnda
görünümü
Graphics2D sýnýfýnda bir grafiði boyarken bir resim dosyasýnýn içinde tanýmlanan bir motifi de
kullanabiliriz.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
TexturePaint tp = getImageTexture("[Link]");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public textureElipsSWF_2000()
super("Elips çizimi");
setBackground(beyaz);
setForeground(siyah);
try {
[Link](img, 0);
[Link](0);
} catch (Exception e) {}
Graphics g = [Link]();
[Link](img, 0, 0, this);
//************
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Graphics2D g2 = (Graphics2D)g;
[Link](tp);
[Link](elips1);
[Link](siyah);
[Link](elips2);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](elips3);
[Link](kirmizidanbeyaza);
[Link](elips4);
[Link](tp);
[Link](elips5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](elips5);
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args)
[Link](new BasicWindowMonitor());
[Link](300,300);
[Link](true);
//************
[Link]
ªekil 6.27 çeºitli oval (elips) çizimlerinin ve arkaplan resimli boyama iºleminin
textureElipsSWF_2000JFrame çýktýsýnda görünümü
metodu kullanýlarak aktarýlmýº ve aynen yeni bir renk gibi çizim ortamýnda kullanýlmýºtýr.
ªimdi de Graphics2D metoduyla arc çizdirmeye bakalým arc yukarda da bahsettiðimiz gibi
tamamlanmamýº bir elipstir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public arcSWF_2000()
super("arc çizimi");
setBackground([Link]);
setForeground(siyah);
Graphics2D g2 = (Graphics2D)g;
[Link]([Link]);
[Link](arc1);
[Link](siyah);
[Link](arc2);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
BasicStroke.JOIN_ROUND,3f,new float[] {10f},0f));
[Link]([Link]);
[Link](arc3);
[Link](kirmizidanbeyaza);
[Link](arc4);
GradientPaint kirmizidanmaviye=new
GradientPaint(250,150,kirmizi,350,190,[Link]);
[Link](kirmizidanmaviye);
[Link](arc5);
[Link](new BasicStroke(2f,BasicStroke.CAP_ROUND,
[Link]([Link]);
[Link](arc5);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
Graphics sýnýfýnda Açýk ve kapalý polygon ºekilleri çizmek için drawPolygon ve fillPolygon
metotlarý kullanýlýr. Metotlarýn tanýmý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public Polygon(
int x[], // x koordinat vektörü
int y[], // y koordinatý vektörü
int nokta sayýsý) // nokta sayýsý
Metot tanýmlarýndan da görüldüðü gibi polygon int türü vektörle çizilebileceði gibi bu vektörü
içinde barýndýran Polygon sýnýfý bir nesne kullanýlarak ta çizilebilir.
import [Link];
import [Link].*;
public class ucgenCiz extends Applet
{
public void paint(Graphics g)
{
int x[]={10,(int)(10+100*[Link]([Link]/3.0)),110,10};
int y[]={100,(int)(100-100*[Link]([Link]/3.0)),100,100};
int x1[]={130,(int)(130+100*[Link]([Link]/3.0)),230,130};
int y1[];
y1=y;
[Link](new Color(0,0,255));
[Link](x,y,4);
[Link](x1,y1,4);
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.29 [Link] programý ve apleti
Graphics2D programýnda grafik çizdirmek için kullanýlan metodlar Graphics sýnýfýna göre
oldukça deðiºiktir. Burada önce örnek programýmýzý verelim:
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public polygonSWF()
super("Polygon çizimi");
int x[]={55,67,109,73,83,55,27,37,1,43};
int y[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2=(Graphics2D)g;
[Link](x[0],y[0]);
for(int i=1;i<[Link];i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{[Link](x[i],y[i]);}
[Link]();
[Link](200,200);
for(int i=0;i<20;i++)
[Link]([Link]/10.0);
[Link](new Color((int)([Link]()*256),(int)([Link]()*256),
(int)([Link]()*256)));
[Link](yildiz);
[Link](new BasicStroke(2));
[Link]([Link]);
[Link](yildiz);
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.30 çeºitli yýldýzlarýn (polygonun) çizim ve döndürme iºlemi polygonSWF
JFrame çýktýsýnda görünümü
bu programda önce
int x[]={55,67,109,73,83,55,27,37,1,43};
int y[]={0,36,36,54,96,72,96,54,36,36};
[Link](x[0],y[0]);
for(int i=1;i<[Link];i++)
{[Link](x[i],y[i]);}
[Link]();
[Link](yildiz);
ile çizilmiº, ve
[Link](yildiz);
[Link]([Link]/10.0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
komutu ile döndürülmüºtür. Programda setPAint kullanarak tesadüfi renkler seçilmiº ve yýldýz
çizimi doldurulmuºtur.
Programda kullanýlan
Terimine özellikle dikkatinizi çekmek isteriz. Bu terim GeneralPath nesnesi yýldýzý tanýmlar.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public generalPathSWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
setBackground([Link]);
setForeground(siyah);
Dimension boyut=getSize();
int dx=[Link];
int dy=[Link];
[Link](siyah);
[Link](new BasicStroke(3));
g2.draw3DRect(0,0,dx-3,dy-3,true);
g2.draw3DRect(3,3,dx-7,dy-7,false);
[Link](20,20);
//quadratik ekleme
[Link](160,120,245,45);
//kübik ekleme
[Link](195,95,295,145,245,195);
[Link](-80,110,345,110,20,195);
[Link](400,250,200,250,20,20);
[Link](sekil);
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args)
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
Bu çizimdeki çizginin oldukça düzgün olduðuna dikkatinizi çekeriz. Bunu saðlayan temel
komut :
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Komutudur. Bu komut çizgileri daha düzgün hale getirir, fakat belli bir hesap ve hafýza
kapasitesi harcar. Programý bu komutu çýkararak da çalýºtýrýnýz ve aradaki farklarý inceleyiniz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
GeneralPath sekil=new GeneralPath(GeneralPath.WIND_EVEN_ODD);
[Link](20,20);
//quadratik ekleme
[Link](160,120,245,45);
//kübik ekleme
[Link](195,95,295,145,245,195);
[Link](sekil);
komutuyla çizdirilmiºtir.
[Link](sekil);
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public curve2SWF_2000()
Graphics2D g2 = (Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
setBackground([Link]);
setForeground(siyah);
Dimension boyut=getSize();
int dx=[Link];
int dy=[Link];
[Link](siyah);
g2.draw3DRect(0,0,dx-3,dy-3,true);
g2.draw3DRect(3,3,dx-7,dy-7,false);
[Link](siyah);
[Link](qc2);
[Link]([Link]);
[Link](qc2_1);
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args)
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
ªekil 6.32 ikinci dereceden genel eðri çizimi, curve2SWF_2000, JFrame çýktýsýnda
görünümü
ªimdide üçüncü dereceden eðri uyduran bir program koduna göz atalým :
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class curve3SWF_2000 extends JFrame {
public curve3SWF_2000()
Graphics2D g2 = (Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
setBackground([Link]);
setForeground(siyah);
Dimension boyut=getSize();
int dx=[Link];
int dy=[Link];
[Link](siyah);
g2.draw3DRect(0,0,dx-3,dy-3,true);
g2.draw3DRect(3,3,dx-7,dy-7,false);
[Link](siyah);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](cc3);
[Link]([Link]);
[Link](cc3_1);
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,300);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.33 üçüncü dereceden genel eðri çizimi, curve3SWF_2000, JFrame çýktýsýnda
görünümü
Java dili sadece .gif ve .jpg standartlarýndaki resimleri gösterebilir. Resim önce getImage
metotuyla bir Image sýnýfý nesneye yuklenir, sonra drawImage metotuyla gösterilir.
Bir örnek problemle resim çizimini biraz daha belirgin hale getitelim :
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
res=getImage(getDocumentBase(),"[Link]");
[Link](res,1,1,this);
/*
int en=[Link](this);
int yukseklik=[Link](this);
[Link](res,1,90,en*2,yukseklik*2,this);
*/
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 6.34 : Resmin java üzerinden aktarýlmasý, [Link]
Java grafik çizim olasýlýklarý burada verilenden çok aha geniº boyutludur. Bu bölümde
veremediðimiz bir çok detayý javanýn parasýz olarak çekebileceðiniz döküman
kütüphanesinde bulabilirsiniz.
6.13 ALIªTIRMALAR
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class ciz1 extends Applet
{
private String s ="Bunu drawString Metotuyla yazdir";
private char c[]={'c','h','a','r','s',' ','8'};
private byte b[]={'b','y','t','e',75,76,77};
public void init()
{
Color c=new Color(0,0,255);
setBackground(c);
}
[Link]
2. Ýki boyutlu plot çizimi amacýyla bir program paketi hazýrlanmýºtýr. Bu paket temel
olarak üç java programýndan oluºmaktadýr. Birinci program dosyadan plot bilgisini
okuyan [Link] programýdýr. Çizilecek Plotla ilgili en temel bilgi [Link] dosyasýnda
bulunmaktadýr. Bu dosyadaki ilk satýr Pot baºlýðýný, ikinci satýr x ekseni baºlýðýný, üçüncü
satýr y ekseni baºlýðýný, dördüncü satýr çizilecek iki boyutlu plot sayýsýný (okunacak dosya
sayýsýný), beºinci ve sonraki satýrlar plot bilgisinin olduðu dosya ismi, çizgi çizim türü, ve
integer RGB renk deðerlerini vermektedir. Çizgi çizim türlerini bazýlarý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// plottype = 23 eºkenar dörtgen
// plottype = 24 beºgen
// plottype = 25 altýgen
eðer çizgi türü 10 olarak tanýmlanmýºsa kullanýlacak olan karakterinde verilmesi gerekir
[Link] 10 * 0 0 255 gibi. Aºaðýda örnek bir [Link] dosyasý deðeri verilmektedir.
türkçe yazý
x ekseni
y ekseni
[Link] 26 0 0 255
[Link] 5 0 0 255
Plot bilgi dosyasýnda iki kolon olarak x,y plot bilgisi verilir. Küçük bir örnek dosyasý verecek
olursak :
11
24
39
4 16
5 25
6 36
7 49
Burada bilgi dosyadan okunmaktadýr. Dosya okuma yazma komutlarýný daha detaylý olarak
10. bölümde inceleyeceðiz.
//======================================================
// Numerical Analysis package in java
// Plot class to plot 2D data
// Dr. Turhan Coban
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// =====================================================
import [Link].*;
// plottype = 24 pentagon
// plottype = 25 hexagon
public char ch[]; // plot character (used with plottype 10)
public int xntic; // number of tics in x axis
public int yntic; // number of tics in y axis
BufferedReader fin;
BufferedReader ffile;
File plotFile;
File lineDataFile;
public void set_plotwindow(int width,int height,double xip,double yip,double dxp,double dyp)
{
//sets rectangular plot window
xabsmin = (int)(width*(xip+0.2));
yabsmin = (int)(height*(yip+0.2));
abswidth = (int)(width*dxp);
absheight = (int)(height*dyp);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double xtemp,ytemp;
label=pl;
xlabel=xl;
ylabel=yl;
nline=[Link];
xntic=xnt;
yntic=ynt;
xgridon=xgo;
ygridon=ygo;
n=new int[nline];
red=new int[nline];
green=new int[nline];
blue=new int[nline];
plottype=new int[nline];
ch=new char[nline];
//read all data to determine limit values
String fn[];
fn=new String[nline];
int i,j;
for(i=0;i<nline;i++)
{
fn[i]=ifn[i];
plottype[i]=ipt[i];
if(plottype[i] == 10) ch[i]='*';
red[i]=ir[i];
green[i]=ig[i];
blue[i]=ib[i];
j=0;
n[i]=0;
//open ffile
try
{
ffile=new BufferedReader(new FileReader(fn[i]));
} catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
try
{
while(ffile!=null)
{
xtemp=[Link](ffile);
ytemp=[Link](ffile);
if(xtemp<xmin) xmin=xtemp;
if(xtempxmax) xmax=xtemp;
if(ytemp<ymin) ymin=ytemp;
if(ytempymax) ymax=ytemp;
n[i]++;
}
} catch(EOFException e_eof) { [Link]();}
if(i==0) nmax=n[i];
else
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(n[i]nmax) nmax=n[i];
}
x=new double[nline][nmax];
y=new double[nline][nmax];
for(i=0;i<nline;i++)
{
//open ffile
try{
ffile=new BufferedReader(new FileReader(lineDataFile));
} catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
for(j=0;j<n[i];j++)
{
x[i][j]=[Link](ffile);
y[i][j]=[Link](ffile);
}
}
}
set_plotwindow(400,400,0.1,0.1,0.9,0.9);
}
//
// A sample data file input :
//
// 4 10 10 1 1
// [Link] 22 0 0 0
// [Link] 21 0 255 0
// [Link] 0 0 255 0
// [Link] 0 0 0 255
//
// see above for meaning of plot types
xmin=9.99e50;
xmax=-9.99e50;
ymin=9.99e50;
ymax=-9.99e50;
xntic=8;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yntic=8;
double xtemp,ytemp;
try{
fin=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
label=[Link](fin);
xlabel=[Link](fin);
ylabel=[Link](fin);
nline=[Link](fin);
xntic=[Link](fin);
yntic=[Link](fin);
xgridon=[Link](fin);
ygridon=[Link](fin);
n=new int[30];
red=new int[30];
green=new int[30];
blue=new int[30];
plottype=new int[30];
ch=new char[30];
//read all data to determine limit values
String fn[];
fn=new String[nline];
int i,j;
for(i=0;i<nline;i++)
{
fn[i]=[Link](fin);
plottype[i]=[Link](fin);
if(plottype[i] == 10) ch[i]=[Link](fin);
red[i]=[Link](fin);
green[i]=[Link](fin);
blue[i]=[Link](fin);
j=0;
n[i]=0;
//open ffile
try{
ffile=new BufferedReader(new FileReader(fn[i]));
} catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
try{
while(ffile!=null)
{
xtemp=[Link](ffile);
ytemp=[Link](ffile);
if(xtemp<xmin) xmin=xtemp;
if(xtempxmax) xmax=xtemp;
if(ytemp<ymin) ymin=ytemp;
if(ytempymax) ymax=ytemp;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
n[i]++;
}
} catch(EOFException e_eof)
{
//close ffile
try{
[Link]();
} catch(IOException e)
{
[Link]("Error Closing File\n"+[Link]());
[Link](1);
}
} //End of EOFException
if(i==0) nmax=n[i];
else
{
if(n[i]nmax) nmax=n[i];
}
}
//close ffile
try{
[Link]();
} catch(IOException e)
{
[Link]("Error Closing File\n"+[Link]());
[Link](1);
}
x=new double[nline][nmax];
y=new double[nline][nmax];
//re-read the data again to load it
for(i=0;i<nline;i++)
{
//open ffile
try{
ffile=new BufferedReader(new FileReader(fn[i]));
} catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
for(j=0;j<n[i];j++)
{
x[i][j]=[Link](ffile);
y[i][j]=[Link](ffile);
}
//close ffile
try{
[Link]();
} catch(IOException e)
{
[Link]("Error Closing File\n"+[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](1);
}
}
set_plotwindow(400,400,0.1,0.1,0.9,0.9);
//close fin
try{
[Link]();
} catch(IOException e)
{
[Link]("Error Closing File\n"+[Link]());
[Link](1);
}
}
//======================================================
// Numerical Analysis package in java
// PlotShapes class
// This class convert graphic draw methods to
// plot coordinates and gives additional plotting methods
// Dr. Turhan Coban
// =====================================================
import [Link].*;
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// ymax : maximum y value (real number)
// g : graphic object that actual drawing is done through
g=gi;
xabsmin=xabsmini;
yabsmin=yabsmini;
absheight=absheighti;
abswidth=abswidthi;
xmin=xmini;
xmax=xmaxi;
ymin=ymini;
ymax=ymaxi;
}
} //end of [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int h=[Link]().getHeight();
int w=h-2;
[Link](s,
(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
} //end of [Link]
}//end of drawRect
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//draw a series of x axis tics
double dtic=(xmax-xmin)/ticNumber;
double x1=xmin;
double y1=ymin;
if(ticSide==0)
{
for(int i=0;i<=ticNumber;i++)
{
drawLine(0,x1,y1,x1,(y1-ticHeight));
x1=x1+dtic;
}
}
else
{
for(int i=0;i<=ticNumber;i++)
{
drawLine(0,x1,y1,x1,(y1+ticHeight));
x1=x1+dtic;
}
}
}
for(int i=0;i<=ticNumber;i++)
{
drawLine(0,x1,y1,(x1+ticWidth),y1);
y1=y1+dtic;
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<=ticNumber;i++)
{
drawLine(0,x1,ymin,x1,ymax);
x1=x1+dtic;
}
}
//draw x numbers
double dtic=(xmax-xmin)/ticNumber;
double x1=xmin;
double y1=ymin;
String s;
s=" ";
for(int i=0;i<=ticNumber;i++)
{
s=[Link]([Link](x1*100.0)/100.00);
[Link](s,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)+20);
x1=x1+dtic;
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void drawXLabel(String xLabel)
{
// draw x labels
double x1=xmin+(xmax-xmin)/2.0;
double y1=ymin;
[Link](xLabel,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)+30);
}
public void
drawPlotLines(int i,int plottype[],double x[][],double y[][],int n[],char ch[])
{
int j;
//draw lines
if(plottype[i]==0)
{
for(j=0;j<n[i]-1;j++)
{
if((x[i][j]=xmin && x[i][j]<=xmax )
&& (y[i][j]=ymin && y[i][j]<=ymax))
{
if((x[i][j+1]=xmin && x[i][j+1]<=xmax) &&
(y[i][j+1]=ymin && y[i][j+1]<=ymax))
{
drawLine(0,x[i][j],y[i][j],x[i][j+1],y[i][j+1]);
}
else if(x[i][j+1]xmax)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],xmax,(a+b*xmax));
}
else if(y[i][j+1]ymax)
{
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],(ymax-a)/b,ymax);
}
else if(x[i][j+1]xmax && y[i][j+1]ymax)
{
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],(ymax-a)/b,(a+b*xmax));
}
}
else if((x[i][j+1]=xmin && x[i][j+1]<=xmax )
&& (y[i][j+1]=ymin && y[i][j+1]<=ymax))
{
if(x[i][j]<xmin)
{
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j+1]-b*x[i][j+1];
drawLine(0,xmin,(a+b*xmin),x[i][j+1],y[i][j+1]);
}
if(y[i][j]<ymin)
{
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j+1]-b*x[i][j+1];
drawLine(0,(ymin-a)/b,ymin,x[i][j+1],y[i][j+1]);
}
}
}//end of for(j=0
}//end of if(plottype
//draw characters
else if(plottype[i]==10)
{
for(j=0;j<n[i];j++)
{
if((x[i][j]=xmin && x[i][j]<=xmax )
&& (y[i][j]=ymin && y[i][j]<=ymax))
{ drawChar(ch[i],x[i][j],y[i][j]); }
}//end of for(j=0;
}//end else if(plottype[i]==10)
//draw rectangles
else if(plottype[i]==20)
{
for(j=0;j<n[i];j++)
{
if((x[i][j]=xmin && x[i][j]<=xmax )
&& (y[i][j]=ymin && y[i][j]<=ymax))
{ drawRect(x[i][j],y[i][j],4,4); }
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}//end of for(j=0;
}//end else if(plottype[i]==20)
//draw circle
else if(plottype[i]==21)
{
for(j=0;j<n[i];j++)
{
if((x[i][j]=xmin && x[i][j]<=xmax )
&& (y[i][j]=ymin && y[i][j]<=ymax))
{ drawOval(x[i][j],y[i][j],4,4); }
}//end of for(j=0;
}//end else if(plottype[i]==21)
else if(plottype[i]=22 && plottype[i]<=27)
{
for(j=0;j<n[i];j++)
{ if((x[i][j]=xmin && x[i][j]<=xmax )
&& (y[i][j]=ymin && y[i][j]<=ymax))
{drawPolygon(x[i][j],y[i][j],5,(plottype[i]-19));}
}//end of for(j=0;
}//end else if(plottype[i]==21..27)
}
}
//======================================================
// Numerical Analysis package in java
// PlotApplet class to plot 2D data
// Dr. Turhan Coban
// =====================================================
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import PlotShapes;
import Plot;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//adding max-min prompts and input fields
//label
//xaxis
//yaxis
// 4 10 10 1 1
// [Link] 22 0 0 0
// [Link] 21 0 255 0
// [Link] 0 0 255 0
// [Link] 0 0 0 255
int xnt=10;
int ynt=10;
int xgo=1;
int ygo=1;
String il=new String("label");
String xl=new String("x axis");
String yl=new String("y axis");
String ifn[]=new String[4];
ifn[0]="[Link]";
ifn[1]="[Link]";
ifn[2]="[Link]";
ifn[3]="[Link]";
int ipt[]=new int[4];
int ib[]=new int[4];
int ir[]=new int[4];
int ig[]=new int[4];
ipt[0]=22;
ipt[1]=21;
ipt[2]=0;
ipt[3]=0;
ir[0]=0;
ig[0]=0;
ib[0]=0;
ir[1]=0;
ig[1]=255;
ib[1]=0;
ir[2]=0;
ig[2]=255;
ib[2]=0;
ir[3]=0;
ig[3]=255;
ib[3]=0;
try{
//p1=new Plot(il,xl,yl,xnt,ynt,xgo,ygo,ifn,ipt,ir,ig,ib);
p1=new Plot();
} catch(IOException ioe) {[Link]("IOException in opening Plot");}
promptXmin=new Label("Xmin ");
inputXmin=new TextField(5);
promptXmax=new Label("Xmax ");
inputXmax=new TextField(5);
promptYmin=new Label("Ymin ");
inputYmin=new TextField(5);
promptYmax=new Label("Ymax ");
inputYmax=new TextField(5);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
add(promptXmin);
add(inputXmin);
add(promptXmax);
add(inputXmax);
add(promptYmin);
add(inputYmin);
add(promptYmax);
add(inputYmax);
}
}//end of method
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
3. drawRect ve fillRect metotlarýný kullanarak biri dolu diðeri sadece bir çizgi olan iki
dikdörtgen çiz.
1. Oval ve fillOval metotlarýný kullanarak biri dolu diðeri sadece bir çizgi olan iki daire çiz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
2. Paint2D metodlarýndan yararlanarak biri dolu diðeri sadece bir çizgi olan iki eºkenar
dörtgen çizdir.
import [Link];
import [Link].*;
4. drawPolygon ve fillPolygon metotlarýný kullanarak biri dolu diðeri sadece bir çizgi olan
iki eºkenar üçgen çiz.
import [Link].*;
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public final static renk camgobegi=new renk(0,255,255);
public final static renk koyugri=new renk(64,64,64);
public final static renk gri=new renk(128,138,128);
public final static renk yesil=new renk(0,255,0);
public final static renk acikgri=new renk(192,192,192);
public final static renk mor=new renk(255,0,255);
public final static renk portakal=new renk(255,200,0);
public final static renk pembe=new renk(255,175,175);
public final static renk beyaz=new renk(255,255,255);
public final static renk sari=new renk(255,255,0);
public final static renk acikmavi=new renk(150,206,237);
public final static renk lacivert=new renk(0,0,128);
//burada kendi yeni renginizi tanýmlayabilirsiniz.
public renk(renk r)
{
super([Link](),[Link](),[Link]());
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getKYM()
{
return getRGB();
}
//metotlar
//static int HSBtoRGB(float hue,float saturation,float brightness)
//getRed(),getGreen(),getBlue(),getRGB()
}
import [Link].*;
import [Link].*;
import [Link];
import polar;
public static void drawYildiz1(Graphics g,int xi,int yi, int n,int yildizboyu,double aci )
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
polar P1=new polar();
for(int i=0;i<n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2+teta1;
[Link](R,teta1);
[Link](r,teta2);
[Link]((xi+(int)[Link]()),(yi-(int)[Link]()),
(xi+(int)[Link]()),(yi-(int)[Link]()));
double teta3=teta*(i+1)+[Link]/2.0+aci;
[Link](R,teta3);
[Link]((xi+(int)[Link]()),(yi-(int)[Link]()),
(xi+(int)[Link]()),(yi-(int)[Link]()));
[Link](xi,yi,
(xi+(int)[Link]()),(yi-(int)[Link]()));
[Link](xi,yi,
(xi+(int)[Link]()),(yi-(int)[Link]()));
public static void drawYildiz1(Graphics g,int xi,int yi, int n,int yildizboyu )
drawYildiz1(g,xi,yi,n,yildizboyu,0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} //drawYildiz1 metodu sonu
public static void drawYildiz(Graphics g,int xi,int yi, int n,int yildizboyu,double aci )
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2.0+teta1;
[Link](R,teta1);
[Link](r,teta2);
x[2*i]=xi+(int)[Link]();
y[2*i]=yi-(int)[Link]();
x[2*i+1]=xi+(int)[Link]();
y[2*i+1]=yi-(int)[Link]();
if(i==n)
x[2*i]=x[0];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
y[2*i]=y[0];
[Link](x,y,(2*n+2));
public static void fillYildiz(Graphics g,int xi,int yi, int n,int yildizboyu,double aci )
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2.0+teta1;
[Link](R,teta1);
[Link](r,teta2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x[2*i]=xi+(int)[Link]();
y[2*i]=yi-(int)[Link]();
x[2*i+1]=xi+(int)[Link]();
y[2*i+1]=yi-(int)[Link]();
if(i==n)
x[2*i]=x[0];
y[2*i]=y[0];
[Link](x,y,(2*n+2));
public static void fillYildiz1(Graphics g,int xi,int yi, int n,int yildizboyu,double aci )
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2.0+teta1;
[Link](R,teta1);
[Link](r,teta2);
x[2*i]=xi+(int)[Link]();
y[2*i]=yi-(int)[Link]();
x[2*i+1]=xi+(int)[Link]();
y[2*i+1]=yi-(int)[Link]();
if(i==n)
x[2*i]=x[0];
y[2*i]=y[0];
[Link](x,y,(2*n+2));
import [Link];
import [Link].*;
import yildiz;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import renk;
//[Link]([Link]);
[Link]([Link]);
setBackground([Link]);
[Link](g,100,100,3,100,0);
[Link]([Link]);
yildiz.drawYildiz1(g,100,100,3,100,0);
import [Link];
import [Link].*;
import yildiz;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double aci=0;
for(long j=0;j<5000;j++)
[Link]([Link]);
[Link](g,100,100,3,100,aci);
[Link]([Link]);
[Link](g,100,100,3,100,aci);
aci+=.001;
[Link]([Link]);
[Link](g,100,100,3,100,0);
7. Program 6.18 de verilen renk sýnýfýný test eden [Link] programýný inceleyiniz.
Ve applet çýktýsýný çalýºtýrýnýz.
import [Link].*;
import [Link];
import renk;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private int kirmizi,yesil,mavi;
kirmizi=150;
yesil=255;
mavi=125;
setBackground([Link]);
[Link](new renk(kirmizi,yesil,mavi));
[Link]("ABCDEFGHIJKLMNOPQRSTUVWXYZ",50,33);
06017
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
11. H6O2
import [Link].*;
import [Link].*;
import [Link];
import polar;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// kenarina olan mesafe
double teta=2.0*[Link]/n;
double R=eskenarcokgenboyu;
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
[Link](R,teta1);
x[i]=xi+(int)[Link]();
y[i]=yi-(int)[Link]();
if(i==n)
x[i]=x[0];
y[i]=y[0];
[Link](x,y,(n+1));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// bu eskenarcokgen cizime teta=pi/2+aci radyandan baslar
double teta=2.0*[Link]/n;
double R=eskenarcokgenboyu;
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
[Link](R,teta1);
x[i]=xi+(int)[Link]();
y[i]=yi-(int)[Link]();
if(i==n)
x[i]=x[0];
y[i]=y[0];
[Link](x,y,(n+1));
8. eskenarcokgen sýnýfýný test etmek amacýyla bir applet programý yazýnýz ve ekrana
beºken çizdiriniz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
9. eskenarcokgen sýnýfýný test etmek amacýyla bir JFrame programý yazýnýz ve ekrana
üçken çizdiriniz.
13.
H6O3
grafik sýnýfýndaki:
public abstract void drawRect(int x1,int y1, int en,int yükseklik)
metotundan yararlanarak H6O3 sinifinda
metotunu yaziniz. Bu metot dikdortgeni verilen açi kadar bir açýyla cizdirsin.
Ýmport [Link].*;
import [Link].*;
import [Link];
import polar;
public static void drawdikdortgen(Graphics g,int xi,int yi,int en,int boy,double aci )
double R=boy;
double r=en;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
polar P1=new polar();
int k=0;
//[Link](R,teta1);
x[0]=xi;
y[0]=yi;
double teta1=aci;
[Link](r,teta1);
x[1]=x[0]+(int)[Link]();
y[1]=y[0]-(int)[Link]();
teta1+=[Link]/2;
[Link](R,teta1);
x[2]=x[1]+(int)[Link]();
y[2]=y[1]-(int)[Link]();
teta1+=[Link]/2;
[Link](r,teta1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x[3]=x[2]+(int)[Link]();
y[3]=y[2]-(int)[Link]();
x[4]=xi;
y[4]=yi;
[Link](x,y,4);
public static void filldikdortgen(Graphics g,int xi,int yi,int en,int boy,double aci )
double R=boy;
double r=en;
int k=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x[0]=xi;
y[0]=yi;
double teta1=aci;
[Link](r,teta1);
x[1]=x[0]+(int)[Link]();
y[1]=y[0]-(int)[Link]();
teta1+=[Link]/2;
[Link](R,teta1);
x[2]=x[1]+(int)[Link]();
y[2]=y[1]-(int)[Link]();
teta1+=[Link]/2;
[Link](r,teta1);
x[3]=x[2]+(int)[Link]();
y[3]=y[2]-(int)[Link]();
x[4]=xi;
y[4]=yi;
[Link](x,y,4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link].*;
import [Link].*;
import dikdortgen;
import renk;
int en,boy,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label bos1;
Label bos2;
Label bos3;
Label renk1;
Label kirmizi;
Label mavi;
Label yesil;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
TextField kutukirmizi;
TextField kutumavi;
TextField kutuyesil;
[Link](new GridLayout(5,4));
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutu3=new Label("eni giriniz :");
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
renk1=new Label("renk");
kirmizi=new Label("kirmizi");
mavi=new Label("mavi");
yesil=new Label("yesil");
kutukirmizi=new TextField(4);
kutumavi=new TextField(4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutuyesil=new TextField(4);
xi1=300;
yi1=300;
en=150;
boy=100;
yaricap1=(int)[Link](100*100+150*150);
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+en);
[Link](""+boy);
[Link](""+aci1);
[Link]("255");
[Link]("200");
[Link]("0");
renk=new renk(255,200,0);
[Link](bos1);
[Link](bos2);
[Link](bos3);
[Link](kirmizi);
[Link](yesil);
[Link](mavi);
[Link](renk1);
[Link](kutukirmizi);
[Link](kutumavi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kutuyesil);
add(p,[Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
xi1=[Link]();
yi1=[Link]();
en=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
boy=[Link]();
aci1=[Link]();
int kirmizi1=[Link]();
int mavi1=[Link]();
int yesil1=[Link]();
renk=new renk(kirmizi1,mavi1,yesil1);
repaint();
[Link](renk);
[Link](g,xi1,yi1,en,boy,(aci1/180.0*[Link]));
[Link]([Link]);
[Link](g,xi1,yi1,en,boy,(aci1/180.0*[Link]));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Grafik kullanýcý arabirim programlarý, GUI, programýnýza kullanýcýnýn daha iyi anlýyabileceði
bir görünüº verme ve ayný zamanda grafik ekrandan girdi cve çýktý yapabilme amacýyla
oluºturulur. Kullanýcýya sunulan programýn onun rahatlýkla anlayabileceði bir formata sahip
olmasý günümüz programlamacýlýðýnda oldukça önemlidir. Reklamlarla büyüyen bir kuºak
için paket bazen paketin içindekinden bile önemli hale gelebilmektedir. Grafik Kullanýcýsý
Arabirim programlarý kullanýcýya sunduðumuz paketi oluºturmaktadýr.
Java’da temel grafik arabirim kütüphaneleri [Link] sýnýfýnda yer almaktadýr. Java 1.2 den
itibaren awt kütüphanesine ek olarak java swing grafik arabirim kütüphanesi [Link]
tanýmlanmýºtýr. Bu bölümde awt ve swing yapýlarýný paralel olarak vermeye çalýºacaðýz..
Yalnýz swing kütüphanesi kapsam olarak çok daha geniº olduðundan swing ile yapýlan tüm
iºlemlerin ve grafik arabirim alt programlarýný awt’de karºýlýklarý mevcut deðildir. Bir önceki
grafik çiziminde olduðu gibi grafik arabirim elemanlarýnýn tanýtýmý da oldukça geniº bir
yelpaze oluºturduðuundan mümkün olduðunca detay verilmeye çalýºýlsa bile tüm kapsamý bu
kitapta iºlemek mümkün deðildir. Örneðin java swing konusundaki kapsamlý bir kitap olan
“Java Swing , O’Reily basým evi” kitabý yaklaºýk 1200 sayfalýk bir kitabý sadece bu konuya
ayýrmýºtýr.
GUI metotlarý [Link] (Abstract windowing toolkit) paketinde yer almaktadýr. Bu pakette
Container ve Component isimli iki alt pakette yer almaktadýr. Her zaman kullandýðýmýz
Applet sýnýfý Component sýnýfýndan türiyen Panel sýnýfýnýn alt sýnýfýdýr. Yani Component
Appletlerin süper sýnýfýdýr.
· TextComponent
· TextField
· TextArea
· Button
· Label
· Checkbox
· List
· Choice
· Canvas
· Scrollbar
· Container
· Panel
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] sýnýfýnýn
· ScrollPane
· Window
· Frame
· Dialog
Paralel olarak [Link] paketinde yer alan grafik arayüz programlarýnda yer alan üst
seviye paketler Japplet, JDialog, JFrame,JWindow ve JComponent’dir
JcomboBox
JLabel
JList
JMenuBar
JPanel
JPopupMenu
JScrollBar
JScrollPane
JTable
JTree
JInternalFrame
JOptionPane
JProgressBar
JRootPane
JSeperator
JSlider
JSplitPane
JTabbedPane
JToolBar
JToolTip
JViewePort
JColorChooser
JTextComponent
JTextArea
JTextField
JPasswordField
JEditorPAne
JTextPane
JFileChooser
JLayeredPane
AbstractButton
JToggleButton
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JCheckBox
JRadioButton
JButton
JMenuItem
JMenu
JRadioButtonMenuItem
JCheckButtonMenuItem
Yine yineleyelim , swing sýnýfýndaki tüm alt metodlarý kapsamak bu kitabýn kapsamýný
oldukça büyütecektir, bu yüzden ºimdilik buna imkan göremiyoruz, fakat pratikte ne olduklarý
hakkýnda iyi bir fikir verebilecek geniºlikte bir spektrum vermeye çalýºacaðýz. Burada özellkle
awt ve swing sýnýfý grafik iºlemcilerini bir arada vermeye çalýºtýk. Kullanýcý her iki tip grafik
ortamýyla da karºýlaºacaðý için (Kendi yazmasa bile hazýr programlar karºýsýna çýkacaktýr),
her ikisini de bilmesi gereklidir. Zaten bu kitabýn tüm konularýnda da hem awt hem de swing
ile yazýlmýº program örnekleri vermeye çalýºtýk. Bu konudan sonra geriye dönüp tüm
program örneklerini grafik ortamý gözüyle inceliyebilirsiniz.
Label sýnýfý Appletin içine sadece okunabilen fakat deðiºtirilemeyen yazýlar yazma amacýyla
kullanýlýrlar. Label sýnýfýnda tanýmlanan metotlar ºunlardýr:
· Kurucu Metotlar :
public Label() // Label sýnýfý nesneyi olusturur herhangi bir yazý göstermez
public Label(String s) // Label sýnýfý nesneyi olusturur ve s stringini gösterir
public void Label(String s,int pozisyon) // Label sýnýfý nesneyi olusturur ve s stringi gösterir
ayný zamanda Labeli pozisyonda verilen deðere göre istenilen yere yerleºtirir.
Yerleºtirme konumlarý :[Link],[Link],[Link] (sol,orta,sað) konumlarýdýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link].*;
[Link]
LabelTesti programýnda kullanýlan add metotu Label’i Container sýnýfýna(Appletin alt sýnýfý
olduðu) baðlar, diðer deyimle applete veya verilen üst komponente ilave eder.
Swing sýnýfý Jlabel Lable sýnýfýndandan farklý olarak bize sadece yazý deðil ayný zamanda
görüntü ekleme olasýlýklarý da sunar. Temel sýnýf olarak kurucu metodlarý :
JLabel()
JLabel(Icon Resim)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Jlabel(String etiket)
[Link]
JLabel .CENTER
[Link]
Veya
[Link]
[Link]
[Link]
void setText(String s) : JLabel ’ýn text deðiºkeninin deðerine yeni verilen deðeri
atar
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
void setVerticalAlignment( int düºey_pozisyon) : Label’in Pencere içindeki düºey
pozisyonunu ayarlar
[Link]
[Link]
[Link]
Veya
[Link]
[Link]
[Link]
int getVerticalAlignment( )
void setIcon(Icon resim) : Label içindeki resmi deðiºtirir veya eðer yoksa ilk defa atar
void setDisplayedMnemonic(int c) : Mnemoic alt harf kontrolunu kullanarak belli bir giriºe
ulaºmayý saðlar. (örneðin ‘m’ harfine set edilmiºse alt-m bu komuta gider. Örnek problemlerle
bu kavram açýlacaktýr.
ªimdi örnek problemlerle swing JLabel kullanýmýna daha detaylý olarak bakalým.
Birinci örneðimizde basit bir ºekilde String label yazdýracaðýz. Çerçeve olarak JFrame
kullandýk.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.2 : [Link] swing java Jlabel örneði
import [Link].*;
[Link](new BasicWindowMonitor());
[Link]().add(etiket);
[Link]();
[Link](true);
[Link]
Ýkinci örneðimizde resimli, hem resim hem yazýlý ve yalnýz yazýlý bir JApplet programý
olºturduk. Bu programýn ayný zamanda main metodu da olduðundan hem applet hem de
frame olarak çaðýrýlmasý mümkündür.
Ýmport [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
ImageIcon icon1;
ImageIcon icon2;
public LabelTestiSW()
getRootPane().putClientProperty("defeatSystemEventQueueCheck",
[Link]);
icon1=new ImageIcon(iconname1);
icon2=new ImageIcon(iconname2);
j1 = new JLabel(icon1);
[Link]([Link]);
[Link]([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Font font=[Link]();
[Link](new Font([Link](),[Link],16));
[Link]([Link]);
[Link](j1);
[Link](j2);
[Link](j3);
[Link](new Color(255,255,204));
[Link]([Link]);
[Link]([Link](1,1,2,2,[Link]));
[Link](new BorderLayout());
[Link](pane1,[Link]);
setContentPane(pane);
[Link](new WindowAdapter() {
});
[Link]().add("Center", applet);
[Link]();
[Link]();
[Link](new Dimension(550,200));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public LabelDemo() {
icon,
[Link]);
[Link]([Link]);
[Link]([Link]);
add(label1);
add(label2);
add(label3);
/*
* lightweight components.
*/
[Link](new WindowAdapter() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void windowClosing(WindowEvent e) {[Link](0);}
});
[Link]();
[Link](true);
[Link]
Bu programda resim
Burada Icon interphase’ine biraz daha yakýndan göz atalým. Icon interphase sýnýfý
olduðundan tanýmlanan sýnýfý
içerisinde
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getIconHeight()
metodlarý tanýmlanmak zorundadýr. ªimdi Icon sýnýfýnýn alt sýnýfý olan OvalIcon sýnýfýný
tanýmlayalým
import [Link].*;
import [Link].*;
import [Link].*;
genislik=w;
yukseklik=h;
Graphics2D g2=(Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link](elips1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getIconWidth() {return genislik;}
Program 7.6 OvalIcon sýnýfýný kullanarak JLabel’da daire Icon’u (resmi) gösteren label2SW
programý
import [Link].*;
import [Link].*;
[Link](new BasicWindowMonitor());
[Link]([Link]);
Container c=[Link]();
[Link](new FlowLayout());
[Link](etiket1);
[Link](etiket2);
[Link](etiket3);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](true);
Bu sýnýfýn çýktýsý :
[Link]
Buradan da görüldüðü gibi JLabel sýnýfýný çok daha geniº bir platformda, oluºturduðumuz bir
grafiðin veya çizimin sonuçlarýný grafik ortama aktarmak amacýyla da kullanabiliriz.
Button (düðme) basýlýnca belirli iºlemlerin yapýlmasýný baºlatan bir sýnýftýr. Graphic arabirim
kullaným (GUI) programlarýný veya aplet programlarýný konsol programlarýndan ayýran en
önemli özellik, GUI lerin iºlem kökenli olmasýdýr. Diðer bir deyimle kullanýcýnýn baºlatacaðý
iºlemleri yapar ve kullanýcýnýn yeni bir iºlem tanýmlamasýný beklerler. Bu iºlemleri yapan
sýnýflar [Link] kütüphanesi nde tanýmlanmýºtýr. Bu kütüphanede en çok
kullanacaðýmýz sýnýflar hiyerarºi düzeninde ºöyle verilebilir :
[Link]
· [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
· ComponentEvent //appletteki elemanlarýn gizlenmesi, boylarýnýn deðiºtirilmesi, veya
deðiºik yerlere alýnmasý amacýyla kullanýlýr.
· PaintEvent
· InputEvent
Kullanýcý bir applet veya pencere tipi baºka Container programý yazarken dinleme ile ilgili iki
iºlem yapar ilk iºlem herhangi bir GUI dan bir girdi olup olmadýðýný dinlemek olduysa
kaydetmek ikincisi ise bu iºlemin sebep olacaðý iºlemleri oluºturmaktýr. Dinleme iºlemini
yapan metotlar ºunlardýr :
[Link]
· ActionListener
· AdjustmentListener
· ComponentListener
· ContainerListener
· FocusListener
· ItemListener
· KeyListener
· MouseListener
· MouseMotionListener
· TextListener
· WindowListener
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu metotlarýn bir çoðunu ilgili örneklerde yeri geldiðinde kullanacaðýz. ªimdi ayný sonucu
veren iki button orneði ile bu kavramý biraz daha açmaya çalýºalým :
import [Link];
import [Link].*;
import [Link].*;
07006JPG
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.6 [Link] sýnýfý sonuçlarýnýn appletde görünmesi
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JButton sýnýfý ile Button sýnýfý arasýnda kullaným açýsýndan Label ve Jlabel sýnýfýnýn
arasýndakilere benzer farklar vardýr.
public JButton()
ºeklindedir. Görüldüðü gibi JButton fazla metod barýndýrmaz bir çok önemli metodu Abstract
button ve onun tepe sýnýfý JComponent sýnýflarýndan alýr. JButton sýnýfýnda Jlabel sýnýfýnda da
kullandýðýmýz JComponent sýnýfýndan gelen metodlar :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public Void setVisible(Boolean b) : görünür veya görünmez yapar.
public void setText(String s) : JLabel ’ýn text deðiºkeninin deðerine yeni verilen
deðeri atar
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Public void setIcon(Icon resim) : AbstractButton‘ýn içindeki resmi deðiºtirir veya eðer yoksa
ilk defa atar
public void setDisplayedMnemonic(int c) : Mnemoic alt harf kontrolunu kullanarak belli bir
giriºe ulaºmayý saðlar. (örneðin ‘m’ harfine set edilmiºse alt-m bu komuta gider. Örnek
problemlerle bu kavram açýlacaktýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Listener (pencere dinleme) metod ve neslerinden ise :
gibi metodlar mevcuttur. ªimdi örnekler üzerinden JButton sýnýfýný kullanmayý deneyelim :
import [Link].*;
import [Link].*;
import [Link].*;
public ButtonTestiSWF()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
super("button örneði");
Container c=getContentPane();
[Link](new FlowLayout());
B1=new JButton("B1",icon1);
[Link]([Link]);
[Link](this);
[Link](B1);
B2=new JButton("B2",icon1);
[Link](this);
[Link](B2);
[Link](cikti);
[Link]([Link]());
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
String gs="";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]()==B1)
else if([Link]()==B2)
[Link](gs);
[Link]
import [Link].*;
import [Link];
import [Link];
import [Link];
implements ActionListener {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
protected Button b1, b2, b3;
b1 = new Button();
[Link](DISABLE);
[Link](false);
[Link](ENABLE);
[Link](this);
[Link](this);
add(b1);
add(b2);
add(b3);
if ([Link]().equals(DISABLE)) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](false);
[Link](false);
[Link](true);
} else {
[Link](true);
[Link](true);
[Link](false);
[Link]
*
* Swing version.
*/
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
protected String leftButtonFilename = "images/[Link]";
protected String middleButtonFilename = "images/[Link]";
protected String rightButtonFilename = "images/[Link]";
[Link](false);
[Link](true);
} else {
[Link](true);
[Link](true);
[Link](false);
}
}
protected URL getURL(String filename) {
URL codeBase = getCodeBase();
URL url = null;
try {
url = new URL(codeBase, filename);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} catch ([Link] e) {
[Link]("Couldn't create image: badly specified URL");
return null;
}
return url;
}
}
[Link]
Programdan da görüldüðü gibi bu program bir önce verilmiº olan programýn swing frame
benzeridir. Ýki program da Applet olarak verilmiºtir. Programlarda setEnabled(Boolean b)
metodu kullanýlarak düðmenin çalýºmasý etkisisz hale getirilmiºtir. Ayrýca swing versiyonunda
resim dosyasýný kullanýrken URL sýnýfý üzerinden okuduk. URL network ortamýnda bilgi
aktarmaya yarayan bir sýnýftýr. Resim dosyasý baºka bir bilgisayarda olabilirdi.
· Kurucu Metotlar :
public TextField()
public TextField(int satýrsayýsý) // satýr sayýsý uzunluðunda bir yazý kutusu açar.
public TextField(String s) // s uzunluðunda bir yazý kutusu açr ve s yi içine yazar
public TextField(String s,int satýrsayýsý) ) // satýr sayýsý uzunluðunda bir yazý kutusu açr ve s
yi içine yazar
· Diðer Metotlar:
Public void setEchoChar(char c) // kutudaki gerçek yazýyý gizleyerek onun yerine c karacter
deðiºkenini yazar.
Public void setEditable(boolean b) //kutunun içine yazýlan yazýnýn degiºtirileblmesini saðlar
veya engeller
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
b=true yazý yazýlabilir b=false yazý yazýlamaz.
import [Link];
import [Link].*;
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.10 [Link] programý sonuçlarýnýn appletde görünümü
Bu programda her yazý alanýna (TextField) addActionListener metotu eklenmiº ve bir yazý
girildiðinde actionPerformed metotundaki showStatus metotu yoluyla en son girilen yazý
showStatus penceresine aktarýlmýºtýr.
TextField sýnýfýnýn java swing eºdeðeri JTextField sýnýfýdýr. JTextField sýnýfý kurucu metotlarý :
JTextField()
JTextField(String)
JTextField(String, int)
JTextField(int)
JTextField(Document, String, int)
ªeklindedir.
TextFielde Paralel olarak Özel bir TextField türü olan PasswordField de swingde
tanýmlanmýºtýr. PassWord fieldin kurucu metod tanýmlarý :
JPasswordField()
JPasswordField(String)
JPasswordField(String, int)
JPasswordField(int)
JPasswordField(Document, String, int)
ªeklinde tanýmlanmýºtýr.
void setText(String)
String getText()
metodlarý tanýmlanmýºtýr.
void setEditable(boolean)
boolean isEditable()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
void setColumns(int);
int getColumns()
int getColumnWidth()
void setHorizontalAlignment(int);
int getHorizontalAlignment()
metodlarý yazýý alanýndaki yazýnýn ne ºekilde yerleºtirildiðini saptar veya isteðe göre
yerleºtirir. [Link] , [Link], veya [Link]
void setEchoChar(char)
char getEchoChar()
JpasswordField sýnýfýnda tanýmlanmýº yazýlan yazýnýn yerine geçecek karekteri tanýmlayan
veya soran metodlardýr.
void addActionListener(ActionListener)
metodlarý ise TextFieldin dinlenmesini ve giriº tuºu basýldýðýnda yapýlacak eylemlerin verildiði
ActionListener implement’inden gelen
void removeActionListener(ActionListener)
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Container c;
public TextFieldTestiSWF()
c=getContentPane();
[Link](new FlowLayout());
[Link]([Link]);
//bos textField
T1=new JTextField(10);
[Link](this);
[Link](T1);
[Link](this);
[Link](T2);
[Link](false);
[Link](this);
[Link](T3);
[Link](T4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String s="Kaynak = ";
if([Link]()==T1)
else if([Link]()==T2)
else if([Link]()==T3)
else if([Link]()==T4)
JOptionPane.PLAIN_MESSAGE);
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.11 TextFieldTesti SWF .java programý sonuçlarýnýn JFrame ve JoptionPane’de
görünümü
awt kütüphanesinde tanýmlanan Text Area sýnýfý yapý olarak TextField sýnýfýna benzer. En
onemli farký bir satýr yerine birden fazla satýr girdi alabilme olasýlýðýdýr. TextField ve TextArea
sýnýflarý TextComponent sýnýfýnýn alt sýnýflarýdýr. Bu yüzden üstte belirttiðimiz
Public void setEchoChar(char c) // kutudaki gerçek yazýyý gizleyerek onun yerine c karacter
deðiºkenini yazar.
Public void setEditable(boolean b) //kutunun içine yazýlan yazýnýn degiºtirileblmesini saðlar
veya engeller
b=true yazý yazýlabilir b=false yazý yazýlamaz.
public TextArea()
public TextArea(int sütun,int satýr)
sütun x satýr boyutunda yazý alaný tanýmlar
public TextArea(String s)
String deðiºkeni s nin boyuna göre yazý alaný tanýmlar ve s yi içine yazar.
public TextArea(String s,int sütun,int satýr)
sütun x satýr boyutunda yazý alaný tanýmlar ve s yi içine yazar
public TextArea(String s,int sütun,int satýr,int scrollbar)
import [Link];
import [Link].*;
public class TextAreaTesti extends Applet
{
private TextArea T1;
public void init()
{
setBackground([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//bos textField
String s="buraya denemek icin\nyazi yazildi\n\t sonrada bu yazi aktarildi";
//not \n satirbasi kontrolu
// \t bir sonraki tab setine git
T1=new TextArea(s,5,40);
add(T1);
}
}
[Link]
Bu programda gördüðünüz \n ve \t string komutlarýdýr. Alt satýra geç ve gelecek tab noktasýna
git anlamýna gelir Bu komutlar aslýnda c dilinden alýnmadýr ve c dilindeki tüm \ komutlarý java
stringlerinde de geçerlidir.
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
setBackground([Link]);
//bos textField
String s="buraya denemek icin\nyazi yazildi\n\t sonrada bu yazi aktarildi";
//not \n sat�rbaŸ� kontrol�
// \t bir sonraki tab setine git
T1=new TextArea(s,5,20,TextArea.SCROLLBARS_NONE);
[Link](this);
add(T1);
kopye=new Button("Kopye ");
[Link](this);
add(kopye);
T2=new TextArea(5,20);
[Link](false);
add(T2);
}
public void actionPerformed(ActionEvent e)
{
// T1 penceresinden seçilen yazýyý
// kopye düðmesine basýldýðýnda T2 penceresine aktar
[Link]([Link]());
}
[Link]
Kopye düðmesine basýlýnca ise sadece [Link]() metotuyla secilmiº olan text
actionPerforned metotu üzerinden T2 Yazým Alanýna (TextArea) aktarýlmaktadýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java swing JTextArea sýnýfý awt deki TextArea sýnýfýnýn benzeridir. Sýnýfýn kurucu
metodlarýnýn tanýmý
public JTextArea();
public JTextArea(Document doc, String Text, int satýrsayýsý int sütun sayýsý);
ºeklindedir.
import [Link].*;
import [Link].*;
import [Link].*;
implements ActionListener,TextListener
public TextAreaTesti1SWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
super("JTextAreaTesti");
Container c=getContentPane();
[Link](new FlowLayout());
[Link]([Link]);
//bos textField
Box b=[Link]();
T1=new JTextArea(s,10,15);
[Link](new JScrollPane(T1));
[Link](this);
[Link](kopye);
[Link](kopye);
T2=new JTextArea(10,15);
[Link](false);
[Link](new JScrollPane(T2));
[Link](b);
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void textValueChanged(TextEvent e)
TextComponent kaynak=(TextComponent)([Link]());
[Link]([Link]());
[Link](new BasicWindowMonitor());
[Link](600,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
awt kütüphanesi Choice (Seçim) sýnýfý birden fazla maddeden seçim yapýlmasý gerektiðinde
kullanýlan bir sýnýftýr.
Choice sýnýfýnýn kurucu metotu ve diger metotlarýnýn listesi aºaðýda verilmiºtir :
import [Link].*;
import [Link];
import [Link].*;
[Link](new TextFieldKontrolu(T));
add(F);
add(T);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public FontIsmiKontrolu(Component C)
{
this.C=C;
}
[Link]().getStyle(),
[Link]().getSize()));
}
}
public TextFieldKontrolu(TextField T)
{
this.T=T;
}
[Link]
Java swing sýnýfýnda Choice sýnýfýnýn benzeri Jchoice sýnýfý mevcut deðildir. Onun yerini
JComboBox sýnýfý almýºtýr
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JComboBox sýnýfýnýn Kurucu metodlarý :
public JComboBox();
ºeklindedir. Vector geliºmiº bir boyutlu deðiºken türüdür detaylarý 11 inci bölüm, geliºmiº
java bilgi iºleme yapýlarý kýsmýnda verilmiºtir.
getSelectedObjects() : birden fazla seçim yapýldýðýnda tüm seçilen object listesini iletir.
import [Link].*;
import [Link].*;
import [Link].*;
private JComboBox F;
private JTextField T;
public JComboBoxTestiSWF()
super("JComboBox örneði");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Container co=getContentPane();
String Liste[]={"MonoSpaced","SansSerif","Serif"};
F=new JComboBox(Liste);
T=new JTextField((String)[Link](0));
[Link](false);
[Link](new Font((String)[Link](0),[Link],12));
[Link](new FontIsmiKontrolu(T));
[Link](new TextFieldKontrolu(T));
[Link](F,[Link]);
[Link](T,[Link]);
[Link](new BasicWindowMonitor());
[Link](300,150);
//[Link]();
[Link](true);
private Component C;
public FontIsmiKontrolu(Component C)
this.C=C;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void itemStateChanged(ItemEvent e)
[Link](new Font([Link]().toString(),
[Link]().getStyle(),
[Link]().getSize()));
private JTextField T;
public TextFieldKontrolu(JTextField T)
this.T=T;
JComboBox C=(JComboBox)[Link]();
}}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
awt sýnýfýnda yer alan Check box ve CheckBoxGroup sýnýflarý çesitli opsiyonlar arasýndan
seçim yapabilme olasýlýðýný saðlayan sýnýflardýr.
Kurucu metotlarý :
Public CheckBox(String s)
Tek bir kare kontrol kutusu oluºturur. Kontrol kutusu baºta boºtur
Public CheckBox(String s, CheckBoxGroup c,boolean durum)
Tekbir daire ºeklinde kontrol kutusu oluºturur ve bu kontrol kutusunu CheckBoxGroup
nesnesine ilave eder.
Public CheckboxGroup()
CheckboxGroup nesnesini oluºturur bu gruba checkboxlar ilave edilebilir
import [Link];
import [Link].*;
import [Link].*;
{
int KalinAyari;
if([Link]())
{KalinAyari=[Link];}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
{KalinAyari=[Link];}
int ItalicAyari;
if([Link]())
{ItalicAyari=[Link];}
else
{ItalicAyari=[Link];}
[Link](new Font("Serif",KalinAyari+ItalicAyari,14));
}
}
[Link]
import [Link];
import [Link].*;
import [Link].*;
Normal=new Checkbox("Normal",fontGurubu,true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
add(Normal);
Kalin=new Checkbox("Kalin",fontGurubu,true);
[Link](this);
add(Kalin);
Italic=new Checkbox("Italik",fontGurubu,true);
[Link](this);
add(Italic);
KalinItalic=new Checkbox("Kalin Italik",fontGurubu,true);
[Link](this);
add(KalinItalic);
NormalFont=new Font("Serif",[Link],14);
KalinFont=new Font("Serif",[Link],14);
ItalicFont=new Font("Serif",[Link],14);
KalinItalicFont=new Font("Serif",[Link]+[Link],14);
[Link](NormalFont);
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public JCheckBox()
Burada da daha önceki JLabel, JButton gibi sýnýflarda gördüðümüz gibi yazýnýn yanýnda
resim yerleºtirme seçimimiz de mevcuttur. Buradaki örnek problemde bir önceki problemin
aynýsý JcheckBox ile çözülmüºtür.
import [Link].*;
import [Link].*;
import [Link].*;
private JTextField T;
int KalinAyari=[Link];;
int ItalikAyari=[Link];
public CheckBoxTestiSWF()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Container c=getContentPane();
[Link]([Link]);
//[Link](new FlowLayout());
[Link](new GridLayout(0,1));
//bos textField
Kalin=new JCheckBox("Kalýn");
[Link]('K');
[Link](false);
[Link](this);
[Link](Kalin);
Italik=new JCheckBox("Ýtalik");
[Link]('Ý');
[Link](false);
[Link](this);
[Link](Italik);
[Link](Check,[Link]);
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
[Link](T,[Link]);
Object kutu=[Link]();
{KalinAyari=[Link];}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if(Kalin==kutu && [Link]()==[Link])
{KalinAyari=[Link];}
{ItalikAyari=[Link];}
{ItalikAyari=[Link];}
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
[Link](new BasicWindowMonitor());
[Link](400,100);
[Link](true);
[Link]
public JRadioButton()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public JRadioButton(Icon resim,boolean kutuiºareti)
Burada JRadioButton sýnýfýna ilave olarak bir tane daha ilave olarak bir tane daha yardýmcý
sýnýf kullanacaðýz. Bu sýnýf ButtonGroup sýnýfýdýr. Bu sýnýf düðmeleri bir gurup altýnda
toplayarak sadece bir tanesinin basýlý durumda olmasý iºlevini kontrol eder. Bu sýnýfýn tanýmý :
public ButtonGroup();
ºeklindedir. ªimdi yine bir öncekine benzer bir örnekte JradioButton ve ButtonGroup
sýnýflarýnýn birarada kullanýmýný görelim.
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class RadioButtonTestiSWF extends JFrame implements ItemListener
private JTextField T;
int KalinAyari=[Link];;
int ItalikAyari=[Link];
public RadioButtonTestiSWF()
Container c=getContentPane();
[Link]([Link]);
[Link](new GridLayout(4,0));
//bos textField
gurup=new ButtonGroup();
normal=new JRadioButton("Normal");
[Link]('N');
[Link](true);
[Link](this);
[Link](normal);
[Link](normal);
kalin=new JRadioButton("Kalýn");
[Link]('K');
[Link](false);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](kalin);
[Link](kalin);
italik=new JRadioButton("Ýtalik");
[Link]('t');
[Link](false);
[Link](this);
[Link](italik);
[Link](italik);
kalinitalik=new JRadioButton("Kalýn-Ýtalik");
[Link]('a');
[Link](false);
[Link](this);
[Link](kalinitalik);
[Link](kalinitalik);
[Link](Check,[Link]);
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
[Link](T,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Object kutu=[Link]();
if(kutu==normal)
KalinAyari=[Link];
ItalikAyari=[Link];
else if(kutu==kalin)
KalinAyari=[Link];
ItalikAyari=[Link];
else if(kutu==italik)
KalinAyari=[Link];
ItalikAyari=[Link];
else if(kutu==kalinitalik)
KalinAyari=[Link];
ItalikAyari=[Link];
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new BasicWindowMonitor());
[Link](400,100);
[Link](true);
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private JTextField T;
int KalinAyari=[Link];;
int ItalikAyari=[Link];
public ToggleButtonSWF()
super("ToggleButton örneði");
Container c=getContentPane();
[Link]([Link]);
//[Link](new FlowLayout());
[Link](new GridLayout(0,1));
//bos textField
Kalin=new JToggleButton("Kalýn");
[Link]('K');
[Link](false);
[Link](this);
[Link](Kalin);
Italik=new JToggleButton("Ýtalik");
[Link]('t');
[Link](false);
[Link](this);
[Link](Italik);
[Link](Check,[Link]);
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
[Link](T,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Object kutu=[Link]();
{KalinAyari=[Link];}
{KalinAyari=[Link];}
{ItalikAyari=[Link];}
{ItalikAyari=[Link];}
[Link](new Font("Serif",KalinAyari+ItalikAyari,20));
[Link](new BasicWindowMonitor());
[Link](400,100);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.21 ToggleButtonTestiSWF .java programýnýn sonuçlarýnýn JFrame’de görülmesi
Modern bilgisayarlarda bilgisayar iºlemlerinin çok büyük bir kýsmý mouse (fare) ile kontrol
edilir. Javada gurubunda temel fare kontrollarýný saðlayan sýnýflar MouseListener ve
MouseMotionListener sýnýflarýdýr.
1. MouseListener Metotlarý :
2. MouseMotionListener Metotlarý
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.22 [Link] applet çýktýsý
import [Link].*;
import [Link].*;
import [Link].*;
public FareTestiSWF()
super("Fare Testi");
altbar=new JLabel();
getContentPane().add(altbar,[Link]);
addMouseListener(this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
addMouseMotionListener(this);
s=e;
nx=x;
ny=y;
repaint();
{ degerleriGir("Kliklendi",[Link](),[Link]()); }
{ degerleriGir("Basýldý",[Link](),[Link]()); }
{ degerleriGir("Býrakýldý",[Link](),[Link]()); }
{ degerleriGir("basilip cekiliyor",[Link](),[Link]()); }
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{ degerleriGir("hareket halinde",[Link](),[Link]()); }
[Link](new BasicWindowMonitor());
[Link](350,150);
[Link](true);
[Link]
JTable ºu ana kadar gördüðümüz sýnýflara göre daha kompleks bir yapý arzeder, fakat
oldukça kullanýºlý bir yapýdýr ve sadece swing kütüphanesinde tanýmlanmýºtýr.
public JTable();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public JTable(Object[][] tablogirdisi ,Object[] tablobaºlýðýgirdisi);
görüldüðü gibi bu sýnýf interface olduðundan bu sýnýftan türetilen sýnýflarýn bu sýnýftaki tüm
metodlarý tanýmlamalarý gerekir. Bu yüzden AbstractTableModel gibi Table Model’den
türetilen sýnýflar üzerinden yeni sýnýfýn türetilmesine gidilebilir.
public AbstractTableModel();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void fireTableRowsDeleted(int satýr,int sütun);
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public TableModel()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
addTableModelListener(this);
veri[row][col] = val;
fireTableDataChanged();
JOptionPane.WARNING_MESSAGE);
private Container c;
public tableSWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
super("Tablo örneði");
c=getContentPane();
[Link](new BorderLayout());
setSize(300,300);
addWindowListener(new BasicWindowMonitor());
[Link](jsp,[Link]);
f=new JTextField();
[Link](f,[Link]);
//=====================================================
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Problem 7.27 table1SWF_2000 .java, TableModel , JTable ve TableModelListener sýnýflarý
kullaným test programý
// JTable örneði
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Object[][] data = {
};
String s="";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s+=data[i][j] + " ";
s+="\n";
JOptionPane.PLAIN_MESSAGE);
//kurucu metod
DataModel()
addTableModelListener(new TML());
data[row][col] = val;
fireTableDataChanged();
public boolean
return true;
};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class table1SWF_2000 extends JFrame {
public table1SWF_2000()
{ super("Tablo örneði");
Container c=getContentPane();
[Link](new BorderLayout());
[Link](jsp, [Link]);
[Link](300,300);
[Link](new BasicWindowMonitor());
[Link](true);
[Link]
7.10 AWT, LIST SINIFI VE JAVA SWING JLIST SINIFI , LÝSTEDEN SEÇÝM
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu gurup aslýnda bölüm 7.6 da tanýmlanan awt Choice , swing JcomboBox seçim sýnýflarýnýn
bir devamý niteliðindedir.
List ve Jlist sýnýflarý bir listeden seçim yapmaya ve bu seçim sonucu gerekli iºlemleri
oluºturmaya yarar. List sýnýfý ItemListener ve ActionListener sýnýf implementlerini kullanýr.
Örnek programýmýzda Listeden seçilen renge göre arkaplan rengi deðiºmektedir.
import [Link];
import [Link].*;
import [Link].*;
for(int i=0;i<[Link];i++)
{
[Link](renkIsmi[i]);
}
add(renkListesi);
}
public void actionPerformed(ActionEvent e)
{
setBackground(C[[Link]()]);
repaint();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
List sýnýfýnýn swing grubundaki paraleli daha geliºmiº bir liste kullanma metodu JList
metodudur. Jlist metodu pencereye ilave edilirken direk olarak ilave edilmez, JscrollPane alt
pencere programý üzerinden ilave edilir. Ayný zamanda dinleme metodu olarak
ListSelectionListener metodu kullanýlýr. Bu metod java swing kütüphanesi [Link]
de tanýmlanmýºtýr.
JList metoduyla bir seçim yapýldýðý gibi birden fazla seçim yapmakta mümkündür.
public JList();
dir.
public int GetSelectedIndex() : seçilen (veya en son seçilen) elemanýn indisini verir
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int[] getSelectedIndices() : seçilen elemanlarýn (birden fazla olabilir) indislerini boyut
üzerinden aktarýr
public Object getSelectedValue() : son seçilen elemandaki deðeri Object olarak aktarýr.
void setSelectionMode(int mode) : tek eleman mý seçileceðini yoksa çok sayýda eleman mý
seçileceðini belirler. Girdi int deðiºkeni
Listenin kenar kayma çubuklarý, listenin içinde yer alacaðý JScrollPane penceresi tarafýndan
oluºturulur.
public JScrollPane();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JScrollPane. HORIZONTAL _SCROLLBAR_AS_NEEDED : sadece gerektiði zaman yatay
kaydýrma çubuðu tanýmla
Deðerlerini alýr.
Birkaç örnek problemle Jlist sýnýfýný vermetye çalýºalým. Ýlk örnek yukarýdaki JcomboBox
problemlerin ayný iºlemini yapmaktadýr. Listeden yapýlan seçime göre JtextField alanýndaki
fontu deðiºtirecektir. Listenin iki elemanýnýn görülmesi müsadesi verilmiºtir. Liste tek seçimli
listedir.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
private JList F;
private JTextField T;
public JListTestiSWF()
Container co=getContentPane();
String Liste[]={"MonoSpaced","SansSerif","Serif"};
F=new JList(Liste);
[Link](2);
[Link](ListSelectionModel.SINGLE_SELECTION);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](0);
T=new JTextField((String)[Link]());
[Link](false);
[Link](new Font((String)[Link](),[Link],12));
[Link](this);
[Link](sp,[Link]);
[Link](T,[Link]);
[Link](new Font((String)[Link](),
[Link]().getStyle(),
[Link]().getSize()));
[Link](new BasicWindowMonitor());
[Link](300,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
Bu örnekte ise listeden yapacaðýmýz seçime göre arka plan rengini deðiºtiriyoruz. Bu
program yukarýda verilen List programýnýn oldukça benzeridir. Listede dört elemanýn
görülmesi izni verilmiºtir. Liste tek seçimli bir listedir.
import [Link].*;
import BasicWindowMonitor;
import renk;
"Yeºil","Açýk gri","mor","Portakal","Pembe","Kýrmýzý","beyaz","sarý"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link],[Link],[Link],[Link],[Link],[Link],
[Link],[Link],[Link]};
JList renklistesi;
Color r=[Link];
Container c;
public JListTesti1SWF()
c=getContentPane();
[Link](new FlowLayout()) ;
renklistesi=new JList(renkler);
[Link](4);
[Link](ListSelectionModel.SINGLE_SELECTION);
[Link](new JScrollPane(renklistesi));
[Link](this);
r=re[[Link]()];
if(r==null)
r=[Link];
[Link](r);
repaint();
//=====================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args)
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
[Link]
Diðer bir Liste kullanma örneði : Bu örnekte Listeye JtextField üzerinden ilave yapabiliyoruz
ve çýkarabiliyoruz. Örnek Java döküman kütüphanesinden alýnýp adapte edilmiºtir.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class ListDemoSWF extends JFrame implements ListSelectionListener {
public ListDemoSWF() {
super("ListDemo");
[Link]("Turhan Çoban");
[Link]("Ýrfan Çoban");
[Link]("Birsen Çeliker");
[Link]("Nurhan Erel");
[Link](ListSelectionModel.SINGLE_SELECTION);
[Link](0);
[Link](this);
[Link](hireString);
[Link](new HireListener());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](fireString);
[Link](new FireListener());
[Link](new HireListener());
[Link](name);
[Link](employeeName);
[Link](hireButton);
[Link](fireButton);
[Link](new BorderLayout());
[Link](listScrollPane, [Link]);
[Link](buttonPane, [Link]);
[Link](index);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//Listede eleman kalmadý iºten atmayý durdur
if (size == 0) {
[Link](false);
//seçimi düzenle
} else {
if (index == [Link]())
index--;
[Link](index);
if ([Link]().equals("")) {
[Link]().beep();
return;
[Link]([Link]());
[Link](size);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} else {
[Link]([Link](), index+1);
[Link](index+1);
if ([Link]() == false) {
if ([Link]() == -1) {
[Link](false);
[Link]("");
} else {
[Link](true);
[Link](name);
[Link](new BasicWindowMonitor());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link](true);
[Link]
Listelerin sadece tek seçim deðil ayný zamanda birden fazla seçim yapmak içinde
kullanýldýðýndan bahsetmiºtik. Aºaðýdaki örnekte listeden Liste türü deðiºkeninde yaptýðýmýz
deðiºikliðe göre bir veya birden fazla seçim yapabiliyoruz . Bu program hem JFrame hem de
Japplet olarak çalýºabilmektedir.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class ListSelectionDemo extends JApplet {
JTextArea output;
JList list;
JTable table;
ListSelectionModel listSelectionModel;
// için tanýmlandý.
public ListSelectionDemo()
this(true);
[Link] = inAnApplet;
if (inAnApplet) {
getRootPane().putClientProperty("defeatSystemEventQueueCheck",
[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String[] columnNames = { "Fransýzca", "Ýngilizce", "Italyanca" };
listSelectionModel = [Link]();
[Link](
new SharedListSelectionHandler());
[Link](listSelectionModel);
"SINGLE_INTERVAL_SELECTION",
"MULTIPLE_INTERVAL_SELECTION" };
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](2);
[Link](new ActionListener() {
if ([Link]("SINGLE_SELECTION")) {
[Link](
ListSelectionModel.SINGLE_SELECTION);
} else if ([Link]("SINGLE_INTERVAL_SELECTION")) {
[Link](
ListSelectionModel.SINGLE_INTERVAL_SELECTION);
} else {
[Link](
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
[Link]("----------"
+ "----------" + newline);
});
[Link](comboBox);
[Link](false);
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//JFrame'i Split pane kullanarak ikiye böl
getContentPane().add(splitPane, [Link]);
//
[Link]([Link](
"Türkçe Liste"));
[Link](listPane);
[Link]([Link](
"Tablo"));
[Link](tablePane);
[Link]([Link](5,5,0,5));
[Link](listContainer);
[Link](tableContainer);
[Link](topHalf);
[Link](controlPane, [Link]);
[Link](outputPane, [Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//XXX: the next line is necessary if bottomHalf is a scroll pane:
[Link](bottomHalf);
[Link](new WindowAdapter() {
[Link](0);
});
[Link]();
[Link](listDemo);
[Link]();
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("Seçilen indeks bölgesi: "
if ([Link]()) {
[Link](" <none>");
} else {
if ([Link](i)) {
[Link](newline);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.30 [Link] programý sonuçlarýn JFrame penceresinde görünümü
(not bu program hem applet hem frame olark görüntülenebilir)
Window türü programlamaya alýºýk olan herkes menu kullanmaya da alýºýktýr. Menuler
pencerenin tepesinden açýlan ve çeºitli görevler yüklenen komponentlerdir. Java swing
menu’leri temel olarak JMenuBar, JMenu ve JMenuItem sýnýflarýndan oluºur. Ayrýca
menulerde JcheckBoxMenuItem, JradioButtonMenuItem gibi alt elemanlar da bulunabilir.
Public JmenuBar();
ªeklindedir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
protected void paintBorder(Graphics g);
public JMenu();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void insert(String etiket,int pos);
public JMenuItem();
bazý metodlarý :
public JCheckBoxMenuItem();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public JCheckBoxMenuItem(String Label,Boolean seçildimi);
ªimdi bu metodlarý kullanan bir örnek menu oluºturalým. Örnek menu sadece menu yapýsýný
göstermek amaçlý olduðundan fazla bir eyem yamamaktadýr. Gerçek programlarýnýzda
gerekli eylemleri yereºtirebilirsiniz.
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
/*
* Menu Demo
*/
JTextArea output;
JScrollPane scrollPane;
public MenuDemo() {
JMenuBar menuBar;
JMenuItem menuItem;
JRadioButtonMenuItem rbMenuItem;
JCheckBoxMenuItem cbMenuItem;
addWindowListener(new BasicWindowMonitor());
[Link](false);
[Link](scrollPane, [Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
setJMenuBar(menuBar);
[Link]('M');
[Link]().setAccessibleDescription(
[Link](menu);
KeyEvent.VK_T);
[Link]([Link](
KeyEvent.VK_1, ActionEvent.ALT_MASK));
[Link]().setAccessibleDescription(
[Link](this);
[Link](menuItem);
new ImageIcon("images/[Link]"));
[Link](KeyEvent.VK_B);
[Link](this);
[Link](menuItem);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]('d');
[Link](this);
[Link](menuItem);
[Link]();
[Link](true);
[Link]('r');
[Link](rbMenuItem);
[Link](this);
[Link](rbMenuItem);
[Link]('i');
[Link](rbMenuItem);
[Link](this);
[Link](rbMenuItem);
[Link]();
[Link]('c');
[Link](this);
[Link](cbMenuItem);
[Link]('k');
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](cbMenuItem);
//a submenu
[Link]();
[Link]('A');
[Link]([Link](
KeyEvent.VK_2, ActionEvent.ALT_MASK));
[Link](this);
[Link](menuItem);
[Link](this);
[Link](menuItem);
[Link](submenu);
[Link]('n');
[Link]().setAccessibleDescription(
[Link](menu);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JMenuItem source = (JMenuItem)([Link]());
+ newline
[Link](s + newline);
+ newline
+ newline
+ (([Link]() == [Link]) ?
[Link](s + newline);
return [Link](dotIndex+1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String[] args) {
[Link]("MenuDemo");
[Link](450, 260);
[Link](true);
[Link]
JSlider sýnýfý bir deðiºkenin deðerini verilen sýnýrlar içerisinde deðiºtirmeye yarayan bir grafik
kullanýcý arayüz sýnýfýdýr. JSlider sýnýfýnýn kurucu metodlarý :
public JSlider();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import yildizSW;
import [Link].*;
import renk;
int xi,yi,yaricap;
xi=xi1;
yi=yi1;
xi=xi1;
yi=yi1;
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](g);
[Link]([Link]);
Graphics2D g2=(Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link](elips1);
import BasicWindowMonitor;
import ovalPanelSWP;
import [Link].*;
private ovalPanelSWP p;
Color r=[Link];
Container c;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// pencereyi baslatma metodu
public ovalTestSWF_2000()
super("JSlider Testi");
c=getContentPane();
p=new ovalPanelSWP(30,30,30);
cap=new JSlider([Link],0,200,10);
[Link](20);
[Link](true);
[Link](true);
[Link](this);
[Link](p,[Link]);
[Link](cap,[Link]);
[Link](30, 30,[Link]());
repaint();
//=====================================================
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
Bu programda uyguladýðýmýz bir çizim ºekline daha detaylý göz atalým. Daire JPanel sýnýfýnda
çizilmiºtir. Daireyi çizmek için ovalPanelSWP sýnýfýný yarattýk. JPanel sýnýfýnda kurucu
metodlarýmýzý herhangi bir sýnýfta olduðu gibi tanýmladýk ve public void
paintComponent(Graphics g) metodu ve Graphics sýnýfý üzerinden çizimimizi tanýmladýk.
Tekrar çizdirmek için repaint() metodunu kullandýk. Ýkinci JFrame proramýmýzda
private ovalPanelSWP p;
p=new ovalPanelSWP(30,30,30);
Container c;
c=getContentPane();
[Link](p,[Link]);
komutlarýný kullanarak panelimizi ana panele monte ettik. StateChanged event metodundaki
[Link](30, 30,[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
komutuyla da çapýný deðiºtirip
repaint();
Panel programýnda
[Link](RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALI
AS_ON);
Grafik arayüz programlarýnýn daha düzgün bir ºekilde gösterilmesi amacýyla Layout sýnýflarý
kullanýlýr. awt grafik interface’inde default deðer olarak kullanýlan Layout sýnýfý FlowLayout
sýnýfýdýr. Swing arayüz programlarýnda ise BorderLayout sýnýfý default olarak kullanýlar.
Flow layout sýnýfý grafik ortamýna (Panel, Applet, Frame, Jpanel, Japplet, JFrame vs.) alt
elemanlarý yerleºtirirken soldan saða doðru akleme (add) sýrasýyla yerleºtirir. Penceredeki
yer bittiyse bir alt satýra geçer.
public Flowlayout()
public Flowlayout(int formatbolgesi)
[Link],
[Link] veya
[Link]
deðerlerini alabilir. Bu deðerlere göre içerdiði elemanlarý saða ortaya veya sola yerleºtirir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public Flowlayout(int formatbolgesi,int yatay_bosluk,int dikey_bosluk);
Yatay_bosluk pixel olarak yatay posisyonda elemanlar arasýnda kalan boslugu gosterir.
Dikey bosluk ise dikey dogrultudaki pixel olarak boºluktur.
Küçuk bir örnek problemle FlowLayout kullanýmýný daha açýk hale getirebiliriz.
import [Link];
import [Link].*;
import [Link].*;
public class FlowLayoutTesti extends Applet implements ActionListener
{
private Button B[];
public void init()
{
B=new Button[3];
B[0]=new Button("Sol");
B[1]=new Button("Orta");
B[2]=new Button("Sag");
for(int i=0;i<[Link];i++)
{
B[i].addActionListener(this);
add(B[i]);
}
}
public void actionPerformed(ActionEvent e)
{
int pozisyon=[Link];;
if([Link]()==B[0])
{
pozisyon=[Link];
}
else if([Link]()==B[1])
{
pozisyon=[Link];
}
else if([Link]()==B[2])
{
pozisyon=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
setLayout(new FlowLayout(pozisyon));
validate();
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
public FlowLayoutTestiSWF_2000()
c=getContentPane();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new FlowLayout());
B=new JButton[3];
B[0]=new JButton("Sol");
B[1]=new JButton("Orta");
B[2]=new JButton("Sað");
for(int i=0;i<[Link];i++)
B[i].addActionListener(this);
[Link](B[i]);
int pozisyon=[Link];;
if([Link]()==B[0])
pozisyon=[Link];
else if([Link]()==B[1])
pozisyon=[Link];
else if([Link]()==B[2])
pozisyon=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new FlowLayout(pozisyon));
[Link]();
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
[Link]
public BorderLayout()
public BorderLayout(int yatay_bosluk,int dikey_bosluk);
yatay_bosluk ve dikey_basluk pixel olarak alýnýr. GUI elemanlarýnýn arasýndaki bosluk
miktarýný tanýmlar.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link].*;
import [Link].*;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.35 [Link] programýnýn sonuçlarýnýn applette görulmesi
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
public BorderLayoutTestiSWF_2000()
c=getContentPane();
[Link](new BorderLayout(5,5));
B=new JButton[5];
for(int i=0;i<[Link];i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
[Link](B[0],[Link]);
[Link](B[1],[Link]);
[Link](B[2],[Link]);
[Link](B[3],[Link]);
[Link](B[4],[Link]);
for(int i=0;i<[Link];i++)
if([Link]()==B[i])
B[i].setVisible(false);
else B[i].setVisible(true);
[Link]();
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
public GridLayoutTestiSWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
c=getContentPane();
[Link](new GridLayout(3,2,5,5));
B=new JButton[6];
for(int i=0;i<[Link];i++)
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
[Link](B[i]);
for(int i=0;i<[Link];i++)
if([Link]()==B[i])
B[i].setVisible(false);
else B[i].setVisible(true);
[Link]();
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
JTabbedPane sadece swing sýnýfýnda kullanýlabilir. Deðiºik sayfalar halinde bir grafik
arayüzü çaðýrýr. Bu sayfalardan istenilen seçilerek kullanýlabilir. Her sayfa baðýmsýz bir grafik
ortamý oluºturur.
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
public JTabbedPaneTestiSWF_2000()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
super("JTabbedPane formatlama Grafik ara yüz (GUI) testi");
c=getContentPane();
[Link](new BorderLayout(5,5));
B=new JButton[6];
for(int i=0;i<[Link];i++)
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
[Link](S[i],B[i]);
[Link](jtp);
for(int i=0;i<[Link];i++)
if([Link]()==B[i])
else B[i].setText(S[i]);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
[Link]
JSplitPane ekraný ikiye böler. Bu ikiye bölme iºlemlerini yineleyerek istediðimiz alt parçalarý
oluºturabiliriz. JSplitPane ile bölünen alt parçalar fare ile çekilerek büyütülüp küçültülebilir.
Örnek problemdeki
c=getContentPane();
[Link](new BorderLayout(5,5));
B=new JButton[4];
jsp=new JSplitPane[3];
for(int i=0;i<[Link];i++)
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
jsp[0]=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,B[0],B[1]);
jsp[1]=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,B[2],B[3]);
jsp[2]=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,jsp[0],jsp[1]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](jsp[2]);
kod parçacýðýnda ekraný önce B[0] ve B[1] düðmelerini yerleºtirdiðimimiz yatay iki parçaya,
sonra B[2] ve B[3] düðmelerini yerleºtirdiðimz iki yatay parçaya böldükten sonra bu parçalarý
(jsp[0] ve jsp[1]) iki düºey parçaya ayýrýyoruz. Böylece birbirinden baðýmsýz dört ayrý alt parça
(split) oluºturuyoruz.
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
JSplitPane jsp[];
public JSplitPaneTestiSWF_2000()
c=getContentPane();
[Link](new BorderLayout(5,5));
B=new JButton[4];
jsp=new JSplitPane[3];
for(int i=0;i<[Link];i++)
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
jsp[0]=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,B[0],B[1]);
jsp[1]=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,B[2],B[3]);
jsp[2]=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,jsp[0],jsp[1]);
[Link](jsp[2]);
for(int i=0;i<[Link];i++)
if([Link]()==B[i])
else B[i].setText(S[i]);
[Link]();
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.40 JSplitPaneTestiSWF_2000.java programý sonuçlarýnýn JFrame’de görülmesi
JscrollPane sýnýfýný Jlist sýnýfýný incelerken görmüºtük. Bu formatlama sýnýfý Scrollbar adýný
verdiðimiz yatay ve düºey kaydýrma çubuklarý yardýmýyla küçük bir pencereye sýðmayacak
kadar büyükolan grafiklerin kullanýlmasýný saðlar.
import [Link].*;
import [Link].*;
import [Link].*;
private Container c;
JScrollPane jscroll;
JPanel jsp;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public JScrollPaneTestiSWF_2000()
c=getContentPane();
[Link](new BorderLayout(5,5));
B=new JButton[16];
jsp=new JPanel();
for(int i=0;i<[Link];i++)
B[i]=new JButton(S[i]);
B[i].addActionListener(this);
[Link](B[i]);
jscroll=new JScrollPane(jsp);
[Link](jscroll,[Link]);
for(int i=0;i<[Link];i++)
if([Link]()==B[i])
else B[i].setText(S[i]);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JScrollPaneTestiSWF_2000 pencere= new JScrollPaneTestiSWF_2000();
[Link](new BasicWindowMonitor());
[Link](400,200);
[Link](true);
[Link]
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
buttons=new Button[5];
[Link](new GridLayout(1,[Link]));
for(int i=0;i<[Link];i++)
{
buttons[i]=new Button("Button "+(i+1));
[Link](buttons[i]);
}
setLayout(new BorderLayout());
add(buttonPanel,[Link]);
}
}
07042JPG
JPanel sýnýfýný daha önce çeºitli alýºtýrmalarda zaten kullanmýºtýk. JPanel’i formatlama
iºleminde ayný Panel sýnýfýnda olduðu gibi bir alt formatlama elemaný olarak kullanabiliriz.
Zaten bütün swing programlarýnýn temeli de JPanel sýnýfýdýr. Swing gurubunda bir üstteki
problemin aynýsýný JApplet olarak yineledik. Awt penceresi ve swing penceresi arasýndaki en
önemli farkýn awt de add terimini appletin bir alt terimi gibi kullanabilirken, swingde
getContentPane() deyimiyle ana JPanel’i çaðýrmak ve çizimleri bunun üzerine yapmak
olduðunu bir kere daha yineleyelim.
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private JPanel buttonPanel;
buttonPanel=new JPanel();
buttons=new JButton[5];
[Link](new GridLayout(1,[Link]));
for(int i=0;i<[Link];i++)
[Link](buttons[i]);
Container c=getContentPane();
[Link](new BorderLayout());
[Link](buttonPanel,[Link]);
07043JPG
ªu ana kadarki format örneklerinde anlatýmý basitleºtirmek amacýyla hep düðmeler (button)
kullandýk. ªimdi de baºka bir problemde Panel sýnýfýnýn kullanýlmasýna bakalým :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.47 : [Link] programý
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]);
[Link](new Font("Serif",[Link],14));
[Link]("Polinomun Kokleri: ",70,175);
[Link]([Link]);
[Link](new Font("Serif",[Link],12));
if(delta<0)
{
[Link]("Kok 1 :"+(-b/2.0/a)+"+ i* "+[Link](- delta)/2.0/a,100,190 );
[Link]("Kok 2 :"+(-b/2.0/a)+"- i* "+[Link](-delta)/2.0/a,100,205);
}
if(delta==0)
{
[Link]("Kok 1 :"+(-b/2.0/a),100,190 );
[Link]("Kok 2 :"+(-b/2.0/a),100,205 );
}
if(delta0)
{
x1=-b/2.0/a+[Link](delta)/20/a;
x2=-b/2.0/[Link](delta)/2.0/a;
[Link]("Kok 1 :"+x1,100,190 );
[Link]("Kok 2 :"+x2,100,205);
}
}
public void actionPerformed( ActionEvent e)
{
Double sayi1=new Double([Link]() );
Double sayi2=new Double([Link]() );
Double sayi3=new Double([Link]() );
a=[Link]();
b=[Link]();
c=[Link]();
delta=b*b-4.0*a*c;
repaint();
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.44 Ýkinci dereceden denklemin koklerini hesaplayan [Link] programý
ve sonuçlarýnýn applette görulmesi
import [Link].*;
import [Link].*;
import [Link].*;
// polinom a*x^2+b*x+c=0
JLabel prompt1;
JLabel prompt2;
JLabel prompta;
JTextField inputa; //
JLabel promptb; //
JTextField inputb; //
JLabel promptc; //
JTextField inputc; //
JTextArea cikti;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void init()
Container c=getContentPane();
cikti=new JTextArea();
[Link]([Link]());
setBackground([Link]);
YaziPaneli=new JPanel();
[Link](new Font("Serif",[Link],12));
[Link](this);
[Link](this);
[Link](this);
[Link](prompt1);
[Link](prompt2);
[Link](prompta);
[Link](inputa);
[Link](promptb);
[Link](inputb);
[Link](promptc);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](inputc);
[Link](YaziPaneli,[Link]);
[Link](cikti,[Link]);
String s="";
if(delta<0)
if(delta==0)
if(delta>0)
x1=-b/2.0/a+[Link](delta)/20/a;
x2=-b/2.0/[Link](delta)/2.0/a;
return s;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed( ActionEvent e)
a=[Link]();
b=[Link]();
c=[Link]();
delta=b*b-4.0*a*c;
[Link](toString());
repaint();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªu ana kadar gördüðümüz sýnýflar grafik arayüzü dizayný yapmaya yarayan sýnýflardý. Java
swing gurubunda ayný zamanda kullanýlmaya hazýr bir çok grafik arayüzleri tanýmlanmýºtýr.
Bunlarýn en çok kullanýlaný, ve bu kitapta da ºu ana kadar yoðun olarak kullanageldiðimiz
JOPtionPane sýnýfýdýr. Bu sýnýfýn ana gayesi pop-up mesaj ve girdi ortamý saðlamaktýr.
JoptionPane sýnýfýný programýmýzda kurucu metod kullanarak kurmamýz gerekmez. Temel
olarak direk statik metodlarýný çaðýrýrýz. JoptionPane panelinde genellikle bir resim,bir yazý
alaný, bir girdi alaný (JtextField alaný), birde Seçilebilen düðmeler bulunur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static int showConfirmDialog(Component anapencere,Object mesaj,String baºlýk,int
opsiyontürü,int mesajtürü,Icon resim);
JOptionPane.ERROR_MESSAGE
JOptionPane.INFORMATION_MESSAGE
JOptionPane.PLAIN_MESSAGE
JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE
JOptionPane.CANCEL_OPTION
JOptionPane.CLOSED_OPTION
JOptionPane.NO_OPTION
JOptionPane.OK_OPTION
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JOptionPane.YES_OPTION
JOptionPane.UNINITILIZED_VALUE dur.
import [Link].*;
import [Link].*;
"Nurhan","Birsen","Ali","Veli","Mustafa","Ahmet","Mehmet","Ayhan"};
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.46 [Link] programý sonucunun JoptionPane çýktýsýnda görülmesi
JcolorChooser’da JoptionPane gibi kullanýlmaya hazýr bir dialog sýnýfýdýr. Renk seçmeye
yarar ve renk seçilmesi gereken her yerde kullanýlabilir. Bir önceki bölümdeki bir alýºtýrmada
bu özelliði kullanmýºtýk. Ýkinci bir örnekle pekiºtirelim :
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public ColorChooserDemo() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]);
[Link]([Link]);
[Link]([Link]);
[Link](true);
[Link](etiket, [Link]);
[Link]([Link]("etiket"));
[Link]().addChangeListener(
new ChangeListener() {
[Link](newColor);
);
[Link]([Link](
Container c = getContentPane();
[Link](etiketPaneli, [Link]);
[Link](tcc, [Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link](new WindowAdapter() {
});
[Link]();
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JFileChooser’da JcolorChooser gibi hazýr bir program demetidir. Bilgisayardan bir dosyayý
seçme ileminde yararlanýlýr. Dosya prosesleri konusunda Java Girdi çýktý programlanmasý
bölümüne bakýnýz.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public FileChooserDemo() {
[Link](new Insets(5,5,5,5));
[Link](new ActionListener() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e) {
if (returnVal == JFileChooser.APPROVE_OPTION) {
} else {
});
kayý[Link](new ActionListener() {
if (returnVal == JFileChooser.APPROVE_OPTION) {
} else {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
});
//Güzel bir görünüm için aç ve kapa düðmelerini ayrý bir panele yerleºtir.
[Link](acmaDugmesi);
[Link](kayýtDugmesi);
Container c = getContentPane();
[Link](buttonPanel, [Link]);
[Link](logScrollPane, [Link]);
[Link](new BasicWindowMonitor());
[Link]();
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.48 [Link] programý sonucunun JFrame çýktýsýnda görülmesi
[Link]
JAR çeºitli sýnýf ve ilgili dosyalarý bir arada bir pakete dönüºtürmek için geliºtirilmiº bir
teknolojidir. JAR teknolojisi peogramlarýn taºýnmasýný ve yeniden yüklenmesini daha kolay bir
hale getirir. Ayný zamanda JAR dosyasýnýn içindeki elementler sýkýºtýrýlmýº halde
bulunduklarýndan daha az yer kaplarlar. Bu yüzden bir JAR dosyasýnýn internet üzerinden
aktarýlmasý, açýk dosyalarýn tek tek aktarýlmasýndan daha kýsa süren bir prosestir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Alýºtýrma 5deki H7AL1 örneði için JAR dosyasý oluºturmak istersek :
komutunu kullanabiliriz. Problemi incelediðnizde JAR dosyasýnýn içine ilave edilen tüm
sýnýflarýn bu problemle direk olarak ilgili olduðunu görebilirsiniz.
jar tf [Link]
jar xf [Link]
komutu kullanýlýr. Örnek olarak yine alýºtýrma 5 de kullanýlan jar dosyasýnýn html dosyasýný
verebiliriz.
<HTML
<HEAD
<TITLE yildiz cizim ornegi</TITLE
</HEAD
<BODY
<H3yildiz cizim ornegi </H3
<applet code=[Link] archive="[Link]" width=600 height=500
</applet
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
</BODY
</HTML
x dosyalar arºivden geri çaðýrýlacaktýr. eðer listede sadece bir isim varsa
bunu jar dosyasý olarak alýr ve içindeki tüm dosyalarý listeler, eðer ilk simden sonra
komutta baºka isimler yer alýyorsa, sadece bu isimleri (eðer jarda mevcutsa) listeler.
0 sýkýºtýrma kullanma
7.24 ALIªTIRMALAR
Resimli bir JcheckBox örneði. Java döküman kütüphanesinden alýnýp adapte edilen bu
programda 16 resimden birisi JCheckBox kullanýlarak yapýlan seçime göre JLAbel
kullanýlarak gösteriliyor.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.52 : CheckBoxDemo .java Programý
import [Link].*;
import [Link].*;
import [Link].*;
JCheckBox chinButton;
JCheckBox glassesButton;
JCheckBox hairButton;
JCheckBox teethButton;
/*
* seçim olasýlýklarý
-g--
--h-
---t
c-h-
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
c--t
-gh-
-g-t
--ht
-ght // üç seçim
c-ht
cg-t
cgh-
seçimlerin anlamlarý :
c : çene
g : gözlük
h : saç
t : diº
*/
StringBuffer choices;
JLabel pictureLabel;
public CheckBoxDemo() {
[Link]('e');
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
glassesButton = new JCheckBox("Gözlük");
[Link]('G');
[Link](true);
[Link]('S');
[Link](true);
[Link]('D');
[Link](true);
[Link](myListener);
[Link](myListener);
[Link](myListener);
[Link](myListener);
"images/geek/geek-"
+ [Link]()
+ ".gif"));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]());
[Link](chinButton);
[Link](glassesButton);
[Link](hairButton);
[Link](teethButton);
setLayout(new BorderLayout());
add(checkPanel, [Link]);
add(pictureLabel, [Link]);
setBorder([Link](20,20,20,20));
int index = 0;
char c = '-';
if (source == chinButton) {
index = 0;
c = 'c';
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} else if (source == glassesButton) {
index = 1;
c = 'g';
index = 2;
c = 'h';
index = 3;
c = 't';
if ([Link]() == [Link])
c = '-';
[Link](index, c);
[Link](new ImageIcon(
"images/geek/geek-"
+ [Link]()
+ ".gif"));
[Link]([Link]());
[Link](new BasicWindowMonitor());
[Link](new CheckBoxDemo());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link](true);
[Link]
2. ªirin bir JComboBox örneði : Listeden yapýlan seçime göre resim deðiºecektir. Bu
programda java döküman kütüphanesinden alýnýp türkçeye adapte edilmiºtir.
import [Link].*;
import [Link].*;
import [Link].*;
JLabel picture;
public ComboBoxDemo() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// combo box yarat ve domuzu seç,
[Link](4);
[Link](new ActionListener() {
JComboBox cb = (JComboBox)[Link]();
});
petStrings[[Link]()] +
".gif"));
[Link]([Link](10,0,0,0));
setLayout(new BorderLayout());
add(petList, [Link]);
add(picture, [Link]);
setBorder([Link](20,20,20,20));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String s[])
[Link](new BasicWindowMonitor());
[Link]();
[Link](true);
[Link]
5. Appletin alt bölgesinde(SOUTH) iki sýra, her sýrada beºer dügmeden on düðme bulunan
bir applet oluºturunuz..
Appletin tepesinde bir TextField oluºturunuz. Her dügmeye basýldýðýnda textfieldde degiºik
bir yazý görünsün. Yazýlarý 2x5 lik bir String deðiºkeninden okuyarak Text fielde yükleyiniz.
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class Panel10 extends Applet implements ActionListener
{
private Panel buttonPanel;
private Button buttons[];
String s[]=
{"Birinci Butona Basildi",
"Ikinci Butona Basildi",
"Ucuncu Butona Basildi",
"Dorduncu Butona Basildi",
"Besinci Butona Basildi",
"Altinci Butona Basildi",
"Yedinci Butona Basildi",
"Sekizinci Butona Basildi",
"Dokuzunccu Butona Basildi",
"Onuncu Butona Basildi"};
TextField T;
public void init()
{
T=new TextField(s[0]);
buttonPanel=new Panel();
buttons=new Button[10];
[Link](new GridLayout(2,[Link]/2));
for(int i=0;i<[Link];i++)
{
buttons[i]=new Button("Button "+(i+1));
buttons[i].addActionListener(this);
[Link](buttons[i]);
}
setLayout(new BorderLayout());
add(buttonPanel,[Link]);
add(T,[Link]);
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.52 [Link] çýktýsý
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import renk;
int n1,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label renk1;
Label renk2;
"mor","portakal","pembe","beyaz","sari","acikmavi","lacivert"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private List renkListesi,arkaPlanRenkListesi;
private renk
r[]={[Link],[Link],[Link],[Link],[Link],[Link],[Link],[Link]
ikgri,[Link],
[Link],[Link],[Link],[Link],[Link],[Link]};
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Panel p,p1;
setBackground([Link]);
p=new Panel();
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new Panel();
[Link](new GridLayout(1,4));
[Link]([Link]);
renkListesi=new List(3,false);
arkaPlanRenkListesi=new List(3,false);
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](renk1);
[Link](renkListesi);
[Link](renk2);
[Link](arkaPlanRenkListesi);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
for(int i=0;i<[Link];i++)
[Link](Renkler[i]);
[Link](Renkler[i]);
add(p,[Link]);
add(p1,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
int indeks=[Link]();
if(indeks!=-1)
setBackground(r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
xi1=[Link]();
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void itemStateChanged(ItemEvent e)
[Link]());
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
else
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
yildiz.drawYildiz1(g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.53 [Link] çýktýsý
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import yildizSW;
import yildizPanelSWP;
import renk;
ListSelectionListener
int n1,xi1,yi1,yaricap1;
double aci1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
renk renk; //sinifin adi renk, nesne adi renk
JLabel kutu1;
JLabel kutu2;
JLabel kutu3;
JLabel kutu4;
JLabel kutu5;
JLabel renk2;
"koyugri","gri","yesil","acikgri","mor","portakal","pembe","beyaz",
"sari","acikmavi","lacivert"};
[Link],[Link],[Link],[Link],[Link],[Link],
[Link],[Link],[Link],[Link],[Link]};
JTextField kutugir1;
JTextField kutugir2;
JTextField kutugir3;
JTextField kutugir4;
JTextField kutugir5;
JPanel p,p1,p2;
yildizPanelSWP yp;
Container c;
c=getContentPane();
setBackground([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
p=new JPanel();
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new JPanel();
[Link](new GridLayout(1,4));
[Link]([Link]);
arkaPlanRenkListesi=new JList(Renkler);
[Link](3);
[Link](ListSelectionModel.SINGLE_SELECTION);
[Link](kutu1);
kutugir1=new JTextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new JTextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new JTextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new JTextField(3);
[Link](kutugir4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutu5=new JLabel("aciyi giriniz (derece) :");
[Link](kutu5);
kutugir5=new JTextField(3);
[Link](kutugir5);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](renk2);
[Link](aprl);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yp=new yildizPanelSWP(xi1,yi1,yaricap1,n1,aci1);
[Link](new GridLayout(2,1));
[Link](p);
[Link](p1);
[Link](p2,[Link]);
[Link](yp,[Link]);
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
xi1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Integer yi1i=new Integer([Link]());
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
[Link](xi1,yi1,yaricap1,n1,aci1);
[Link](r[indeks]);
repaint();
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
repaint();
[Link]
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import yildiz;
import renk;
implements ActionListener,ItemListener,MouseListener,MouseMotionListener
int n1,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label renk1;
Label renk2;
"mor","portakal","pembe","beyaz","sari","acikmavi","lacivert"};
private renk
r[]={[Link],[Link],[Link],[Link],[Link],[Link],[Link],[Link]
ikgri,[Link],
[Link],[Link],[Link],[Link],[Link],[Link]};
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Panel p,p1;
setBackground([Link]);
p=new Panel();
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new Panel();
[Link](new GridLayout(1,4));
[Link]([Link]);
renkListesi=new List(3,false);
arkaPlanRenkListesi=new List(3,false);
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutu4=new Label("yaricapi giriniz :");
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](renk1);
[Link](renkListesi);
[Link](renk2);
[Link](arkaPlanRenkListesi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
addMouseListener(this);
addMouseMotionListener(this);
for(int i=0;i<[Link];i++)
[Link](Renkler[i]);
[Link](Renkler[i]);
add(p,[Link]);
add(p1,[Link]);
int indeks=[Link]();
if(indeks!=-1)
setBackground(r[indeks]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
xi1=[Link]();
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paint(Graphics g)
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
else
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
yildiz.drawYildiz1(g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
xi1=[Link]();
yi1=[Link]();
[Link](""+xi1);
[Link](""+yi1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int xi2=[Link]();
int yi2=[Link]();
yaricap1=(int)[Link]((xi1-xi2)*(xi1-xi2)+(yi1-yi2)*(yi1-yi2));
aci1=-Math.atan2((yi2-yi1),(xi2-xi1))*180.0/[Link]-90;
[Link](""+yaricap1);
[Link](""+aci1);
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import renk;
int n1,xi1,yi1,yaricap1;
double aci1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
renk renk; //sinifin adi renk, nesne adi renk
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label bos1;
Label bos2;
Label bos3;
Label renk1;
Label kirmizi;
Label mavi;
Label yesil;
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Scrollbar kutukirmizi;
Scrollbar kutumavi;
Scrollbar kutuyesil;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//not : init metodunda t�m de§iŸkenlerin ilk de§erleri verilmelidir.
[Link](new GridLayout(5,4));
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kutugir5);
renk1=new Label("renk");
kirmizi=new Label("kirmizi");
mavi=new Label("mavi");
yesil=new Label("yesil");
kutukirmizi=new Scrollbar([Link],255,1,0,255);
kutumavi=new Scrollbar([Link],200,1,0,255);
kutuyesil=new Scrollbar([Link],0,1,0,255);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](bos1);
[Link](bos2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](bos3);
[Link](kirmizi);
[Link](yesil);
[Link](mavi);
[Link](renk1);
[Link](kutukirmizi);
[Link](kutumavi);
[Link](kutuyesil);
add(p,[Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
xi1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Integer yi1i=new Integer([Link]());
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
repaint();
int kirmizi1=[Link]();
int mavi1=[Link]();
int yesil1=[Link]();
renk=new renk(kirmizi1,mavi1,yesil1);
repaint();
[Link](renk);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
yildiz.drawYildiz1(g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
ªekil 7.56 Yýldýz çizdiren ve scrollbar kullanarak renk kontrolu yapan [Link] çýktýsý
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import renk;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//card menager Layout kullan�m�
private CardLayout c;
int n1,xi1,yi1,yaricap1;
double aci1;
Button B1,B2,B3,B4;
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label bos1;
Label bos2;
Label bos3;
Label renk1;
Label kirmizi;
Label mavi;
Label yesil;
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Scrollbar kutukirmizi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Scrollbar kutumavi;
Scrollbar kutuyesil;
c=new CardLayout();
p=new Panel();
[Link](c);
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
[Link](new GridLayout(1,4));
[Link](new GridLayout(1,4));
[Link](new GridLayout(1,4));
[Link](new GridLayout(2,4));
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutu3=new Label("kose sayisini giriniz :");
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
renk1=new Label("renk");
kirmizi=new Label("kirmizi");
mavi=new Label("mavi");
yesil=new Label("yesil");
kutukirmizi=new Scrollbar([Link],255,1,0,255);
kutumavi=new Scrollbar([Link],200,1,0,255);
kutuyesil=new Scrollbar([Link],0,1,0,255);
xi1=300;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](bos1);
[Link](bos2);
[Link](bos3);
[Link](kirmizi);
[Link](yesil);
[Link](mavi);
[Link](renk1);
[Link](kutukirmizi);
[Link](kutumavi);
[Link](kutuyesil);
[Link](p1,[Link]);
[Link](p2,[Link]);
[Link](p3,[Link]);
[Link](p4,[Link]);
B1=new Button("<<");
B2=new Button("<");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
B3=new Button(">");
B4=new Button(">>");
add(B1);
add(B2);
add(B3);
add(B4);
add(p,[Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
//sayfa se‡imi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]()==B1)
[Link](p);
else if([Link]()==B2)
[Link](p);
else if([Link]()==B3)
[Link](p);
else if([Link]()==B4)
[Link](p);
xi1=[Link]();
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double aci1i=new Double([Link]());
aci1=[Link]();
repaint();
int kirmizi1=[Link]();
int mavi1=[Link]();
int yesil1=[Link]();
renk=new renk(kirmizi1,mavi1,yesil1);
repaint();
[Link](renk);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
yildiz.drawYildiz1(g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.57 [Link], cardLayout sistemini kullanan yýldýz çizme appleti
import [Link];
import [Link].*;
import [Link].*;
import renk;
implements ActionListener,ItemListener,MouseListener,MouseMotionListener
Label renk1;
Label renk2;
"mor","portakal","pembe","beyaz","sari","acikmavi","lacivert"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private List renkListesi,arkaPlanRenkListesi;
private renk
r[]={[Link],[Link],[Link],[Link],[Link],[Link],[Link],[Link]
ikgri,[Link],
[Link],[Link],[Link],[Link],[Link],[Link]};
Panel p,p1;
int xi1,yi1,xi2,yi2;
int ii;
setBackground([Link]);
p=new Panel();
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new Panel();
[Link](new GridLayout(1,4));
[Link]([Link]);
renkListesi=new List(3,false);
arkaPlanRenkListesi=new List(3,false);
xi1=0;
yi1=0;
xi2=0;
yi2=0;
renk=new renk(255,200,0);
[Link](renk1);
[Link](renkListesi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](renk2);
[Link](arkaPlanRenkListesi);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
addMouseListener(this);
addMouseMotionListener(this);
for(int i=0;i<[Link];i++)
[Link](Renkler[i]);
[Link](Renkler[i]);
add(p1,[Link]);
int indeks=[Link]();
if(indeks!=-1)
setBackground(r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
repaint();
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
else
[Link]([Link]);
[Link](xi1,yi1,xi2,yi2);
xi1=[Link]();
yi1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void mousePressed(MouseEvent e)
xi1=[Link]();
yi1=[Link]();
xi2=[Link]();
yi2=[Link]();
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]
ªekil 7.58 Appletde fare kullanarak ºekil çizdiren [Link] applet görüntüsü
10. [Link], Alýºtýrma H7AL2'de yýldýz çizilmiº ve mouse'u basýp çekip býrakarak yeni
yýldýz oluºturulmuºtur. Ayný iºlemi yapan, fakat eºkenar çokken çizen programý oluºturunuz.
import [Link];
import [Link].*;
import [Link].*;
import eskenarcokgen;
import renk;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
implements ActionListener,ItemListener,MouseListener,MouseMotionListener
int n1,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label renk1;
Label renk2;
"mor","portakal","pembe","beyaz","sari","acikmavi","lacivert"};
private renk
r[]={[Link],[Link],[Link],[Link],[Link],[Link],[Link],[Link]
ikgri,[Link],
[Link],[Link],[Link],[Link],[Link],[Link]};
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Panel p,p1;
setBackground([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
p=new Panel();
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new Panel();
[Link](new GridLayout(1,4));
[Link]([Link]);
renkListesi=new List(3,false);
arkaPlanRenkListesi=new List(3,false);
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kutu5=new Label("aciyi giriniz (derece) :");
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](renk1);
[Link](renkListesi);
[Link](renk2);
[Link](arkaPlanRenkListesi);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
addMouseListener(this);
addMouseMotionListener(this);
for(int i=0;i<[Link];i++)
[Link](Renkler[i]);
[Link](Renkler[i]);
add(p,[Link]);
add(p1,[Link]);
int indeks=[Link]();
if(indeks!=-1)
setBackground(r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
xi1=[Link]();
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
repaint();
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
xi1=[Link]();
yi1=[Link]();
[Link](""+xi1);
[Link](""+yi1);
int xi2=[Link]();
int yi2=[Link]();
yaricap1=(int)[Link]((xi1-xi2)*(xi1-xi2)+(yi1-yi2)*(yi1-yi2));
aci1=-Math.atan2((yi2-yi1),(xi2-xi1))*180.0/[Link]-90;
[Link](""+yaricap1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](""+aci1);
repaint();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.59 Appletde ºekil çokgen çizdiren [Link] applet çýktýsý
11. [Link], Choice kullanarak eskenarcokken veya yildiz çizebilen applet programýný
oluºturunuz.
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import renk;
implements ActionListener,AdjustmentListener,ItemListener
int n1,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
//Label bos1;
//Label bos2;
Label bos3;
Label renk1;
Label kirmizi;
Label mavi;
Label yesil;
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Scrollbar kutukirmizi;
Scrollbar kutumavi;
Scrollbar kutuyesil;
Checkbox c1,c2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Panel p=new Panel();
[Link](new GridLayout(5,4));
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
[Link](kutugir5);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//bos1=new Label(" ");
renk1=new Label("renk");
kirmizi=new Label("kirmizi");
mavi=new Label("mavi");
yesil=new Label("yesil");
kutukirmizi=new Scrollbar([Link],255,1,0,255);
kutumavi=new Scrollbar([Link],200,1,0,255);
kutuyesil=new Scrollbar([Link],0,1,0,255);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](c1);
[Link](c2);
[Link](bos3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kirmizi);
[Link](yesil);
[Link](mavi);
[Link](renk1);
[Link](kutukirmizi);
[Link](kutumavi);
[Link](kutuyesil);
add(p,[Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
xi1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
aci1=[Link]();
repaint();
//renk de§iŸtirildiginde
int kirmizi1=[Link]();
int mavi1=[Link]();
int yesil1=[Link]();
renk=new renk(kirmizi1,mavi1,yesil1);
repaint();
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paint(Graphics g)
if ([Link]()==0)
[Link](renk);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
else if ([Link]()==1)
[Link](renk);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.60 Appletde choice kullanarak çokgen veya yýldýz çizdiren [Link] applet çýktýsý
12. [Link], Checkbox kullanarak eskenarcokken veya yildiz veya herikisinide bir arada
çizebilen (yýldýzýn köºelerinden geçen bir eskenar cokken) applet programýný oluºturunuz.
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import eskenarcokgen;
import renk;
int n1,xi1,yi1,yaricap1;
double aci1;
Label kutu1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Label kutu2;
Label kutu3;
Label kutu4;
Label kutu5;
Label renk1;
Label renk2;
"mor","portakal","pembe","beyaz","sari","acikmavi","lacivert"};
private renk
r[]={[Link],[Link],[Link],[Link],[Link],[Link],[Link],[Link]
ikgri,[Link],
[Link],[Link],[Link],[Link],[Link],[Link]};
TextField kutugir1;
TextField kutugir2;
TextField kutugir3;
TextField kutugir4;
TextField kutugir5;
Panel p,p1;
Checkbox c1,c2;
setBackground([Link]);
[Link](true);
[Link](false);
p=new Panel();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new GridLayout(3,4));
[Link]([Link]);
p1=new Panel();
[Link](new GridLayout(1,4));
[Link]([Link]);
renkListesi=new List(3,true);
arkaPlanRenkListesi=new List(3,true);
[Link](kutu1);
kutugir1=new TextField(3);
[Link](kutugir1);
[Link](kutu2);
kutugir2=new TextField(3);
[Link](kutugir2);
[Link](kutu3);
kutugir3=new TextField(3);
[Link](kutugir3);
[Link](kutu4);
kutugir4=new TextField(3);
[Link](kutugir4);
[Link](kutu5);
kutugir5=new TextField(3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](kutugir5);
[Link](c1);
[Link](c2);
xi1=300;
yi1=300;
n1=5;
yaricap1=100;
aci1=0;
[Link](""+xi1);
[Link](""+yi1);
[Link](""+n1);
[Link](""+yaricap1);
[Link](""+aci1);
renk=new renk(255,200,0);
[Link](renk1);
[Link](renkListesi);
[Link](renk2);
[Link](arkaPlanRenkListesi);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
for(int i=0;i<[Link];i++)
[Link](Renkler[i]);
[Link](Renkler[i]);
[Link](0);
[Link](3);
int indeks=[Link]();
setBackground(r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
add(p,[Link]);
add(p1,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e)
int indeks=[Link]();
if(indeks!=-1)
setBackground(r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
[Link](r[indeks]);
xi1=[Link]();
yi1=[Link]();
n1=[Link]();
yaricap1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
aci1=[Link]();
repaint();
[Link]());
repaint();
int indeks=[Link]();
if(indeks!=-1)
[Link](r[indeks]);
else
[Link]([Link]);
[Link](r[indeks]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
else if ( [Link]())
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](r[indeks]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
else if ([Link]())
[Link](r[indeks]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]([Link]);
[Link](g,xi1,yi1,n1,yaricap1,aci1/180.0*[Link]);
[Link]
ªekil 7.61 Appletde checkBox kullanarak çokgen ve/veya yýldýz çizdiren [Link] applet
çýktýsý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
13. [Link], [Link](alýºtýrma 12) programýnýn aynýsýný oluºturunuz, ancak renk
seçimini Scrollbar ile yapýnýz.
14. H7OD3_2000
JSlider kullanarak çizdiðiniz bir yýldýzýn çapýný büyütüp küçülten H7OD3_2000 programýný
yazýnýz.
import [Link].*;
import [Link].*;
import yildizSW;
import renk;
int xi,yi,yaricap;
int n;
double aci;
xi=xi1;
yi=yi1;
yaricap=yaricap1;
aci=aci1;
n=n1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int yaricap1,int n1,double aci1)
xi=xi1;
yi=yi1;
yaricap=yaricap1;
aci=aci1;
n=n1;
repaint();
[Link](g);
[Link]([Link]);
[Link](g,xi,yi,n,yaricap,aci/180.0*[Link]);
[Link]([Link]);
yildizSW.drawYildiz1(g,xi,yi,n,yaricap,aci/180.0*[Link]);
import BasicWindowMonitor;
import ovalPanelSWP;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H7OD3_2000 extends JFrame implements ChangeListener
private yildizpanelSWP p;
Color r=[Link];
Container c;
public H7OD3_2000()
super("JSlider Testi");
c=getContentPane();
p=new yildizpanelSWP(0);
cap=new JSlider([Link],0,200,10);
[Link](10);
[Link](true);
[Link](this);
[Link](p,[Link]);
[Link](cap,[Link]);
[Link]([Link]());
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//=====================================================
[Link](new BasicWindowMonitor());
[Link](400,400);
[Link](true);
[Link]
15. H7OD4_2000
Düðme (Button) kontrolü ile yýldýz vetya oval çizdirecek bir program yazýnýz. Yýldýz
düðmesine basýlýnca ekrana yýldýz gelsin, oval düðmesine basýlýnca ekrana oval gelsin
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class yildizovalPanelSWP extends JPanel
int anahtar;
int xi,yi,yaricap;
int n;
double aci;
anahtar=1;
xi=xi1;
yi=yi1;
yaricap=yaricap1;
aci=aci1;
n=n1;
anahtar=an;
xi=xi1;
yi=yi1;
yaricap=yaricap1;
aci=aci1;
n=n1;
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void setAnahtar(int an)
anahtar=an;
[Link](g);
[Link]([Link]);
if(anahtar==1)
[Link](g,xi,yi,n,yaricap,aci/180.0*[Link]);
[Link]([Link]);
yildizSW.drawYildiz1(g,xi,yi,n,yaricap,aci/180.0*[Link]);
else if(anahtar==2)
Graphics2D g2=(Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link](elips1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.64 H7OD4_2000 .java
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import yildizovalPanelSWP;
private yildizovalPanelSWP p;
private Container c;
public H7OD4_2000()
c=getContentPane();
[Link](new GridLayout(1,2));
B1=new JButton("yýldýz");
[Link](this);
[Link](B1);
B2=new JButton("Oval");
[Link](this);
[Link](B2);
[Link](p1,[Link]);
int x=(int)([Link]()/2.0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int y=(int)([Link]()/2.0);
int r=(int)([Link](x*x+y*y)/3.0);
p=new yildizovalPanelSWP(x,y,r,5,0);
[Link](p,[Link]);
int x=(int)([Link]()/2.0);
int y=(int)([Link]()/2.0);
int r=(int)([Link](x*x+y*y)/3.0);
if([Link]()==B1)
{[Link](x,y,r,5,0,1);}
else if([Link]()==B2)
{[Link](x-r,y-r,2*r,5,0,2);}
[Link](new BasicWindowMonitor());
[Link](250,200);
[Link](true);
[Link] - [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.63 ªekil -7.64 H7OD4_2000.java program çýktýsýnýn JFrame penceresinde görünümü
ªu ana kadar çeºitli örneklerde hem swing hem de awt olarak verdiðimiz örneklerle iki grafik
sistemindeli farklýlýk ve benzerlikleri belirtmeye çalýºtýk. ªimdi özellikle bu karºýlaºtýrmayý
çeºitli uygulama problemleri olarak göreceðiz. Bu örnekteki problemler temel olarak java
döküman kütüphanesinden alýnmýºtýr. Ýlk örneðimiz TextEventDemo awt de yazýlmýº bir
applet programý. TextArea penceresine giren her harfte TextEvent yardýmýyla kontrollar
yapýyoruz.
/*
*/
import [Link];
import [Link].*;
import [Link].*;
implements ActionListener {
TextField textField;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
TextArea textArea;
TextArea displayArea;
[Link](this);
[Link](new MyTextActionListener());
[Link](false);
setLayout(gridbag);
[Link] = [Link];
[Link] = 1.0;
[Link](new BorderLayout());
[Link]("North", textField);
[Link]("Center", textArea);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] = 2;
[Link](leftPanel, c);
add(leftPanel);
[Link] = 1.0;
[Link] = [Link];
[Link] = 1;
[Link](displayArea, c);
add(displayArea);
[Link] = 0.0;
[Link](button, c);
add(button);
[Link]();
String preface;
String newline;
newline = [Link]("[Link]");
preface = source
+ newline
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void textValueChanged(TextEvent e) {
TextComponent tc = (TextComponent)[Link]();
String s = [Link]();
try {
s = [Link](0, 10);
if ([Link]()) {
[Link]([Link].MAX_VALUE);
[Link]([Link](),
selStart, selEnd);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
/** düðmeye basýlýnca... */
[Link]("");
[Link]();
[Link]
/*
* Swing versiyonu
*/
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
implements ActionListener {
JTextField textField;
JTextArea textArea;
JTextArea displayArea;
[Link](this);
[Link](new MyTextActionListener());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JScrollPane scrollPane = new JScrollPane(textArea);
[Link](false);
[Link](gridbag);
[Link] = [Link];
[Link] = 1.0;
[Link](new BorderLayout());
[Link](textField, [Link]);
[Link](scrollPane, [Link]);
[Link] = 2;
[Link](leftPanel, c);
[Link](leftPanel);
[Link] = 1.0;
[Link] = [Link];
[Link] = 1;
[Link](displayScrollPane, c);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](displayScrollPane);
[Link] = 0.0;
[Link](button, c);
[Link](button);
[Link]();
setContentPane(contentPane);
String preface;
String newline;
newline = [Link]("[Link]");
preface = source
+ newline
update(e);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
update(e);
String s = null;
try {
[Link]([Link](),
selStart, selEnd);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e) {
[Link]("");
[Link]();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
AWT Converter (birim dönüºtürücü)
Swing Converter (birim dönüºtürücü)
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
/*
* 1.1 version.
*/
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
/**
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* measurements are the same, this program could be extended to
*/
setLayout(new GridLayout(2,0,5,5));
metricDistances);
add(metricPanel);
add(usaPanel);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
/**
*/
ConversionPanel to;
if (from == metricPanel)
to = usaPanel;
else
to = metricPanel;
[Link](multiplier * [Link]());
Dimension d = getSize();
/**
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
*/
[Link](new WindowAdapter() {
[Link](0);
});
[Link]();
[Link]("Center", converter);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.68 [Link] AWT programý
/*
* 1.1 version.
*/
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
implements ActionListener,
AdjustmentListener,
ItemListener {
TextField textField;
Choice unitChooser;
Scrollbar slider;
Converter controller;
Unit[] units;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
setLayout(gridbag);
controller = myController;
units = myUnits;
[Link] = [Link];
[Link](label, c);
add(label);
[Link](textField, c);
add(textField);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](units[i].description);
[Link](unitChooser, c);
add(unitChooser);
[Link](this);
[Link](max + 10);
[Link](block);
[Link](slider, c);
add(slider);
[Link](this);
/**
*/
double getMultiplier() {
int i = [Link]();
return units[i].multiplier;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Dimension d = getSize();
/**
* Choice bug.
*/
/**
*/
double getValue() {
double f;
try {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
f = (double)[Link]([Link]()).doubleValue();
} catch ([Link] e) {
f = 0.0;
return f;
setSliderValue(getValue());
[Link](this);
[Link](this);
[Link]([Link]([Link]()));
[Link](this);
void setValue(double f) {
setSliderValue(f);
[Link]([Link]((float)f));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
/** Set the slider value. */
void setSliderValue(double f) {
sliderValue = max;
if (sliderValue < 0)
sliderValue = 0;
[Link](sliderValue);
/*
* 1.1 version.
*/
String description;
double multiplier;
super();
[Link] = description;
[Link] = multiplier;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString() {
return s;
/*
* 1.1+Swing version.
*/
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
JPanel mainPane;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
/**
*/
public Converter() {
metricDistances,
dataModel);
usaDistances,
new FollowerRangeModel(dataModel));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//Create a JPanel, and add the ConversionPanels to it.
if (COLORS) {
[Link]([Link]);
[Link](new GridLayout(2,1,5,5));
[Link]([Link](5,5,5,5));
[Link](metricPanel);
[Link](usaPanel);
resetMaxValues(true);
maximum = (int)([Link] *
(usaMultiplier/metricMultiplier));
if (DEBUG) {
+ metricMultiplier
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
+ "; usaMultiplier = "
+ usaMultiplier
+ maximum);
[Link](maximum);
if (resetCurrentValues) {
[Link](maximum);
if (LOOKANDFEEL != null) {
if ([Link]("Metal")) {
lookAndFeel = [Link]();
} else if ([Link]("System")) {
lookAndFeel = [Link]();
} else if ([Link]("Mac")) {
lookAndFeel = "[Link]";
//PENDING: check!
} else if ([Link]("Windows")) {
lookAndFeel = "[Link]";
} else if ([Link]("Motif")) {
lookAndFeel = "[Link]";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
if (DEBUG) {
+ lookAndFeel);
try {
[Link](lookAndFeel);
} catch (ClassNotFoundException e) {
+ lookAndFeel);
} catch (UnsupportedLookAndFeelException e) {
+ lookAndFeel
} catch (Exception e) {
+ lookAndFeel
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
initLookAndFeel();
[Link](new WindowAdapter() {
[Link](0);
});
//JPanel is opaque.
[Link]([Link]);
if (COLORS) {
[Link]().setBackground([Link]);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 7.71 [Link] SWING programý
/*
* 1.1+Swing version.
*/
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
DecimalField textField;
JComboBox unitChooser;
JSlider slider;
ConverterRangeModel sliderModel;
Converter controller;
Unit[] units;
String title;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Unit[] myUnits,
ConverterRangeModel myModel) {
if (COLORS) {
setBackground([Link]);
setBorder([Link](
[Link](myTitle),
[Link](5,5,5,5)));
controller = myController;
units = myUnits;
title = myTitle;
sliderModel = myModel;
[Link](2);
[Link]([Link]());
[Link](new ActionListener() {
[Link]([Link]());
});
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//Add the combo box.
[Link](units[i].description);
[Link](0);
[Link](units[0].multiplier);
[Link](new ActionListener() {
int i = [Link]();
[Link](units[i].multiplier);
[Link](false);
});
[Link](new ChangeListener() {
[Link]([Link]());
});
return getPreferredSize();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]().height);
return getPreferredSize();
};
if (COLORS) {
[Link]([Link]);
[Link]([Link](
0,0,0,5));
[Link](new BoxLayout(unitGroup,
BoxLayout.Y_AXIS));
[Link](textField);
[Link](slider);
add(unitGroup);
add(unitChooser);
[Link](TOP_ALIGNMENT);
[Link](TOP_ALIGNMENT);
/**
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* Returns the multiplier (units/meter) for the currently
*/
return [Link]();
return [Link]();
/*
*/
String description;
double multiplier;
super();
[Link] = description;
[Link] = multiplier;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString() {
return s;
/*
* 1.1+Swing version.
*/
import [Link].*;
import [Link].*;
/**
**/
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
protected double value = 0.0;
public ConverterRangeModel() {
if (DEBUG) {
return multiplier;
if (DEBUG) {
[Link] = multiplier;
fireStateChanged();
if (DEBUG) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return maximum;
if (DEBUG) {
return (int)minimum;
//Do nothing.
if (DEBUG) {
return (int)getDoubleValue();
if (DEBUG) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("In ConverterRangeModel setValue");
setDoubleValue((double)newValue);
if (DEBUG) {
return value;
if (DEBUG) {
return (int)extent;
//Do nothing.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean getValueIsAdjusting() {
return isAdjusting;
int newExtent,
int newMin,
int newMax,
boolean newAdjusting) {
setRangeProperties((double)newValue,
newExtent,
newMin,
newMax,
newAdjusting);
int unusedExtent,
int unusedMin,
int newMax,
boolean newAdjusting) {
if (DEBUG) {
[Link]("setRangeProperties(): "
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
+ "newValue = " + newValue
newMax = minimum + 1;
if (DEBUG) {
newValue = newMax;
if (DEBUG) {
if (newValue != value) {
if (DEBUG) {
value = newValue;
changeOccurred = true;
if (newMax != maximum) {
if (DEBUG) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
maximum = newMax;
changeOccurred = true;
if (newAdjusting != isAdjusting) {
maximum = newMax;
isAdjusting = newAdjusting;
changeOccurred = true;
if (changeOccurred) {
fireStateChanged();
/*
* DefaultBoundedRangeModel.
*/
[Link]([Link], l);
[Link]([Link], l);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Object[] listeners = [Link]();
if (listeners[i] == [Link]) {
if (changeEvent == null) {
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
/*
* 1.1+Swing version.
*/
import [Link].*;
import [Link].*;
implements ChangeListener {
ConverterRangeModel dataModel;
[Link] = dataModel;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
fireStateChanged();
if (DEBUG) {
[Link]((int)(newMaximum *
(multiplier/[Link]())));
return (int)getDoubleValue();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void setValue(int newValue) {
setDoubleValue((double)newValue);
return [Link]()
* [Link]()
/ multiplier;
[Link](
newValue * multiplier
/ [Link]());
return [Link]();
[Link](newExtent);
int extent,
int min,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int max,
boolean adjusting) {
[Link](value*multiplyBy,
extent, min,
(int)(max*multiplyBy),
adjusting);
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
super(columns);
setDocument(new FormattedDocument(f));
format = f;
setValue(value);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
try {
retVal = [Link](getText()).doubleValue();
} catch (ParseException e) {
[Link]().beep();
return retVal;
setText([Link](value));
import [Link].*;
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link];
public FormattedDocument(Format f) {
format = f;
return format;
throws BadLocationException {
try {
[Link](proposedResult);
} catch (ParseException e) {
[Link]().beep();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("insertString: could not parse: " + proposedResult);
try {
if ([Link]() != 0)
[Link](proposedResult);
[Link](offs, len);
} catch (ParseException e) {
[Link]().beep();
/*
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* Swing versiyonu.
*/
import [Link].*;
import [Link].*;
implements ChangeListener {
ConverterRangeModel dataModel;
[Link] = dataModel;
[Link](this);
fireStateChanged();
if (DEBUG) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return (int)(modelMax * multiplyBy);
[Link]((int)(newMaximum *
(multiplier/[Link]())));
return (int)getDoubleValue();
setDoubleValue((double)newValue);
return [Link]()
* [Link]()
/ multiplier;
[Link](
newValue * multiplier
/ [Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getExtent() {
return [Link]();
[Link](newExtent);
int extent,
int min,
int max,
boolean adjusting) {
[Link](value*multiplyBy,
extent, min,
(int)(max*multiplyBy),
adjusting);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 7.67 AWT Converter (birim dönüºtürücü)
[Link]
bu programýn swing eºdeðeri ana metinde verilmiºti. ªimdi de swing versiyonuna göz atalým
/*
* awt versiyonu
*/
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link];
implements ActionListener,
ItemListener {
TextArea output;
String newline;
newline = [Link]("[Link]");
//Build
[Link]("bir");
[Link]("iki");
[Link]("üç");
[Link]("dört");
[Link]("beº");
[Link]("altý");
[Link]("yedi");
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
italyanca = new List(); //Defaults to none visible, only one selectable
[Link]("uno");
[Link]("due");
[Link]("tre");
[Link]("quattro");
[Link]("cinque");
[Link]("sei");
[Link]("sette");
[Link](this);
[Link](this);
setLayout(gridBag);
[Link](false);
[Link] = [Link];
[Link] = 1.0;
[Link] = 1.0;
[Link] = 2;
[Link](output, tc);
add(output);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] = [Link];
[Link](turkce, lc);
add(turkce);
[Link](italyanca, lc);
add(italyanca);
"turkce" : "italyanca";
"turkce" : "italyanca";
if ([Link]() == [Link]) {
[Link]("item #"
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
+ language + " dilinde. " + newline);
[Link]("item #"
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import BasicWindowMonitor;
String[] possibleValues,
String title,
String labelText) {
title, labelText);
if (dialog != null) {
[Link](initialValue);
[Link](comp);
[Link](true);
} else {
[Link]("ListDialog hatasý");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return value;
value = newValue;
[Link](value, true);
String labelText) {
//buttons
[Link](new ActionListener() {
[Link](false);
});
[Link](new ActionListener() {
[Link] = (String)([Link]());
[Link](false);
});
getRootPane().setDefaultButton(setButton);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// ana dialog kýsmý
[Link](ListSelectionModel.SINGLE_INTERVAL_SELECTION);
[Link](new MouseAdapter() {
if ([Link]() == 2) {
[Link]();
});
[Link](LEFT_ALIGNMENT);
[Link](list);
[Link](label);
[Link]([Link](new Dimension(0,5)));
[Link](listScroller);
[Link]([Link](10,10,10,10));
[Link]([Link]());
[Link](cancelButton);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link](new Dimension(10, 0)));
[Link](setButton);
[Link](listPane, [Link]);
[Link](buttonPane, [Link]);
pack();
[Link](new BasicWindowMonitor());
[Link](name);
[Link]([Link]);
[Link](new ActionListener()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](selectedName);
});
[Link](contentPane);
[Link]([Link](20,20,20,20));
[Link](intro);
[Link](name);
[Link]([Link](new Dimension(0,10)));
[Link](button);
[Link](JComponent.CENTER_ALIGNMENT);
[Link](JComponent.CENTER_ALIGNMENT);
[Link](JComponent.CENTER_ALIGNMENT);
[Link]();
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
20. bu program iºlem takip çubuk grafiði olan progressMonitor tanýmlamakta ve
kullanmaktadýr.
import [Link].*;
import [Link].*;
import [Link].*;
public ProgressMonitorDemo() {
super("ProgressMonitorDemo");
newline = [Link]("[Link]");
//create a timer
timer = new Timer(ONE_SECOND, new TimerListener());
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if ([Link]() || [Link]()) {
[Link]();
[Link]();
[Link]().beep();
[Link]();
[Link](true);
} else {
[Link]([Link]());
[Link]([Link]());
[Link]([Link]() + newline);
[Link]([Link]().getLength());
}
}
}
[Link](false);
[Link]();
[Link]();
}
}
[Link](new WindowAdapter() {
public void windowClosing(WindowEvent e) {[Link](0);}
});
[Link]();
[Link](true);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bu program detaylý bir dosya seçme sistemi tanýmlamaktadýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public FileChooserDemo() {
super("FileChooserDemo");
[Link](new Insets(5,5,5,5));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ImageIcon openIcon = new ImageIcon("images/[Link]");
[Link](new ActionListener() {
if (returnVal == JFileChooser.APPROVE_OPTION) {
} else {
});
[Link](new ActionListener() {
if (returnVal == JFileChooser.APPROVE_OPTION) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} else {
});
[Link](openButton);
[Link](saveButton);
[Link](buttonPanel, [Link]);
[Link](logScrollPane, [Link]);
[Link](new WindowAdapter() {
});
[Link]();
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bu program detaylý bir dosya seçme sistemi tanýmlamaktadýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
static private String newline = [Link]("[Link]");
public FileChooserDemo2() {
super("FileChooserDemo2");
[Link](new Insets(5,5,5,5));
[Link](new ActionListener() {
[Link](new ImageFilter());
[Link](new ImageFileView());
[Link](new ImagePreview(fc));
if (returnVal == JFileChooser.APPROVE_OPTION) {
+ "." + newline);
} else {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
});
[Link](sendButton, [Link]);
[Link](logScrollPane, [Link]);
[Link](new WindowAdapter() {
});
[Link]();
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bu program detaylý bir dosya seçme sistemi tanýmlamaktadýr.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class TreeDemo extends JFrame {
public TreeDemo() {
super("TreeDemo");
createNodes(top);
[Link]().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
[Link](new TreeSelectionListener() {
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if (node == null) return;
if ([Link]()) {
displayURL([Link]);
if (DEBUG) {
} else {
displayURL(helpURL);
if (DEBUG) {
[Link]([Link]());
});
if (playWithLineStyle) {
[Link]("[Link]", lineStyle);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
htmlPane = new JEditorPane();
[Link](false);
initHelp();
[Link](treeView);
[Link](htmlView);
[Link](minimumSize);
[Link](minimumSize);
getContentPane().add(splitPane);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
+ [Link]("[Link]")
+ [Link]("[Link]");
bookName = book;
try {
bookURL = null;
return bookName;
String s = null;
try {
s = "file:"
+ [Link]("[Link]")
+ [Link]("[Link]")
+ "[Link]";
if (DEBUG) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
displayURL(helpURL);
} catch (Exception e) {
try {
[Link](url);
} catch (IOException e) {
[Link](category);
//original Tutorial
"[Link]"));
[Link](book);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//Tutorial Continued
"[Link]"));
[Link](book);
"[Link]"));
[Link](book);
//Arnold/Gosling
[Link](book);
//FAQ
[Link](book);
//Chan/Lee
"[Link]"));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](book);
//Threads
"[Link]"));
[Link](book);
[Link](category);
//VM
"[Link]"));
[Link](book);
//Language Spec
"[Link]"));
[Link](book);
[Link](new WindowAdapter() {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void windowClosing(WindowEvent e) {[Link](0);}
});
[Link]();
[Link](true);
ªimdi bir grafik çizim programýna bakalým. Swing ve Graph2D olarak yazýlmýº olan bu
program bir dosyadan ([Link]) okuduðu veriye göre grafik çizmektedir.
Örneðin [Link] dosyasýnda
Baºlýk
x ekseni
y ekseni
[Link] 20 0 0 0
[Link] 3 0 0 255
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
deðerleri varsa Plot baºlýðý olarak “Baslýk”, x exseni yazýsý olarak “x ekseni”, y ekseni yazýsý
baºlýðý olarak “y ekseni”, toplam veri dosyasý olarak 2, veri dosyasý isimleri “[Link]” ve “[Link]”,
çizim ºekilleri 20 ve 3 ve renkler 00 255 ve 0 0 0 kullanmaktadýr.
//======================================================
// PlotShapes class
// =====================================================
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Graphics2D g;
int xabsmin,yabsmin;
int absheight,abswidth;
double xmin,xmax,ymin,ymax;
Font f;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
final static BasicStroke dashed = new BasicStroke(10.0f,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,
g=gi;
//Font fonts[]=[Link]().getAllFonts();
//f=fonts[2].deriveFont([Link],12);
//[Link](f);
xabsmin=xabsmini;
yabsmin=yabsmini;
absheight=absheighti;
abswidth=abswidthi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
xmin=xmini;
xmax=xmaxi;
ymin=ymini;
ymax=ymaxi;
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight),
(int)(xabsmin+(x2-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y2-ymin)/(ymax-ymin)*absheight)));
} //end of drawLine
ch1[0]=ch;
int h=[Link]().getHeight();
int w=h-2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](ch1,0,1,
(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth)-(int)(abswidth/200.0),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)+h/2);
} //end of [Link]
// starting at (x1,y1)
int h=[Link]().getHeight();
int w=h-2;
//[Link](ch,firstspace,numberofchars,
// (int)((xabsmin+(x1-xmin)/(xmax-xmin)*abswidth)+abswidth/80.0),
// (int)((yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)+h/2));
[Link](ch,firstspace,numberofchars,
(int)((xabsmin+(x1-xmin)/(xmax-xmin)*abswidth)+abswidth/80.0),
(int)((yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)));
} //end of [Link]
int h=[Link]().getHeight();
int w=h-2;
[Link](s,
(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
} //end of [Link]
[Link](new [Link]((int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth-
rectwidth/2),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight-rectheight/2),
rectwidth,rectheight));
}//end of drawRect
[Link](new [Link]((int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth-width/2),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight-height/2),
width,height));
}//end of drawRect
double Pi=[Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int xvalues[]=new int[side+1];
[Link]);
double angle_increase;
double angle;
angle_increase=2.0*Pi/side;
angle=Pi/2.0;
for(int i=0;i<side;i++)
xvalues[i]= (int)([Link](xabsmin+(x1-xmin)/
(xmax-xmin)*abswidth+radius*[Link](angle)));
yvalues[i]= (int)([Link](yabsmin+absheight-(y1-ymin)/
(ymax-ymin)*absheight-radius*[Link](angle)));
if(i==0)
xvalues[side]=xvalues[i];yvalues[side]=yvalues[i];
[Link](xvalues[0],yvalues[0]);
else
[Link](xvalues[i],yvalues[i]);
[Link](polygon);
}//end of drawPolygon
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void drawXTic(int ticNumber,double ticHeight,int ticSide)
double dtic=(xmax-xmin)/ticNumber;
double x1=xmin;
double y1=ymin;
if(ticSide==0)
for(int i=0;i<=ticNumber;i++)
drawLine(0,x1,y1,x1,(y1-ticHeight));
x1=x1+dtic;
else
for(int i=0;i<=ticNumber;i++)
drawLine(0,x1,y1,x1,(y1+ticHeight));
x1=x1+dtic;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//draw a series of y axis tics
double dtic=(ymax-ymin)/ticNumber;
double x1=xmin;
double y1=ymin;
if(ticSide==0)
for(int i=0;i<=ticNumber;i++)
drawLine(0,x1,y1,(x1-ticWidth),y1);
y1=y1+dtic;
else
for(int i=0;i<=ticNumber;i++)
drawLine(0,x1,y1,(x1+ticWidth),y1);
y1=y1+dtic;
double dtic=(xmax-xmin)/ticNumber;
double x1=xmin;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<=ticNumber;i++)
drawLine(0,x1,ymin,x1,ymax);
x1=x1+dtic;
double dtic=(ymax-ymin)/ticNumber;
double y1=ymin;
for(int i=0;i<=ticNumber;i++)
drawLine(0,xmin,y1,xmax,y1);
y1=y1+dtic;
//draw x numbers
double dtic=(xmax-xmin)/ticNumber;
double x1=xmin;
double y1=ymin;
String s;
s=" ";
for(int i=0;i<=ticNumber;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
s=[Link]([Link](x1*100.0)/100.00);
[Link](s,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)+(int)(abswidth/20.0));
x1=x1+dtic;
// draw y numbers
double dtic=(ymax-ymin)/ticNumber;
double x1=xmin;
double y1=ymin;
String s;
s=" ";
for(int i=0;i<=ticNumber;i++)
s=[Link]([Link](y1*100)/100.0)+" ";
[Link](s,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth-abswidth/10.0),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
y1=y1+dtic;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
// draw x labels
double x1=xmin+(xmax-xmin)/2.0;
double y1=ymin;
[Link](xLabel,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)
+(int)(abswidth/12.0));
// draw y labels
double x1=xmin-(xmax-xmin)/6.0;
double y1=ymax-(ymax-ymin)/3.0;
int n=[Link]();
[Link](0,n,ch,0);
//AffineTransform at=[Link](3.0*[Link]/2.0,
//(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
//(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
//[Link](at);
//[Link](yLabel,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
//(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
//at=[Link]([Link]/2.0,
//(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
//(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight));
//[Link](at);
for(int i=0;i<n;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
drawChar(ch[i],x1,y1);
y1=y1-(ymax-ymin)/30;
double x1=xmin+(xmax-xmin)/2.0;
double y1=ymax;
[Link](Label,(int)(xabsmin+(x1-xmin)/(xmax-xmin)*abswidth),
(int)(yabsmin+absheight-(y1-ymin)/(ymax-ymin)*absheight)-(int)(abswidth/40.0));
public void
int j;
//draw lines
switch ( i )
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
for(j=0;j<n[i]-1;j++)
drawLine(0,x[i][j],y[i][j],x[i][j+1],y[i][j+1]);
else if(x[i][j+1]>xmax)
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],xmax,(a+b*xmax));
else if(y[i][j+1]>ymax)
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],(ymax-a)/b,ymax);
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j]-b*x[i][j];
drawLine(0,x[i][j],y[i][j],(ymax-a)/b,(a+b*xmax));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
if(x[i][j]<xmin)
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j+1]-b*x[i][j+1];
drawLine(0,xmin,(a+b*xmin),x[i][j+1],y[i][j+1]);
if(y[i][j]<ymin)
double b=(y[i][j+1]-y[i][j])/(x[i][j+1]-x[i][j]);
double a=y[i][j+1]-b*x[i][j+1];
drawLine(0,(ymin-a)/b,ymin,x[i][j+1],y[i][j+1]);
}//end of for(j=0
[Link](new BasicStroke(1.0f));
}//end of if(plottype
//draw characters
else if(plottype[i]==10)
for(j=0;j<n[i];j++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
&& (y[i][j]>=ymin && y[i][j]<=ymax))
{ drawChar(ch[i],x[i][j],y[i][j]); }
}//end of for(j=0;
//draw rectangles
else if(plottype[i]==20)
for(j=0;j<n[i];j++)
{ drawRect(x[i][j],y[i][j],abswidth/100,abswidth/80); }
}//end of for(j=0;
//draw circle
else if(plottype[i]==21)
for(j=0;j<n[i];j++)
{ drawEllipse(x[i][j],y[i][j],abswidth/100,abswidth/80); }
}//end of for(j=0;
for(j=0;j<n[i];j++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
&& (y[i][j]>=ymin && y[i][j]<=ymax))
{drawPolygon(x[i][j],y[i][j],5,(plottype[i]-(int)(abswidth/20.0)));}
}//end of for(j=0;
Burada tanýmlanan ºekil, çizgi vs gerçek plot koordinat sistemini kullanmakta ve pencere
koordinat sistemiyle gerçek koordinat sistemleri arasýnda otomatik dönüºüm yapmaktadýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
final static BasicStroke stroke = new BasicStroke(1.0f);
public Plot2D()
setBackground([Link]);
setForeground([Link]);
try{
p1=new Plot();
try{
p1=new Plot();
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](this);
if ([Link]()) {
try {
[Link]();
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
drawShapes((Graphics2D)g);
return Printable.PAGE_EXISTS;
Dimension d=getSize();
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int rowspacing=(int)([Link]/100.0);
int columnspacing=(int)([Link]/50.0);
int rectWidth=gridWidth-columnspacing;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int rectHeight=gridHeight-rowspacing;
[Link]=(int)(0.25*rectWidth);
[Link]=(int)(0.2*rectHeight);
[Link]=(int)(0.65*rectWidth);
[Link]=(int)(0.7*rectHeight);
//[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
[Link](stroke);
[Link](fg);
[Link]([Link],[Link],[Link],[Link]);
[Link],[Link],[Link],[Link],[Link],[Link]);
if([Link]!=0)
[Link]([Link]);
if([Link]!=0)
[Link]([Link]);
int i,j;
for(i=0;i<[Link];i++)
[Link](new Color([Link][i],[Link][i],[Link][i]));
[Link](i,[Link],p1.x,p1.y,p1.n,[Link]);
}//end of for(i=0
[Link](fg);
[Link]([Link],([Link])/80.0,0);
[Link]([Link],([Link])/80.0,0);
[Link]([Link]);
[Link]([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](g);
Graphics2D g2 = (Graphics2D) g;
drawShapes(g2);
//======================================================
// =====================================================
/*
* Swing version.
*/
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import Plot2D;
import PlotShapesSW;
import BasicWindowMonitor;
Plot2D jta;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JTextField inputXmax; // input field Xmax
JButton printButton;
public PlotWindowSWF_2000()
super("Plot çizimi");
inputXmin=new JTextField(5);
inputXmax=new JTextField(5);
inputYmin=new JTextField(5);
inputYmax=new JTextField(5);
//*******
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
promptXLabel=new JLabel(" x ekseni baºlýðý : ");
inputLabel=new JTextField(30);
inputXLabel=new JTextField(30);
inputYLabel=new JTextField(30);
//*******
inputXntic=new JTextField(5);
inputYntic=new JTextField(5);
//*******
Dimension size=[Link]();
[Link]=800;
return size;
};
[Link](new GridLayout(1,8));
[Link](promptXmin);
[Link](inputXmin);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](promptXmax);
[Link](inputXmax);
[Link](promptYmin);
[Link](inputYmin);
[Link](promptYmax);
[Link](inputYmax);
[Link](mpane,[Link]);
[Link](new GridLayout(1,8));
[Link](promptXntic);
[Link](inputXntic);
[Link](promptYntic);
[Link](inputYntic);
[Link](promptXgridon);
[Link](inputXgridon);
[Link](promptYgridon);
[Link](inputYgridon);
[Link](xpane,[Link]);
//********
[Link](new GridLayout(3,2));
[Link](promptLabel);
[Link](inputLabel);
[Link](promptXLabel);
[Link](inputXLabel);
[Link](promptYLabel);
[Link](inputYLabel);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](lpane,[Link]);
//*********
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
jta=new Plot2D();
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
printButton=new JButton("Yazdýr");
[Link](new BorderLayout());
[Link](jta);
[Link](printButton,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](PLOTPANEL, pane2);
[Link](KONTROLPANEL, pane1);
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
Object source=[Link]();
if(source==inputXgridon)
if ([Link]() == [Link])
[Link]=0;
else
[Link]=1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if(source==inputYgridon)
if ([Link]() == [Link])
[Link]=0;
else
[Link]=1;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
if ([Link]()==printButton )
[Link]();
[Link]=[Link]();
[Link]=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]=[Link]();
//*****
[Link]=[Link]();
[Link]=[Link]();
//*****
[Link]=[Link]();
[Link]=[Link]();
[Link]=[Link]();
[Link]=[Link]();
[Link]();
[Link](new BasicWindowMonitor());
[Link](600,600);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
8. JAVADA HATA ANALÝZÝ VE YAKALANMASI
Javada diðer dillerden farklý olarak dil yapýsýnýn içinde hatalarý yakalamak için oldukça
geliºmiº bir sistem mevcuttur. Eger javada kontrol edilmemiº bir hata oluºursa program durur
ve hatayý yazar. Biz hata oluºtuðunda hata kontrol sisteminde hatayý kontrol edip programý
çalýºtýrmaya devam edebiliriz. Javadaki hata kontrol bloðu ºu ºekilde yazýlýr :
AbstractMethodError
ClassCircularityError
ClassFormatError
Error
ExceptionInInitializerError
IllegalAccessError
IncompatibleClassChangeError
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
InstantiationError
InternalError
LinkageError
NoClassDefFoundError
NoSuchFieldError
NoSuchMethodError
OutOfMemoryError
StackOverflowError
ThreadDeath
UnknownError
UnsatisfiedLinkError
VerifyError
VirtualMachineError
ArithmeticException
ArrayIndexOutOfBoundsException
ArrayStoreException
ClassCastException
ClassNotFoundException
CloneNotSupportedException
Exception
IllegalAccessException
IllegalArgumentException
IllegalMonitorStateException
IllegalStateException
IllegalThreadStateException
IndexOutOfBoundsException
InstantiationException
InterruptedException
NegativeArraySizeException
NoSuchFieldException
NoSuchMethodException
NullPointerException
NumberFormatException
RuntimeException
SecurityException
StringIndexOutOfBoundsException
EmptyStackException
MissingResourceException
NoSuchElementException
TooManyListenersException
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] exception listesi
CharConversionException
EOFException
FileNotFoundException
IOException
InterruptedIOException
InvalidClassException
InvalidObjectException
NotActiveException
NotSerializableException
ObjectStreamException
OptionalDataException
StreamCorruptedException
SyncFailedException
UTFDataFormatException
UnsupportedEncodingException
WriteAbortedException
Java hata oluºtuðununda hatanýn oluºtuðu metotun giriºinde kullanýlan throws kelimesini
takip eden Exception sýnýfýyla ayný exception gurubunu yaºýyan try-catch gurubuna aktarýr.
Bu metotun içinde gerekli noktada (hatanýn oluºacaðý ºartda) throw deyimi kullanýlarak hata
oluºtuðu aktarýlýr ve bu aktarým try-catch gurubu tarafýndan yakalanýr ve iºleme alýnýr.
Hata kontrolunu daha iyi açýklayabilmek amacýyla bir örnek vermek istiyoruz.
SifiraBölünmeException sinifinda yeni bir hata kontrol sinifi yaratiyoruz. Bu sinif ve java
kütüphanesinde mevcut olan tamsayý format hatasý (NumberFormatException)
sifirebolmetesti programýnda test edilmiºtir. Sonuçlar applet çýktýlarýnda görülmektedir. Eðer
bu hatalar kontrol edilmeseydi, java programý hata vererek çalýºmasýný durdururdu.
Programdaki hata kontrol deyimleri kalýn harfle verilmiºtir. Hata kontrol bloðu ise italik olarak
verilmiºtir.
public sifiraBolunmeException()
{
super("sifira bolmeye calistiniz ");
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Problem 8.2 Bizim tarafýmýzdan oluºturulan [Link] hata
kontrolü ve sayý formatý hata kontrolü (NumberFormatException) yapan
[Link] programý
import [Link];
import [Link].*;
import [Link].*;
import [Link];
import sifiraBolunmeException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{showStatus("iki tam sayi girmelisiniz.");}
catch(sifiraBolunmeException sbh)
{showStatus([Link]());}
}
}
[Link], [Link],[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
metotunda metotun once throws sifiraBolunmeException deyimiyle exception gondereceði
bildirilmiº, ve metotun içinde
try{
sayi1=[Link]([Link]());
sayi2=[Link]([Link]());
[Link]("");
[Link]("");
sonuc=bol(sayi1,sayi2);
showStatus(sayi1+" / "+sayi2+" = "+[Link](sonuc));
}
catch(NumberFormatException nfe)
{showStatus("iki tam sayi girmelisiniz.");}
catch(sifiraBolunmeException sbh)
{showStatus([Link]());}
}
}
8.2 ALIªTIRMALAR
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] programýnýnda gercek sayi girildiginde hata(Exception) vermek
için gerceksayiException tanýmlanmýºtýr. [Link] programýndaki
public gercekSayiException()
Problem 8.4 : bayagikesirException , bayaðý kesir sýfýra bölme hata taným programý
public bayagikesirException()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Problem 8.5 : [Link], hata kontrollü bayagikesir sýnýfý
//===========================================
//===========================================
import [Link].*;
import bayagikesirException;
import gercekSayiException;
// sinif bayagikesir
// islemlerini tanimlar
//
class bayagikesir {
// sinif degiskenleri
int pay;
int payda;
// kurucu metodlar
public bayagikesir()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
pay=0;
payda=1;
pay=npay;
payda=npayda;
//*** tanimlayiniz
double tmp1,tmp2;
tmp1=(int)npay;
tmp2=(int)npayda;
else
pay=(int)tmp1;
payda=(int)tmp2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public bayagikesir(int numer)
pay=numer;
payda=1;
public bayagikesir(bayagikesir c )
pay=[Link]();
payda=[Link]();
int n=pay;
int m=payda;
if(n==0)
return m;
if(m==0)
return n;
while(m != n)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(n>m)
n=n-m;
else
m=m-n;
return n;
//sadelestir
int isaret=1;
if(pay<0)
isaret=-isaret;
pay=-pay;
if(payda<0)
isaret=-isaret;
payda=-payda;
int ebob=enbuyukortakbolen();
ebob=[Link](ebob);
pay=isaret*pay/ebob;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
payda=payda/ebob;
return pay;
return payda;
pay=r;
payda=i;
pay=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
payda=[Link]();
pay=nr;
payda=ni;
pay=nr;
payda=1;
bayagikesirGir((int)d*10000,10000);
sadelestir();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return ((double)pay/(double)payda);
[Link]((int)d*10000,10000);
[Link]();
return b;
payda = payda*[Link]();
sadelestir();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sadelestir();
payda = payda*[Link]();
sadelestir();
sadelestir();
pay = pay*[Link]();
payda = payda*[Link]();
sadelestir();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void carp(int sag ) throws bayagikesirException
pay = pay*sag;
sadelestir();
pay = pay*[Link]();
payda = payda*[Link]();
sadelestir();
payda = payda*sag;
sadelestir();
// aktar�r
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int r1= [Link]() * [Link]() + [Link]() * [Link]();
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
// bir bayagikesir ve bir Pay say�n�n toplam�n� return deyimiyle bayagikesir olarak
// aktar�r
int i1=[Link]();
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
// bir bayagikesir ve bir Pay say�n�n toplam�n� return deyimiyle bayagikesir olarak
// aktar�r
int i1=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
//===================================
// aktar�r
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
// bir bayagikesir ve bir Pay say�n�n toplam�n� return deyimiyle bayagikesir olarak
// aktar�r
int i1=[Link]();
bayagikesir sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
// bir bayagikesir ve bir Pay say�n�n toplam�n� return deyimiyle bayagikesir olarak
// aktar�r
int i1=[Link]();
bayagikesir sonuc;
sonuc=new bayagikesir(r1,i1);
[Link]();
return sonuc;
//===================================
bayagikesir sonuc;
sonuc=new bayagikesir([Link]()*[Link](),[Link]()*[Link]());
[Link]();
return sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static bayagikesir carp(bayagikesir sol, int sag) throws bayagikesirException
bayagikesir sonuc;
sonuc=new bayagikesir([Link]()*sag,[Link]());
[Link]();
return sonuc;
bayagikesir sonuc;
sonuc=new bayagikesir([Link]()*sol,[Link]());
[Link]();
return sonuc;
double a=[Link]()*[Link]()+[Link]()*[Link]();
bayagikesir sonuc;
sonuc=new bayagikesir((int)([Link]()*[Link]()),(int)([Link]()*[Link]()));
[Link]();
return sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static bayagikesir bol(bayagikesir sol, int sag) throws bayagikesirException
bayagikesir sonuc;
sonuc=new bayagikesir([Link](),([Link]()*sag));
[Link]();
return sonuc;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean buyuktur_esittir(bayagikesir sol,bayagikesir sag)
String b="";
if([Link]([Link]())!=1)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else
b=b+[Link]()+" ";
return b;
String b="";
if([Link](Payda())!=1)
else
b=b+Pay()+" ";
return b;
};
Problem 8.6 : bayagikesirException, bayaðý kesir sýfýra bölme hata test programý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
//tarafindan yaratilmistir.
import bayagikesir;
class H6O1
double n1,n2;
int n=[Link]();
int i;
for(i=0;i<[Link];i++)
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("bir bayagikesir giriniz : ");
n1=[Link]();
n2=[Link]();
sayi[i]=new bayagikesir(n1,n2);
catch (gercekSayiException e)
[Link]([Link]());
i--;
for(i=0;i<[Link];i++)
try{
[Link](sayi[i]);
catch (bayagikesirException e)
[Link]([Link]());
[Link]("Toplam = "+[Link]());
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]);
catch (bayagikesirException e)
[Link]([Link]());
[Link]("Ortalama = "+[Link]());
import [Link];
import bayagikesir;
class H8AL1_2000
double n1,n2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n=[Link]();
int i;
String s="";
for(i=0;i<[Link];i++)
try{
n1=[Link]();
n2=[Link]();
sayi[i]=new bayagikesir(n1,n2);
catch (gercekSayiException e)
JOptionPane.ERROR_MESSAGE);
i--;
catch (bayagikesirException e)
JOptionPane.ERROR_MESSAGE);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(i=0;i<[Link];i++)
try{
[Link](sayi[i]);
catch (bayagikesirException e)
JOptionPane.ERROR_MESSAGE);
s+="Ortalama = "+[Link]();
try{
[Link]([Link]);
catch (bayagikesirException e)
JOptionPane.ERROR_MESSAGE);
s+="Ortalama = "+[Link]();
[Link](null,s,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](0);
ݺlemleri tek tek sýrayla ve iyi bir ºekilde yapabilseydik belki de çok mükemmel sonuçlar
alabilirdik. Fakat Dünyadaki hemen hemen hiçbirºey tek tek sýrayla çalýºmaz. Ýnsan vücudu
da dahil bir çok doðal sistem paralel olarak çalýºýr. Yani bir iºlem yapýlýrken parelelinde diðer
bir iºlem yapýlmaya devam eder. Bizim ºu anda kullandýðýmýz bilgisayarlarýn büyük bir
bölümü tek bir iºlemciye(processor) sahiptir. Birden fazla iºlemciye sahip paralel
bilgisayarlarda, her bir iºlemcide bir iº tanýmlayarak paralel kullaným mümkündür. Fakat tek
iºlemcili sistemler için(seri bilgisayar) yazýlmýº olan program dilleri genel olarak birden fazla
iºlemin ayný anda yapýlmasýna izin vermezler. Modern bilgisayar dilleri arasýnda sadece Ada
ve Java dilleri bir iºlemcide birden fazla iºlemin (programýn) ayný anda kullanýlmasýna izin
verir. C++ dili birden fazla programýn ayný anda kullanýlmasýna izin vermez. Bu yüzden tek
kullanýmlý bir programlama dilidir.
CPU nun Parelel kullanýmý Runnable interface’i veya abstract Thread sýnýfýni kullanarak
gerçekleºtirilir. Aºaðýda Bu iki yolu kullanarak bir digital saat programý oluºturulmuºtur. Bu
programlarda saat sadece tek bir program olmasýna raðmen bilgisayarýn belleðinde eðer
devamlý çalýºtýrýlacak olursa baºka hiçbir programýn çalýºtýrýlamýyacaðý düºünülerek paralel
kullanýmlý olarak verilmiºtir.
Zaman içinde programlarý bilgisayarda kontrollu yapýda kullanmak ayný zamanda bize gerçek
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
JFrame a;
{a=ai;}
while(true)
[Link]();
[Link]();
try {[Link](1000);}
catch(InterruptedException e)
{[Link]([Link]());}
JLabel jb;
Font F;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Date D;
saatThreadSWF r;
GregorianCalendar takvim;
public saatSWF()
Container cc=getContentPane();
jb=new JLabel("");
F=new Font("TimesRoman",[Link],24);
[Link](F);
takvim=new GregorianCalendar(pdt);
D=new Date();
[Link](D);
r=new saatThreadSWF(this);
[Link](jb);
[Link]();
D=new Date();
[Link](D);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link])+" / "+
[Link](Calendar.HOUR_OF_DAY)+" : "+
[Link]([Link])+" : "+
[Link]([Link]);
[Link](s);
[Link](new BasicWindowMonitor());
[Link](400,100);
[Link](true);
[Link]
Program 9.3 [Link] sýnýfýnýn Runnable interface’i ile yazýlýmý ve applet çýktýsý
import [Link];
import [Link];
import [Link];
import [Link];
Date theDate;
Thread runner;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void start()
{
if(runner==null)
{
runner=new Thread(this);
[Link]();
}
}
while(true)
{
theDate=new Date();
repaint();
try {[Link](1000);}
catch(InterruptedException e) {}
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 9.4 saatRunnableSWF sýnýfýnýn Runnable interface’i ile yazýlýmý
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class saatRunnableSWF extends JFrame implements Runnable
{
JLabel jb;
Font F;
Date D;
saatThreadSWF r;
GregorianCalendar takvim;
Thread runner;
public saatRunnableSWF()
{
super("Digital Saat Runnable implement Thread");
Container cc=getContentPane();
jb=new JLabel("");
F=new Font("TimesRoman",[Link],24);
[Link](F);
// Türkiye standart (Greenwitch zamanýna göre iki saat ileride)
String[] ids = [Link](+2 * 60 * 60 * 1000);
SimpleTimeZone pdt = new SimpleTimeZone(+2 * 60 * 60 * 1000, ids[0]);
takvim=new GregorianCalendar(pdt);
D=new Date();
[Link](D);
setBackground([Link]);
r=new saatThreadSWF(this);
[Link](jb);
[Link]();
}
public void start()
{
if(runner==null)
{
runner=new Thread(this);
[Link]();
}
}
public void run()
{
while(true)
{
repaint();
try {[Link](1000);}
catch(InterruptedException e)
{[Link]([Link]());}
}
}
public void paint(Graphics g)
{
D=new Date();
[Link](D);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String s=" ["+
[Link]([Link]) +" / "+
[Link]([Link])+" / "+
[Link]([Link]) +" ] "+
[Link](Calendar.HOUR_OF_DAY)+" : "+
[Link]([Link])+" : "+
[Link]([Link]);
[Link](s);
}
public static void main(String[] args)
{
saatRunnableSWF pencere= new saatRunnableSWF();
[Link](new BasicWindowMonitor());
[Link](400,100);
[Link](true);
}
}
Ýkinci olarak biraz daha karýºýk bir örneðe göz atalým. Bu örnekte, iki tane program bilgisayar
belleginde ayný anda çalýºacaktýr. Birinci program ikinci programla ortak olarak kullanýlan bir
bilgisayar int hafýza noktasýna sýrasýyla birden ona kadar deðiºen bir rakam yazacak, ikinci
program da ayný noktadan (OrtakHucreden) yazýlan deðeri okuyacaktýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](count);
[Link]("OrtakInteger "+count+" degerini uretti");
try{
sleep( (int) ([Link]()*5000 ) );
}
catch(InterruptedException e)
{
[Link]("Exeption "+[Link]());
}
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
OrtakInteger 4 degerini uretti
OrtakInteger 5 degerini uretti
Kullan Integer5 degerini okudu
Kullan Integer5 degerini okudu
OrtakInteger 6 degerini uretti
OrtakInteger 7 degerini uretti
Kullan Integer7 degerini okudu
OrtakInteger 8 degerini uretti
OrtakInteger 9 degerini uretti
Kullan Integer9 degerini okudu
import [Link].*;
import [Link].*;
import [Link].*;//runnable interfacei kullanarak
public UretInteger(TutInteger h)
{
pTut=h;
thread = new Thread(this);
[Link]();
}
catch(InterruptedException exception) {
[Link]("Exception " + [Link]());
}
}
}
}
public KullanInteger(TutInteger h) {
cTut = h;
thread= new Thread(this);
[Link]();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void run() {
int Intdegeri=0;
while(Intdegeri != 9) {
try {
[Link]((int)([Link]()*3000));
}
catch(InterruptedException e) {
[Link]("Exception " + [Link]());
}
Intdegeri = [Link]();
[Link]("Kullan Integer " + Intdegeri+"degerini yakaladi");
}
}
}
class TutInteger {
private int OrtakInt;
public void setOrtakInt(int Intdegeri) {OrtakInt = Intdegeri;}
public int getOrtakInt() { return OrtakInt;}
}
import [Link].*;
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link]();
}
}
public Uretinteger(Tutinteger h)
{
pTut=h;
}
try{
sleep( (int) ([Link]()*500 ) );
}
catch(InterruptedException e)
{
[Link]("Hata : "+[Link]());
}
}
}
}
public Consumeinteger(Tutinteger h)
{
cTut=h;
}
intdegeri=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("Hata "+[Link]());
}
intdegeri=[Link]();
}
}
}
class Tutinteger
{
private int Ortakint[] = {9,9,9,9,9};
private boolean writeable = true;
private boolean okunabilir = false;
private int YerelOku =0, YerelYaz=0;
private TextArea cikti;
Ortakint[YerelYaz]=intdegeri;
okunabilir = true;
[Link]("\n Uretilen "+intdegeri+" Yazilan "+YerelYaz);
YerelYaz = ++YerelYaz % 5;
printBuffer(cikti, Ortakint);
if(YerelYaz==YerelOku)
{
writeable=false;
[Link]("\nDEPOLAMA YERLER˜ DOLU ");
}
notify();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public synchronized int getOrtakint()
{
int intdegeri;
while (!okunabilir)
{
try{
[Link](" KULLANMAK iCiN BEKLiYOR ");
wait();
}
catch (InterruptedException e)
{
[Link]("hata:"+[Link]() );
}
}
writeable=true;
intdegeri=Ortakint[YerelOku];
printBuffer(cikti, Ortakint);
if (YerelOku==YerelYaz)
{okunabilir=false;
[Link]("\niNTEGER DEPOSU BOS");
}
notify();
return intdegeri;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Uretilen 5 Yazilan 0 yazilan hucre 1 okunan hucre 4 depo: 5 1 2 3 4
Uretilen 6 Yazilan 1 yazilan hucre 2 okunan hucre 4 depo: 5 6 2 3 4
Uretilen 7 Yazilan 2 yazilan hucre 3 okunan hucre 4 depo: 5 6 7 3 4
Kullanilan 4 Okundugu Hucre 4 yazilan hucre 3 okunan hucre 0 depo: 5 6 7 3 4
Kullanilan 5 Okundugu Hucre 0 yazilan hucre 3 okunan hucre 1 depo: 5 6 7 3 4
Uretilen 8 Yazilan 3 yazilan hucre 4 okunan hucre 1 depo: 5 6 7 8 4
Kullanilan 6 Okundugu Hucre 1 yazilan hucre 4 okunan hucre 2 depo: 5 6 7 8 4
Uretilen 9 Yazilan 4 yazilan hucre 0 okunan hucre 2 depo: 5 6 7 8 9
Kullanilan 7 Okundugu Hucre 2 yazilan hucre 0 okunan hucre 3 depo: 5 6 7 8 9
Kullanilan 8 Okundugu Hucre 3 yazilan hucre 0 okunan hucre 4 depo: 5 6 7 8 9
Kullanilan 9 Okundugu Hucre 4 yazilan hucre 0 okunan hucre 0 depo: 5 6 7 8 9
INTEGER DEPOSU BOS
class OrtakHucreSyn
{
public static void main(String args[])
{
TutInteger h=new TutInteger();
UretInteger p=new UretInteger(h);
KullanInteger c= new KullanInteger(h);
[Link]();
[Link]();
}
}
public UretInteger(TutInteger h)
{
pTut=h;
}
try{
sleep( (int) ([Link]()*3000 ) );
}
catch(InterruptedException e)
{
[Link]("Exeption "+[Link]());
}
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class KullanInteger extends Thread
{
private TutInteger cTut;
public KullanInteger(TutInteger h)
{
cTut=h;
}
class TutInteger
{
private int OrtakInt;
private boolean Yazilabilir = true;
OrtakInt=Intedegeri;
Yazilabilir=false;
notify();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
while (Yazilabilir)
{
try{
wait();
}
catch (InterruptedException e)
{
[Link]("Exception:"+[Link]() );
}
}
Yazilabilir=true;
notify();
return OrtakInt;
}
}
9.3 ALIªTIRMALAR
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1. daha önce tanýmladýðýmýz [Link] (problem 6.19) programýný da kullanarak burada
analog bir saat tanýmý yapýlmýºtýr. Analog saat her saniyede bir çalýºmakta ve kendini tekrar
çizmektedir. Programý inceleyiniz.
import [Link];
import [Link].*;
import [Link].*;
import yildiz;
import polar;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try{
[Link]([Link]);
[Link](g,200,200,170);
[Link]([Link]);
[Link](g,200,200,16,160,aci2,0);
[Link]([Link]);
[Link](g,200,200,8,110,aci3,0);
[Link]([Link]);
[Link](g,200,200,10,60,aci1,0);
[Link]([Link]);
[Link](g,200,200,165);
[Link](g,200,200,170);
[Link](g,200,200,16,160,aci2,0);
[Link](g,200,200,8,110,aci3,0);
yildiz.drawYildiz1(g,200,200,10,60,aci1);
aci1-=[Link]/30.0;
aci2-=[Link]/1800.0;
aci3-=[Link]/21600.0;
for(int i=0;i<12;i++)
{
[Link](165,[Link]*i/6);
[Link]([Link]);
if(i==0||i==3||i==6||i==9||i==12)
{
[Link](g,(int)([Link]()+200),(int)([Link]()),5,20,0);
[Link]([Link]);
yildiz.drawYildiz1(g,(int)([Link]()+200),(int)([Link]()),5,20,0);
}
else
{
[Link]([Link]);
[Link](g,(int)([Link]()+200),(int)([Link]()),15,10,0);
//yildiz.drawYildiz1(g,(int)([Link]()+200),(int)([Link]()),15,10,0);
}
}
}
catch(NullPointerException e){}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 9.3 [Link] appleti
import [Link].*;
import [Link].*;
import [Link].*;
import yildizSW;
import polar;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
super("Analog Saat");
c=new Date();
// Türkiye standart (Greenwitch zamanýna göre iki saat ileride)
String[] ids = [Link](+2 * 60 * 60 * 1000);
if ([Link] == 0)
[Link](0);
SimpleTimeZone pdt = new SimpleTimeZone(+2 * 60 * 60 * 1000, ids[0]);
GregorianCalendar takvim=new GregorianCalendar(pdt);
[Link](c);
p=new polar();
setBackground([Link]);
aci1=-[Link]([Link])/60.0*[Link]*2;
aci2=-[Link]([Link])/60.0*[Link]*2;
aci3=-(([Link]([Link]))%12)/12.0*[Link]*2+aci2/12.0;
y=new yildizCiz2ThreadSWF(this);
[Link]();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
catch(NullPointerException e){}
}
public static void main(String[] args)
{
analogSaatSWF pencere= new analogSaatSWF();
[Link](new BasicWindowMonitor());
[Link](400,400);
[Link](true);
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch(InterruptedException e)
{[Link]([Link]());}
}
}
} //y�ld�zciz2Thread s�n�f�n�n sonu
public class analogSaatSWA extends JApplet
{
yildizCiz2ThreadSWA y;
double aci1,aci2,aci3;
Date c;
polar p;
public void init()
{
// Türkiye standart (Greenwitch zamanýna göre iki saat ileride)
String[] ids = [Link](+2 * 60 * 60 * 1000);
if ([Link] == 0)
[Link](0);
SimpleTimeZone pdt = new SimpleTimeZone(+2 * 60 * 60 * 1000, ids[0]);
GregorianCalendar takvim=new GregorianCalendar(pdt);
c=new Date();
[Link](c);
p=new polar();
setBackground([Link]);
aci1=-[Link]([Link])/60.0*[Link]*2;
aci2=-[Link]([Link])/60.0*[Link]*2;
aci3=-(([Link]([Link]))%12)/12.0*[Link]*2+aci2/12.0;
y=new yildizCiz2ThreadSWA(this);
[Link]();
}
public void paint(Graphics g)
{
try{
[Link]([Link]);
[Link](g,200,200,170);
[Link]([Link]);
[Link](g,200,200,16,160,aci2,0);
[Link]([Link]);
[Link](g,200,200,8,110,aci3,0);
[Link]([Link]);
[Link](g,200,200,10,60,aci1,0);
[Link]([Link]);
[Link](g,200,200,165);
[Link](g,200,200,170);
[Link](g,200,200,16,160,aci2,0);
[Link](g,200,200,8,110,aci3,0);
yildizSW.drawYildiz1(g,200,200,10,60,aci1);
aci1-=[Link]/30.0;
aci2-=[Link]/1800.0;
aci3-=[Link]/21600.0;
for(int i=0;i<12;i++)
{
[Link](165,[Link]*i/6);
[Link]([Link]);
if(i==0||i==3||i==6||i==9||i==12)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](g,(int)([Link]()+200),(int)([Link]()),5,20,0);
[Link]([Link]);
yildizSW.drawYildiz1(g,(int)([Link]()+200),(int)([Link]()),5,20,0);
}
else
{
[Link]([Link]);
[Link](g,(int)([Link]()+200),(int)([Link]()),15,10,0);
//yildiz.drawYildiz1(g,(int)([Link]()+200),(int)([Link]()),15,10,0);
}
}
}
catch(NullPointerException e){}
}
}
2. [Link] programýný inceleyiniz.
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
break;
case 'g':
which_light='y';
[Link]([Link]);
[Link](x+10,y+hight_diff,radius*2,radius*2);
[Link](x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
[Link]([Link]);
[Link](x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
repaint(1000);
}
}
Program 9.13 : trafikIsigiSWP .java JPanel programý, trafik ýºýðý panelini tanýmlar
import [Link].*;
import [Link].*;
import yildizSW;
import [Link].*;
import renk;
public class trafikIsigiSWP extends JPanel
{
private char which_light='y';
private static int x=10;
private static int y= 40;
private static int h=360;
private static int w=100;
private static int radius=40;
private static int hight_diff=30;
public trafikIsigiSWP()
{
which_light='y';
}
public trafikIsigiSWP(char l)
{
which_light=l;
}
public void setIsik( char l)
{
which_light=l;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public char getIsik()
{
return which_light;
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link]([Link]);
Rectangle2D dikdortgen1=new [Link](x,y,w,h);
[Link](dikdortgen1);
[Link]([Link]);
Rectangle2D dikdortgen2=new [Link](x-1,y-1,w+2,h+2);
[Link](dikdortgen2);
Rectangle2D dikdortgen3=new [Link](x-2,y-2,w+4,h+4);
[Link](dikdortgen3);
Rectangle2D dikdortgen4=new [Link](x-4,y-4,w+8,h+8);
[Link]([Link]);
[Link](dikdortgen3);
Ellipse2D elips1=new [Link](x+10,y+hight_diff,radius*2,radius*2);
Ellipse2D elips2=new [Link](x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
Ellipse2D elips3=new [Link](x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
switch(which_light) {
case 'r':
which_light='g';
[Link]([Link]);
[Link](elips1);
[Link](elips2);
[Link]([Link]);
[Link](elips3);
break;
case 'y':
which_light='r';
[Link]([Link]);
[Link](elips2);
[Link](elips3);
[Link]([Link]);
[Link](elips1);
break;
case 'g':
which_light='y';
[Link]([Link]);
[Link](elips3);
[Link](elips1);
[Link]([Link]);
[Link](elips2);
break;
//repaint(2000);
}
}
}
Program 9.14 : trafikIsigiSWF .java JFrame programý, trafik ýºýðý tanýmlar ve çalýºtýrýr
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
public class trafikIsigi1SWF extends JFrame implements ActionListener
{
isikKontroluThread1 yik;
JButton light_switch;
JTextField t1,t2;
JLabel l0,l1,l2,l3,l4;
trafikIsigi1SWP ti1;
Container c;
public trafikIsigi1SWF()
{
c=getContentPane();
JPanel p1=new JPanel();
[Link](new GridLayout(2,4));
yik=new isikKontroluThread1(this);
[Link]();
ti1=new trafikIsigi1SWP(yik);
light_switch = new JButton("Iºýðý deðiºtir");
light_switch.setForeground([Link]);
light_switch.setBackground([Link]);
t1=new JTextField(""+[Link]());
t2=new JTextField(""+[Link]());
l0=new JLabel(" ");
l1=new JLabel("yesil isik yanma zamani : ");
l2=new JLabel("saniye ");
l3=new JLabel("kirmizi isik yanma zamani : ");
l4=new JLabel("saniye ");
[Link](light_switch);
[Link](l1);
[Link](t1);
[Link](l2);
[Link](l0);
[Link](l3);
[Link](t2);
[Link](l4);
light_switch.addActionListener(this);
[Link](this);
[Link](this);
[Link](p1,[Link]);
[Link](ti1,[Link]);
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==light_switch)
{
repaint();
}
else if([Link]()==t1)
{
Double i1=new Double([Link]());
[Link]([Link]());
}
else if([Link]()==t2)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Double i1=new Double([Link]());
[Link]([Link]());
}
}
public static void main(String[] args)
{
trafikIsigi1SWF pencere= new trafikIsigi1SWF();
[Link](new BasicWindowMonitor());
[Link](300,600);
[Link](true);
}
}
[Link]
4. H8O1
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double kirmiziZaman;
public double sariZaman;
public char hangi_isik;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return kirmiziZaman;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paint(Graphics g) {
[Link]([Link]);
[Link](x,y,w,h);
[Link]([Link]);
[Link](x-1,y-1,w+2,h+2);
[Link](x-2,y-2,w+4,h+4);
switch([Link]()) {
case 'r':
[Link]('g');
[Link]([Link]);
[Link](x+10,y+hight_diff,radius*2,radius*2);
[Link](x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
[Link]([Link]);
[Link](x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
break;
case 'y':
[Link]('r');
[Link]([Link]);
[Link](x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
[Link](x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
[Link]([Link]);
[Link](x+10,y+hight_diff,radius*2,radius*2);
break;
case 'g':
[Link]('y');
[Link]([Link]);
[Link](x+10,y+hight_diff,radius*2,radius*2);
[Link](x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
[Link]([Link]);
[Link](x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
break;
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import yildizSW;
import [Link].*;
import renk;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]('y');
[Link]([Link]);
[Link](elips3);
[Link](elips1);
[Link]([Link]);
[Link](elips2);
break;
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class trafikIsigi1SWF extends JFrame implements ActionListener
{
isikKontroluThread1 yik;
JButton light_switch;
JTextField t1,t2;
JLabel l0,l1,l2,l3,l4;
trafikIsigi1SWP ti1;
Container c;
public trafikIsigi1SWF()
{
c=getContentPane();
JPanel p1=new JPanel();
[Link](new GridLayout(2,4));
yik=new isikKontroluThread1(this);
[Link]();
ti1=new trafikIsigi1SWP(yik);
light_switch = new JButton("Iºýðý deðiºtir");
light_switch.setForeground([Link]);
light_switch.setBackground([Link]);
t1=new JTextField(""+[Link]());
t2=new JTextField(""+[Link]());
l0=new JLabel(" ");
l1=new JLabel("yesil isik yanma zamani : ");
l2=new JLabel("saniye ");
l3=new JLabel("kirmizi isik yanma zamani : ");
l4=new JLabel("saniye ");
[Link](light_switch);
[Link](l1);
[Link](t1);
[Link](l2);
[Link](l0);
[Link](l3);
[Link](t2);
[Link](l4);
light_switch.addActionListener(this);
[Link](this);
[Link](this);
[Link](p1,[Link]);
[Link](ti1,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==light_switch)
{
repaint();
}
else if([Link]()==t1)
{
Double i1=new Double([Link]());
[Link]([Link]());
}
else if([Link]()==t2)
{
Double i1=new Double([Link]());
[Link]([Link]());
}
}
public static void main(String[] args)
{
trafikIsigi1SWF pencere= new trafikIsigi1SWF();
[Link](new BasicWindowMonitor());
[Link](300,600);
[Link](true);
}
}
[Link]
3. H8O2
Birbirinden baðýmsýz çalýºan iki trafik ýºýðýný iki ayrý ýºýk olarak simule edin. Bu ýsýklardan
birincisinde yesil veya sarý yanarken ikincisinde kýrmýzý yansýn, ikincisinde yeºil veya sarý
yanarken birincisinde kýrmýzý yansýn. Kýrmýzý ve yeºil süreleri ayný olmayabilir, fakat birbirinin
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
tersi olacaktýr. Örneðin birinci ýºýkta 6 saniye kýrmýzý, 10 saniye yeºil, 1 saniye sarý yanýyorsa,
ikinci ýºýkta 11 saniye kýrmýzý, 5 saniye yeºil, 1 saniye sarý yanacaktýr. Birinci ýºýk sarýdan
kýrmýzýya geçtiði anda ikinci ýºýk yeºil yanacaktýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
{
int bekleyen = 0;
boolean kontrolEdenVar = false;
IkiIsikKontroluThread yik[] = new IkiIsikKontroluThread[2];
char which_light[]= new char[] {'r', 'r'};
TextField t1, t2;
Label l1,l2,l3,l4;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public synchronized void kontrolAl()
{
try
{
if ( kontrolEdenVar )
{
bekleyen++;
wait();
}
else
{
kontrolEdenVar = true;
}
}
catch ( InterruptedException interruptedEx)
{ [Link]();}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]);
[Link](xi+10,yi+hight_diff,radius*2,radius*2);
break;
case 'y':
[Link]([Link]);
[Link](xi+10,yi+hight_diff,radius*2,radius*2);
[Link](xi+10,yi+hight_diff*3+radius*4,radius*2,radius*2);
[Link]([Link]);
[Link](xi+10,yi+hight_diff*2+radius*2,radius*2,radius*2);
break;
}
}
IkiTrafikIsigi ti;
int isikNo;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public IkiIsikKontroluThread(IkiTrafikIsigi tiparam, int isikNo)
{
ti = tiparam;
[Link] = isikNo;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yesilZaman=zi;
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 9.7 sinkronize olarak çalýºan iki trafik ýºýðý
4. H8OD2_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
10 m3 boyutunda bir depomuz var. Bu depoya birinci pompa su doldurmakta, ikinci pompa is
suyu boºaltmaktadýr. Pompalarýn debileri deðiºtirilebilmektedir, ve kullanýcý tarafýndan
gerektiðinde elle açýlýp kapatýlabilmektedir. Depo tamamen boºalýrsa boºaltan pompa
otomatik olarak durdurulacaktýr. Depo tamamen dolarsa dolduran pompa otamatik olarak
durdurulacaktýr. Bu prosesi gerçek zamanda simule eden iki pompa ve bir depodan oluºan
bir sistem oluºturunuz, sonuçlarý belli zaman aralýklarýyla ekrana yazdýrýnýz (pompa1,
pompa2 debileri ve depodaki su miktarý ve baºlangýçtan itibaren geçen zaman) veya bir
grafik çýktý üzerinden simulasyon çýktýsýný oluºturunuz. (ayný deðerleri grafik çýktýda
gösteriniz) Depodaki su miktarýný bir ortak double deðeri olarak düºünebiliriz.
class H8OD2_2000
[Link]();
[Link]();
public Pompa1(havuz h)
pTut=h;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
while(true)
[Link](debi);
try{
catch(InterruptedException e)
[Link]("Exeption "+[Link]());
public Pompa2(havuz h)
cTut=h;
while (true)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
try{
catch(InterruptedException e)
[Link]("Exeption "+[Link]());
[Link](debi);
class havuz
while (!pompa1)
try{
wait();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch (InterruptedException e)
[Link]("Exception:"+[Link]() );
OrtakSu += suMiktari;
pompa1 = false;
OrtakSu = kapasite;
else
[Link]("Pompa1'in debisi " + suMiktari + " dir. Depo daki su miktari :" + OrtakSu);
pompa2 = true;
notify();
while (!pompa2)
try{
wait();
catch (InterruptedException e)
[Link]("Exception:"+[Link]() );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
OrtakSu -= suMiktari;
if (OrtakSu <= 0)
pompa2=false;
OrtakSu = 0;
else
[Link]("Pompa2'in debisi " + suMiktari + " dir. Depo daki su miktari :" + OrtakSu);
pompa1 = true;
notify();
/*
* awt animasyon
*/
import [Link].*;
import [Link].*;
/*
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* Bu örnek tüm animasyonlar için örnek olarak kullanýlabilir.
*/
implements Runnable {
int delay;
Thread animatorThread;
super(windowTitle);
addMouseListener(new MouseAdapter() {
if (frozen) {
frozen = false;
startAnimation();
} else {
frozen = true;
stopAnimation();
});
addWindowListener(new WindowAdapter() {
stopAnimation();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void windowDeiconified(WindowEvent e) {
startAnimation();
[Link](0);
});
if (frozen) {
//
} else {
//Animasyon baºlýyor...
if (animatorThread == null) {
[Link]();
animatorThread = null;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// böylece öbür programlara engel olmaz
[Link]().setPriority(Thread.MIN_PRIORITY);
frameNumber++;
//rakamý göster
repaint();
//beklemeye al
try {
startTime += delay;
[Link]([Link](0,
[Link]()));
} catch (InterruptedException e) {
break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String args[]) {
if ([Link] > 0) {
try {
fps = [Link](args[0]);
} catch (Exception e) {}
[Link](200, 60);
[Link](true);
[Link]();
[Link]
Bu örnek problemde bir öncekinin temel olarak aynýsý, sadece swing kullanýlmýº hali
/*
* Swing versiyonu
*/
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
/*
*/
implements Runnable {
AnimappPanel animappPanel;
int delay;
Thread animatorThread;
super(windowTitle);
getContentPane().add(animappPanel);
addMouseListener(new MouseAdapter() {
if (frozen) {
frozen = false;
startAnimation();
} else {
frozen = true;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
stopAnimation();
});
addWindowListener(new WindowAdapter() {
stopAnimation();
startAnimation();
[Link](0);
});
if (frozen) { }
else {
//animasyonu baºlat
if (animatorThread == null) {
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void stopAnimation() {
animatorThread = null;
//önceliði düºür.
[Link]().setPriority(Thread.MIN_PRIORITY);
//baºlama zamaný
//thread tanýmý
//animasyon döngüsü
frameNumber++;
//göster
repaint();
//geciktir
try {
startTime += delay;
[Link]([Link](0,
[Link]()));
} catch (InterruptedException e) {
break;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public AnimappPanel() {}
[Link](g);
if ([Link] > 0) {
try {
fps = [Link](args[0]);
} catch (Exception e) {}
[Link](200, 60);
[Link](true);
[Link]();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 9.9 swing animasyon örneði
/*
*/
import [Link].*;
import [Link].*;
import [Link].*;
/*
*/
implements ActionListener {
int delay;
JLabel label;
Timer timer;
super(windowTitle);
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](true);
addWindowListener(new WindowAdapter() {
stopAnimation();
startAnimation();
[Link](0);
});
[Link](new MouseAdapter() {
if (frozen) {
frozen = false;
startAnimation();
} else {
frozen = true;
stopAnimation();
});
[Link](label, [Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
if (frozen) {
} else {
[Link]();
[Link]();
frameNumber++;
if ([Link] > 0) {
try {
fps = [Link](args[0]);
} catch (Exception e) {}
[Link]();
[Link](true);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
InputStream
FilterInputStream
LineNumberInputStream
BufferedInputStream
DataInputStream
PushbackInputStream
ByteArrayInputStream
FileInputStream
ObjectInputStream
PipedInputStream
SequenceInputStream
StringBufferInputStream
OutputStram
ByteArrayOutputStream
FileOutputStream
FilterOutputStream
BufferedOutputStream
DataOutputStream
PrintStream
ObjectOutputStream
PipedOutputStream
ObjectStreamClass
StreamTokenizer
Reader
FileReader
BufferedReader
LineNumberReader
CharArrayReader
FilterReader
PushbackReader
InputStreamReader
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
FileReader
PipedReader
StringReader
Writer
BufferedWriter
CharArrayWriter
FilterWriter
OutputStreamWriter
PipedWriter
PrintWriter
StringWriter
File
FileDescriptor
RandomAccessFile
Bu sýnýflarýn hepsinin genel görevi javaya girdi saðlamak ve çýktý almaktýr. Burada bunlardan
bir kýsmýnýn iºlevlerini ve nasýl çalýºtýklarýný inceleyeceðiz. Önce temel ana sýnýflarýn
bazýlarýnýn tanýmlarýna daha detaylý
bakalým. InputStream sýnýfý byte türü yazý okuma sýnýfýdýr. Tüm byte türü bilgi akýº kanalý
sýnýflarýnýn ana sýnýfýdýr. Tanýmý :
public abstract class InputStream extends Object
{
public InputStream();
public int available() throws IOException;
public void close() throws IOException;
public synchronized void mark(int readlimit);
public boolean markSupported();
public abstract int read() throws IOException;
public int read(byte b[]) throws IOException;
public int read(byte b[],int off,int len) throws IOException;
public synchronized void reset() throws IOException;
public long skip(long n) throws IOException;
}
InputStream sýnýfýnýn byte türü yazma pareleli olan OutputStream sýnýfýnýn tanýmý ise :
public abstract class OutputStream extends Object
{
public outputStream();
public void close() throws IOException;
public void flush() throws IOException;
public abstract void write(int b) throws IOException;
public void write(byte b[]) throws IOException;
public void write(byte b[],int baºlamanoktasý,int uzunluk) throws IOException;
}
Abstract sýnýf Reader, InputStream sýnýfýna olduça yakýndýr, yalnýz data transferinde byte
yerine char kullanýr, böylece girdi çýktýda unicode stream kullanabilme olasýlýðý yakalar.
public abstract class Reader extends Object
{
protected Reader();
protected Reader(Object o);
public abstract void close() throws IOException;
public void mark(int readlimit) throws IOException;
public boolean markSupported() ;
public abstract int read() throws IOException;
public int read(char c[]) throws IOException;
public int read(char c[],int baºlamanoktasý,int uzunluk) throws IOException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean ready() throws IOException;
public void reset() throws IOException;
public long skip(long n) throws IOException;
}
Abstract sýnýf Writer da Output straem sýnýfýna eºdeðerdir. Fakat ayný readerda olduðu gibi
bu sýnýf da veri akýºýnda char ve string kullanýr.
public abstract class Writer extends Object
{
public outputStream();
public void close() throws IOException;
public void flush() throws IOException;
public abstract void write(int b) throws IOException;
public void write(char c[]) throws IOException;
public void write(char c[],int baºlamanoktasý,int uzunluk) throws IOException;
public void write(String s) throws IOException;
public void write(String s,int baºlamanoktasý,int uzunluk) throws IOException;
}
Bu sýnýflar temel sýnýflardýr. Bunlarýn altýnda yer alan çeºitli sýnýflara aºaðýdaki bölümlerde
daha detaylý bakacaðýz.
10.2 FÝLE (DOSYA) SINIFI
File sýnýfý girdi çýktý iºlemlerini saðlarken, dosya isimleri ve bulunduklarý dizin ile ilgili bilgi
verir.
File sýnýfýnýn tanýmý :
Public class File extends Object implements Serializable, Comparable
{
public static final String pathSeperator;
public static final char pathSeperatorChar;
public static final String seperator;
public static final char seperatorChar;
public File(String dosya_ismi);
public File(String dizin_ismi, String dosya_ismi);
public File(File file_tipi_nesne,String dosya_ismi);
public boolean canRead();
public boolean canWrite();
public boolean compareTo(Object o);
public boolean compareTo(File baºkabirdosya);
public boolean createNewFile();
public static File createTempFile(String isim) throws IOException;
public static File createTempFile(String isim,File dosya) throws IOException;
public boolean delete();
public void deleteOnExit();
public boolean equals(Object o);
public boolean exists(Object o);
public File getAbsooluteFile();
public File getAbsoolutePath();
public File getCanonicalFile() throws IOException;
public File getCanonicalPath() throws IOException;
public String getName();
public String getParent();
public File getParentFile();
public String getPath();
public int hashCode();
public boolean isAbsolute();
public boolean isDirectory();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean isFile();
public boolean isHidden();
public long lastModified();
public long length();
public String[] list();
public String[] list(FilenameFilter filitrefonksiyonu);
public static File[] listRoots();
public boolean mkdir();
public boolean mkdirs();
public boolean renameTo(File yeniisim);
public boolean setLastModified(long nezaman);
public boolean setReadOnly();
public String toString();
public URL toURL() throws MAlformedURLException;
}
Kurucu metotlarýn çaðýrýlmasýna örnek olarak :
File f1=new File(“/”);
File f2=new File(“/”,”[Link]”);
File f3=new File(f1,”[Link]”);
tanýmlarýný verebiliriz. File sýnýfýnda tanýmlanmýº olan Metotlardan bazýlarýnýn tanýmlarý
ºunlardýr. canRead()
Tanýmlanan dosyadan bilgi okunulabilirliðini test eder.
canWrite()
Tanýmlanan dosyaya bilgi yazýlabilirliðini test eder.
delete()
Dosyayý siler
equals(Object)
Dosya ismini Object te verilen dosya ismiyle karºýlaºtýrýr.
exists()
Dosyanýn mevcut olup olmadýðýný kontrol eder.
getAbsolutePath()
Dosyanýn tam dizin ismini ve dosya ismini verir( co/java/prog/[Link]).
getName()
Dosyanýn ismini verir.([Link])
getParent()
Dosyanýn içinde bulunduðu dizinin ismini verir.(prog)
getPath()
dosyanýn ismini ve içinde bulunduðu dizinin ismini verir.(prog/[Link])
isAbsolute()
Dosya isminin mutlak isim olup olmadýðýný kontrol eder.(Eðer dosya ismi
co/java/prog/[Link] olarak verilmiºse true deðeri verir.)
isDirectory()
verilen isimin bir dizin ismi olup olmadýðýný kontrol eder.
isFile()
verilen isimin birdosya isimi olup olamdýðýný kontrol eder.
lastModified()
Dosyanýn en son deðiºtirildiði tarihi verir
length()
Dosyanýn boyutunu Byte olarak verir.
list()
Verilen dizinin içindeki dosyalarýn listesini verir.
list(FilenameFiltre)
Verilen dizinin içindeki Filtre nesnesindeki tanýma uyan dosyalarýn listesini verir.
mkdir()
Yeni bir dizin oluºturur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
mkdirs()
O anda tanýmlý olan dizinin içine bir alt dizin oluºturur.
renameTo(File)
Dosyanýn ismini deðiºtirir.
toString()
Dosya ve dizin isimleri topluluðunun String deðiºkeni eºdeðerini verir.
File(dosya) sýnfýndaki metodlardan da görülebileceði gibi bu sýnýf dosyadan okuyup yazma
gibi bir iºlem yürütmez. File sýnýfýnýn temel iºlevi girdi çýktý dosyasýnýn adlandýrýlmasý ve
isimle ilgili fonksiyonlara ulaºýlmasýdýr. File sýnýfýnýn bazý metotlarýný ufak bir program içinde
kullanalým.
Program 10.1 . [Link] programý
import [Link].*;
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class FileTestiSW
{
public static void main(String args[])
{
//önce JFileChooser kullanarak dosyayý seç, sonra dosya özelliklerini göster.
File f=new File("[Link]");
JFileChooser dosyasec=new JFileChooser();
int onay = [Link](null);
//veya kayýt için int onay = [Link](null);
if(onay==JFileChooser.APPROVE_OPTION)
{
f=[Link]();
}
String s="";
s+="Dosya ismi : "+[Link]()+"\n";
s+="Dizin ismi : "+[Link]()+"\n";
s+="Mutlak Dizin ismi : "+[Link]()+"\n";
s+="Üst Dizin ismi : "+[Link]()+"\n";
s+=[Link]() ? "Mevcut " : " Mevcut deðil "+"\n";
s+=[Link]() ? "Yazýlabilir " : " Yazýlamaz"+"\n";
s+=[Link]() ? "Okunabilir " : " Okunamaz"+"\n";
s+=[Link]() ? "Dizin " : " Dizin degil"+"\n";
s+=[Link]() ? "Dosya " : " Dosya degil"+"\n";
s+=[Link]() ? "Mutlak dizin ismi " : " Mutlak dizin ismi deðil"+"\n";
s+="Son Degisiklik : "+[Link]()+"\n";
s+="Dosya boyutu : "+[Link]()+" Byte"+"\n";
[Link](null,s,"Dosya testi",JOptionPane.PLAIN_MESSAGE);
[Link](0);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu deyim bize [Link] isimli dosyadan bir fileOutputStream aracýlýðýyla açýlan dosyayý
DataOutputStream’e çevirip gerçek deðiºkenler cinsinden akýº kanalý açar.
DataOutputStream ve FileOutputStream sýnýflarýnýn tanýmlarý :
public class DataOutputStream extends FilterOutputStream implements DataOutput
{
public DataOutputStream(OutputStram o);
protected int written
public void flush()
public final void size()
public synchronized void write(byte[],int baslangýçnoktasý,int uzunluk);
public synchronized void write(int);
public final void writeBoolean(boolean b);
public final void writeBytes(String s)
public final void writeChar(int)
public final void writeChars(String)
public final void writeDouble(double)
public final void writeFloat(float)
public final void writeInt(int)
public final void writeLong(long)
public final void writeShort(int)
public final void writeUTF(String)
}
FileOutputStream ise dosya sýnýfý File ile DataOutputStream sýnýfý arasýndaki gerekli
tanýmlarý saðlar
public class FileOutputStream extends OutputStream
{
public FileOutputStream(File file) throws IOException;
public FileOutputStream(FileDescriptor fd) throws IOException;
public FileOutputStream(String s) throws IOException;
public FileOutputStream(String s, boolean b) throws IOException;
public void close() throws IOException;
protected void finalize() throws IOException;
public void getFD() throws IOException;
public void write(byte[]) throws IOException;
public void write(byte[], int, int) throws IOException;
public void write(int) throws IOException;
public final FileDescriptor getFD() throws IOException;
}
Kanal açýldýktan sonra DataOutputStream sýnýfýnýn metodlarýný kullanarak dosyaya yazý
yazabiliriz. Yazma metodlarýnýn iºlevlerine bir göz atarsak :
write(byte B[] )
byte tipi boyutludeðiºkeni açýlmýº olan DataOutputStream kanalýna yazar.
write(byte B[], int baslangýcindeksi, int indeksboyutu)
byte tipi boyutludeðiºkeni açýlmýº olan DataOutputStream kanalýna yazar.
Baslangiç indeksinden baslar ve indeksboyutu uzunluðundaki kýsmý yazar.
write(int B) int datayý data output stream’e yazar.
writeBoolean(boolean B) Boolean deðiºkeni DataOutputStream’e yazar.
writeByte(int) int deðiºkeni byte olarak DataOutputStream’e yazar.
writeBytes(String) String deðiºkeni byte boyutlu deðiºken olarak DataOutputStream’e
yazar.
writeChar(int) int deðiºkeni char deðiºken olarak DataOutputStream’e yazar.
writeChars(String) String deðiºkeni Char deðiºken olarak DataOutputStream’e yazar.
writeDouble(double) double deðiºkeni double deðiºken olarak DataOutputStream’e yazar.
writeFloat(float) float deðiºkeni float deðiºken olarak DataOutputStream’e yazar.
writeInt(int) float deðiºkeni float deðiºken olarak DataOutputStream’e yazar.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
writeLong(long) long deðiºkeni long deðiºken olarak DataOutputStream’e yazar.
writeShort(int) int deðiºkeni short (short integer) deðiºken olarak DataOutputStream’e
yazar.
writeUTF(String) String deðiºkeni unicode UTF-8 formatý karekter boyutu olarak yazar.
Bu ºekilde yazdýðýmýz bir veri akýºýn okumak için ise :
DataInputStream girdiakimi;
try{
girdiakimi=new DataInputStream(new FileInputStream(“[Link]"));
}
catch(IOException e)
{
[Link]("Dosya acilamadi\n"+[Link]());
[Link](1);
}
tanýmýný kulanabiliriz. Buradaki DataInputStream sýnýfýnýn tanýmý :
public class DataInputStream extends FilterInputStream implements DataInput
{
public DataInputStream(InputStream in);
public DataInputStream(InputStream in);
public final int read(byte b[]) throws IOException;
public final int read(byte b[], int baºlangýçdeðeri, int uzunluk) throws IOException;
public final void readFully(byte b[]) throws IOException;
public final void readFully(byte b[],int baºlangýçdeðeri, int uzunluk) throws IOException;
public final int skipBytes(int n) throws IOException;
public final boolean readBoolean() throws IOException;
public final byte readByte() throws IOException;
public final int readUnsignedByte() throws IOException;
public final short readShort() throws IOException;
public final int readUnsignedShort() throws IOException;
public final char readChar() throws IOException;
public final int readInt() throws IOException;
public final long readLong() throws IOException;
public final float readFloat() throws IOException;
public final double readDouble() throws IOException;
public final String readLine() throws IOException;
public final String readUTF() throws IOException;
public final static String readUTF(DataInput in) throws IOException;
}
ºeklindedir. FileInputStream ise :
public FileInputStream(File file) throws FileNotFoundException
{
public FileInputStream(FileDescriptor fdObj);
public int read() throws IOException;
public int read(byte b[]) throws IOException;
public int read(byte b[],int baºlangýçnoktasý,int uzunluk) throws IOException;
public long skip(long n) throws IOException;
public int available() throws IOException;
public void close() throws IOException;
public final FileDescriptor getFD() throws IOException;
protected void finalize() throws IOException;
}
ºeklinde tanýmlýdýr. DataInputStream metdunun alt okuma metodlarýna biraz daha detaylý
göz atarsak:
read(byte[])
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
byte veri akýºýný direk okur.
read(byte[], int baºlangýçnoktasý, int boyut)
byte veri akýºýný baºlangýçnoktasý indeksinden boyut uzunluðuna kadar okurdirek okur.
readBoolean()
boolean deðiºken (true veya false) okur.
readByte()
8-bit byte integer okur
readChar()
unicode karecter(char) okur
readDouble()
double okur
readFloat()
float okur
readFully(byte[])
byte boyutlu deðiºkenini, byte[] boyutlu girdi deðiºkeninin boyutuna göre okur.
readFully(byte[], int, int)
readInt()
Integer okur
readLine()
Bir satýrý satýrbaºý yap komutuna kadar okur. Java 1.0 komutudur. 1.1 ve üzerinde bazý
okuma hatalarý yaptýðý görüldüðünden kullanýlmamasý tavsiye edilir.
readLong()
Long tamsayý deðiºkeni okur.
readShort()
Short tamsayý deðiºkeni okur
readUnsignedByte()
8-bitlik iºaretsiz tamsayý deðiºkeni okur.
readUnsignedShort()
16-bitlik iºaretsiz tamsayý deðiºkeni okur.
readUTF()
Unicode karekteri okur.
readUTF(DataInput)
Unicode Karakterini (Character) DataInput girdi akýºýndan okur.
skipBytes(int n)
n byte deðeri okumadan atlar.
ªimdi bir örnek problem ile bu yazma ve okuma iºlemine daha yakýndan bir göz atalým.
Program 10.2 de yeni bir dosya açýlmakta, ve dosyaya veri girilmektedir. Program 10.3 de
ayný programýn swing kullanýlarak yazýlmýº versiyonu mevcuttur. Program 10.4 de ise
yaratýlan dosyaya girilen veriler okunmaktadýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} catch(IOException e)
{ [Link]("Dosya dogru acilamadi\n"+[Link]());
[Link](1);
}
setSize(300,150);
setLayout(new GridLayout(5,2));
H=new Label("Hesap numarasi :");
add(H);
hesapIsmiKutusu=new TextField();
add(hesapIsmiKutusu);
I=new Label("isim : ");
add(I);
isimKutusu=new TextField(20);
add(isimKutusu);
S=new Label("Soyisim : ");
add(S);
soyIsimKutusu=new TextField(20);
add(soyIsimKutusu);
P=new Label("Hesaptaki para : ");
add(P);
hesapKutusu=new TextField(20);
add(hesapKutusu);
enter=new Button("Gir");
[Link](this);
add(enter);
done=new Button("Cikis");
[Link](this);
add(done);
setVisible(true);
}
public void hesapEkle()
{
int accountNumber=0;
Double d;
if(![Link]().equals(""))
{
try{
accountNumber=[Link]([Link]());
if(accountNumber0)
{
[Link](accountNumber);
[Link]([Link]());
[Link]([Link]());
d=new Double([Link]());
[Link]([Link]());
}
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
catch(NumberFormatException nfe)
{
[Link]("Hesap numarasi tamsayi degisken olamalidir");
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch(IOException io)
{
[Link]("Dosyaya yazarken hata olustu\n"+[Link]());
[Link](1);
}
}
}
public void actionPerformed(ActionEvent e)
{
hesapEkle();
if([Link]()==done)
{
try{ [Link]();}
catch(IOException io)
{
[Link]("Dosya kapatilamadi\n"+[Link]());
}
[Link](0);
}
}
public static void main(String args[])
{
new ardisikDosyaYarat();
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Container c;
public ardisikDosyaYaratSWF_2000()
{
super("Müºteri dosyasi Aç");
c=getContentPane();
try{
cikti=new DataOutputStream(new FileOutputStream("[Link]"));
} catch(IOException e)
{ [Link]("Dosya doðru açýlamadý\n"+[Link]());
[Link](1);
}
[Link](new GridLayout(5,2));
H=new JLabel("Hesap numarasi :");
[Link](H);
hesapIsmiKutusu=new JTextField();
[Link](hesapIsmiKutusu);
I=new JLabel("isim : ");
[Link](I);
isimKutusu=new JTextField(20);
[Link](isimKutusu);
S=new JLabel("Soyisim : ");
[Link](S);
soyIsimKutusu=new JTextField(20);
[Link](soyIsimKutusu);
P=new JLabel("Hesaptaki para : ");
[Link](P);
hesapKutusu=new JTextField(20);
[Link](hesapKutusu);
enter=new JButton("Gir");
[Link](this);
[Link](enter);
done=new JButton("Cikis");
[Link](this);
[Link](done);
setVisible(true);
}
public void hesapEkle()
{
int accountNumber=0;
Double d;
if(![Link]().equals(""))
{
try{
accountNumber=[Link]([Link]());
if(accountNumber>0)
{
[Link](accountNumber);
[Link]([Link]());
[Link]([Link]());
d=new Double([Link]());
[Link]([Link]());
}
[Link]("");
[Link]("");
[Link]("");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("");
}
catch(NumberFormatException nfe)
{
[Link]("Hesap numarasi tamsayi degisken olamalidir");
}
catch(IOException io)
{
[Link]("Dosyaya yazarken hata olustu\n"+[Link]());
[Link](1);
}
}
}
public void actionPerformed(ActionEvent e)
{
hesapEkle();
if([Link]()==done)
{
try{ [Link]();}
catch(IOException io)
{
[Link]("Dosya kapatilamadi\n"+[Link]());
}
[Link](0);
}
}
public static void main(String[] args)
{
ardisikDosyaYaratSWF_2000 pencere= new ardisikDosyaYaratSWF_2000();
[Link](300,150);
[Link](new BasicWindowMonitor());
[Link](true);
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try{
input=new DataInputStream(new FileInputStream("[Link]"));
} catch(IOException e) { [Link]("Dosya acilamadi\n"+[Link]());
[Link](1);
}
setSize(300,150);
setLayout(new GridLayout(5,2));
add(new Label("Hesap Numarasi :"));
accountField=new TextField();
add(accountField);
add(new Label("isim : "));
firstNameField=new TextField(20);
add(firstNameField);
add(new Label("soyisim : "));
lastNameField=new TextField(20);
add(lastNameField);
add(new Label("Hesaptaki para : "));
balanceField=new TextField(20);
add(balanceField);
next=new Button("bir sonraki hesap");
[Link](this);
add(next);
done=new Button("cikis");
[Link](this);
add(done);
setVisible(true);
}
public void readRecord()
{
int account;
String first,last;
double balance;
{
try{
account=[Link]();
first=[Link]();
last=[Link]();
balance=[Link]();
[Link]([Link](account));
[Link](first);
[Link](last);
[Link]([Link](balance));
}
catch(EOFException eof)
{
closeFile();
}
catch(IOException io)
{
[Link]("Dosyay� okurken hata olustu\n"+[Link]());
[Link](1);
}
}
}
public void actionPerformed(ActionEvent e)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
if([Link]()==next)
readRecord();
else
closeFile();
}
private void closeFile()
{
try{
[Link]();
[Link](0);
}
catch(IOException e)
{
[Link]("Dosya Kapama Hatasý oluºtu\n"+[Link]());
[Link](1);
}
}
public static void main(String args[])
{
new ardisikDosyaOku();
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try{
cikti=new DataOutputStream(new FileOutputStream(f));
}
catch(IOException e)
{ [Link]("Dosya dogru acilamadi\n"+[Link]());
[Link](1);
}
ºeklinde de yaratabilirdik. Ýkinci ºekilde dosyayý tanýmlarken tam dizin ismini de otomatik
olarak tanýmlamýº olurduk.
Dosyanýn okunmasý içinse
try{
input=new DataInputStream(new FileInputStream("[Link]"));
}
catch(IOException e)
{
[Link]("Dosya acilamadi\n"+[Link]());
[Link](1);
}
gurubunu kullandýk. Eðer dosya ismi de deðiºkende dýºarýdan okuduktan sonra ismi File
sýnýfýna yükleyip sonra akýº kanalý açabiliriz.
Dosya ile iºlemler bittikten sonra dosya kapanýr.
private void closeFile()
{
try{
[Link]();
[Link](0);
}
catch(IOException e)
{
[Link]("Dosya Kapama Hatasý oluºtu\n"+[Link]());
[Link](1);
}
}
closeFile() metotu dosya akýºýný kapatmak amacýyla oluºturulmuºtur.
Bu örnekte kullandýðýmýz, DataOutputStream, FileOutputStream, DataInputStream,
FileInputStream girdi çýktý akýº kontrollarý temel olarak daha önce tanýmlarýný vermiº
olduðumuz OutputStream ve InputStream sýnýflarýndan türetilmiº sýnýflardý. Ve temel olarak
byte deðiºken türü üzerinden veri akýºýný saðlamaktadýrlar.
Yine yukarýda tanýmlanmýº olan Reader ve Writer sýnýflarý ise ayný iºlemi char sýnýfý veri akýºý
üzerinden yapmaktadýr ve char sýnfý direk olarak unicode olarak tanýmlandýðýndan
herhangibir hataya sebep vermeden daha iyi bir veri akýºý saðlar. Bu sýnýfýn alt sýnýflarý olarak
tanýmlanan ve yazma iºleminde kullanýlan sýnýflarýn kullanýlmasýna bir göz atalým.
Genel olarak Writer sýnýfýndan türetilen ve en çok kullanýlan Yazma kanalý PrintWriter ,
BufferedWriter, FileWriter veya OutputStreamWriter sýnýflarýnýn beraber kullanýlmasýyla
gerçekleºtirilebilir. Bu sýnýflarýn birlikte kulanýlmalarýný ºu deyimlerle örnekleyebiliriz :
dosya "[Link]" e yazdýrmak için :
tanýmý kullanýlabilir.
PrintWriter sýnýfýnýn tanýmý :
public class PrintWriter extends Writer
{
public PrintWriter(OutputStream o) ;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public PrintWriter(OutputStream o, boolean b) ;
public PrintWriter(Writer w) ;
public PrintWriter(Writer w, boolean b);
public void flush();
public void close();
public boolean checkError();
protected void setError();
public void write(int c);
public void write(char buf[]);
public void write(String s,int baslamaindeksi,int uzunluk);
public void write(String s);
public void print(boolean b);
public void print(char c);
public void print(int i);
public void print(long l);
public void print(float f);
public void print(double d);
public void print(Object obj);
public void println();
public void println(boolean x);
public void println(char x);
public void println(int x);
public void println(long x);
public void println(float x);
public void println(double x);
public void println(char x[]);
public void println(Object x);
}
PrintWriter sýnýfýnýn mevcut metotlarýnýn iºlevleri ºunlardýr :
checkError() Tüm veriyi gönderir ve hata kontrolu yapar.
close() veri akýº kanalýný kapatýr.
flush() veri akýº kanalýndaki tüm veriyi gönderir (ve bufferi yeni veri için boºaltýr).
print (boolean) boolean deðiºken yazar.
print (char) character deðiºken yazar.
print (char[]) boyutlu chracter deðiºkenleriyazar.
print (double) double yazar.
print (float) float yazar.
print (int) integer yazar.
print (long) long yazar.
print (Object) object sýnýfýnýn tanýmladýðý çýktýyý (object türüne göre deðiºebilir) yazar.
print(String) String yazar
println () satýr sonu yapar alt satýra geçer.
println (boolean) boolean yazar ve satýr sonu yapar alt satýra geçer.
println (char) character yazar ve satýr sonu yapar alt satýra geçer.
println (char[]) boyutlu character deðiºkenleri yazar ve satýr sonu yapar alt satýra geçer.
println (double) double yazar ve satýr sonu yapar alt satýra geçer.
println (float) float yazar ve satýr sonu yapar alt satýra geçer.
println (int) Print an integer, and then finish the line.
println (long) long yazar ve satýr sonu yapar alt satýra geçer.
println (Object) object sýnýfýnýn tanýmladýðý çýktýyý (object türüne göre deðiºebilir) yazar ve
satýr sonu yapar alt satýra geçer.
println(String) String yazar ve satýr sonu yapar alt satýra geçer.
setError() bir hata oluºtuðunu gösterir
write (char[]) boyutlu character deðiºkenlerini yazar
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
write (char[], int, int) boyutlu character deðiºkenlerini birinci integer(tamsayý) boyutundan
ikinci integer boyutuna kadar yazar.
write (int) tek bir character yazar.
write (String) string yazar
write(String, int, int) string deðiºkenini birinci integer(tamsayý) boyutundan ikinci integer
boyutuna kadar yazar.
BufferedWriter sýnýfýnýn tanýmý :
public class BufferedWriter extends Writer
{
public BufferedWriter(Writer cikti);
public BufferedWriter(Writer cikti,int boyut);
public void write(int c) throws IOException;
public void write(char c[],int baºlamaindeksi,int uzunluk) throws IOException;
public void write(String s, int baºlamaindeksi,int uzunluk) throws IOException;
public void newLine() throws IOException;
public void flush() throws IOException;
public void close() throws IOException;
}
ºeklindedir. Yazma verimini arttýrmak için akýºa ilave edilmektedir.
FileWriter sýnýfý ise File sýnýfý ile baðlantýmýzý kuran (dosyayý tanýmlayan sýnýfýmýzdýr.). Writer
sýnýfýnýn altýnda yer alan OutputStreamWriter Sýnýfýnýn alt sýnýfýdýr. tanýmý :
public class FileWriter extends OutputStreamWriter
{
public FileWriter(String fileName) throws IOException;
public FileWriter(String fileName,boolean append) throws IOException;
public FileWriter(File file) throws IOException;
public FileWriter(FileDescriptor fd);
}
OutputStreamWriter sýnýfýnýn tanýmý :
public class OutputStreamWriter extends Writer
{
public OutputStreamWriter(OutputStream o,String enc) throws
UnsupportedEncodingException;
public OutputStreamWriter(OutputStream o);
public String getEncoding();
public void write(int c) throws IOException;
public void write(char c[],int baºlamaindeksi,int uzunluk) throws IOException;
public void write(String str,int baºlamaindeksi,int uzunluk) throws IOException;
public void flush() throws IOException;
public void close() throws IOException;
}
Bu sýnýflarý kullanarak bir yazma kanaý açmak istersek :
PrintWriter cfout=new PrintWriter(new BufferedWriter(new FileWriter("[Link]")));
[Link]("hello");
Komutunu kullanabiliriz. Bu komut
hello string deðiºkenini [Link] dosyasýna yazdýrýr.
Dosya veya ekrandan okumak için ise paralel olarak BufferedReader, FileReader ve
InputStreamReader sýnýflarýný kullanabiliriz. BufferedReader sýnýfýnýn tanýmý :
public class BufferedReader extends Reader
{
public BufferedReader(Reader giriº,int boyut);
public BufferedReader(Reader giriº);
public int read(char c[],int off,int len) throws IOException;
public int read() throws IOException;
public String readLine() throws IOException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public long skip(long n) throws IOException;
public boolean ready() throws IOException;
public boolean markSupported();
public void mark(int readAheadLimit) throws IOException;
public void reset() throws IOException;
public void close() throws IOException;
}
BufferedReader ve FileReader sýnýflarýný birarada kullanarak bir okuma kanalý açabiliriz.
örneðin [Link] dosyasýndan okumak için :
Bu terimleri kullanarak dosyaya yazma ve okumayla ilgili ufak bir örnek verelim
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Class Text to read data from screen or file
// and write (by using print) to screen or file
// formatted c printf like comand structure
// Dr. Turhan Coban
//============================================
import [Link].*;
import [Link].*;
class Text
{
BufferedReader in;
/*
---------------------------------------------------
Static routines provided are:
---------------------------------------------------
public static void prompt(String s);
public static int readInt(DataInputStream in);
public static int readInt(BufferedReader in);
public static double readDouble(DataInputStream in);
public static double readDouble(BufferedReader in);
public static String readString(DataInputStream in);
public static String readString(BufferedReader in);
public static char readChar(DataInputStream in);
public static char readChar(BufferedReader in);
----------------------------------------------------
Dynamic routines provided are :
----------------------------------------------------
public void Text()
public void Text(String s1)
public void Text(File f1)
public int readInt();
public double readDouble();
public String readString();
public char readChar();
Sample use :
--------- reading a double--------------
DataInputStream cin=new DataInputStream([Link]);
double number;
number=[Link](cin);
veya
BufferedReader cin=new BufferedReader(new InputStreamReader([Link]));
double number;
number=[Link](cin);
veya
double number;
Text cin=new Text();
number=[Link]();
------ reading data from a file "[Link]"------
DataInputStream fin=new DataInputStream
(new FileInputStream("[Link]"));
double number;
number=[Link](fin);
veya
double number;
BufferedReader fin=new BufferedReader(new FileReader("[Link]"));
double number;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
number=[Link](fin);
veya
double number;
Text cin=new Text("[Link]");
number=[Link]();
------ printing data into a file "[Link]"----
PrintStream fout=new PrintStream(new FileOutputStream("[Link]"));
String a="turhan";
[Link](a);
veya
BufferedWriter fout=new BufferedWriter(new FileWriter("[Link]"));
String a="Turhan");
[Link](a);
----------------------------------------------------
*/
private static StringTokenizer T;
private static String S;
public Text()
{
in=new BufferedReader(new InputStreamReader([Link]));
}
public Text(String s1) throws IOException
{
in=new BufferedReader(new FileReader(s1));
}
public static void prompt (String s) {
[Link](s + " ");
[Link]();
}
public static int readInt (DataInputStream in) throws IOException
{
if (T==null) refresh(in);
while (true)
{
try {
String item = [Link]();
return [Link]([Link]()).intValue();
}
catch (NoSuchElementException e1) { refresh (in);}
catch(NumberFormatException e2)
{ //[Link]("Error in number, try again.");
}
}
}
public int readInt() throws IOException
{
return [Link](in);
}
public String readStringLine() throws IOException
{
return [Link](in);
}
public double readDouble() throws IOException
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return [Link](in);
}
public String readString() throws IOException
{
return [Link](in);
}
public char readChar() throws IOException
{
return [Link](in);
}
public static int readInt (BufferedReader in) throws IOException
{
if (T==null) refresh(in);
while (true)
{
try {
String item = [Link]();
return [Link]([Link]()).intValue();
}
catch (NoSuchElementException e1) { refresh (in);
} catch(NumberFormatException e2)
{ //[Link]("Error in number, try again.");
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} catch(NoSuchElementException e1) {
refresh (in);
} catch(NumberFormatException e2)
{
//[Link]("Error in number, try again.");
}
}
}
public static double readDouble(BufferedReader in) throws IOException
{
if(T==null) refresh(in);
while (true) {
try {
String item = [Link]();
return [Link] ([Link]()).doubleValue();
} catch(NoSuchElementException e1) {
refresh (in);
} catch(NumberFormatException e2)
{
//[Link]("Error in number, try again.");
}
}
}
// this method is deprecated, but still kept for historical reasons
// prefer BufferedReader version
public static String readString(DataInputStream in) throws IOException
{
if(T==null) refresh (in);
while (true) {
try {return [Link]();}
catch (NoSuchElementException e1) {
refresh (in);
}
}
}
public static String readString(BufferedReader in) throws IOException
{
if(T==null) refresh (in);
while (true) {
try {return [Link]();}
catch (NoSuchElementException e1) {
refresh (in);
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if (ch < 0 || (char)ch == '\n' || (char)ch == '\0')
done = true;
else
r = r + (char) ch;
}
catch([Link] e)
{ done = true;
}
}
return [Link](0,([Link]()-1));
}
public static String readStringLine(BufferedReader in) throws IOException
{
//reads a line of strings from BufferedReader in
int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = [Link]();
if (ch < 0 || (char)ch == '\n' || (char)ch == '\0')
done = true;
else
r = r + (char) ch;
}
catch([Link] e)
{ done = true;
}
}
return [Link](0,([Link]()-1));
}
private static void refresh (DataInputStream in) throws IOException
{
String s = [Link]();
if (s==null) throw new EOFException();
T = new StringTokenizer(s);
}
private static void refresh (BufferedReader in) throws IOException
{
String s = [Link]();
if (s==null) throw new EOFException();
T = new StringTokenizer(s);
}
}
Text sýnýfýný kullanarak sequential bilgiyi dosyadan okuyan [Link] programý altta
verilmiºtir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String s3="Bos String";
String s4="Bos String";
PrintWriter cfout=new PrintWriter(new BufferedWriter(new FileWriter("[Link]")));
[Link]("Merhaba");
[Link]("isminiz nedir");
[Link]("Hosgeldiniz");
[Link]();
Text cfin=new Text("[Link]");
s1=[Link]();
s2=[Link]();
s3=[Link]();
s4=[Link]();
[Link]("s1 = "+s1);
[Link]("s2 = "+s2);
[Link]("s3 = "+s3);
[Link]("s4 = "+s4);
}
}
bu programýn çýktýsý :
s1 = Merhaba
s2 = isminiz
s3 = nedir
s4 = Hosgeldiniz
ºeklindedir. Burada görüldüðü gibi her kelime ayrý bir string olarak algýlanmýºtýr. Bu yapýyý
gerçekleºtiren Text sýnýfý içerisinde kullanýlan StringTokenizer sýnýfýdýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class Atom
{
public int number; // atomic number
public String name; // name of the the atom
public String symbol; // symbol of the atom
public double mass; // mass of the atom
public double N; // number of the atoms
BufferedReader fina;
public Atom()
{
//empty constructor
number=0;
symbol="";
name="";
mass=0;
N=1;
}
//=================================================================
public Atom(int anumber,double NN) throws IOException
{
//this constructor will load Atom data from a given atomic number
//and number of atoms
//type
String atom_name;
String atom_symbol;
double atom_mass;
int atom_number;
try{
fina=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try {
while(fina != null)
{
atom_number=[Link](fina);
atom_name= [Link](fina);
atom_symbol= [Link](fina);
atom_mass=[Link](fina);
if(atom_number==anumber)
{
N=NN;
number=atom_number;
name=atom_name;
symbol=atom_symbol;
mass=atom_mass*N;
break;
}
}
} catch(EOFException e_eof) {[Link](); }
}
public Atom(String st1,double NN) throws IOException
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// this constructor will load Atom data from a given atom name
// or atom symbol and number of atoms
// type
String atom_name;
String atom_symbol;
double atom_mass;
int atom_number;
try{
fina=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try {
while(fina != null)
{
atom_number=[Link](fina);
atom_name= [Link](fina);
atom_symbol= [Link](fina);
atom_mass=[Link](fina);
if([Link](atom_name) || [Link](atom_symbol))
{
N=NN;
number=atom_number;
name=atom_name;
symbol=atom_symbol;
mass=atom_mass*N;
break;
}
}
} catch(EOFException e_eof) {[Link](); }
}
public Atom(String st1) throws IOException
{
// this constructor will load Atom data from a given atom name
// or atom symbol and number of atoms
// type
double NN=1;
String atom_name;
String atom_symbol;
double atom_mass;
int atom_number;
try{
fina=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try {
while(fina != null)
{
atom_number=[Link](fina);
atom_name= [Link](fina);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
atom_symbol= [Link](fina);
atom_mass=[Link](fina);
if([Link](atom_name) || [Link](atom_symbol))
{
N=NN;
number=atom_number;
name=atom_name;
symbol=atom_symbol;
mass=atom_mass*N;
break;
}
}
} catch(EOFException e_eof) {[Link](); }
}
public Atom(Atom a)
{
number=[Link];
name=[Link];
symbol=[Link];
mass=[Link];
N=a.N;
}
public Atom(Atom a, double NN)
{
number=[Link];
name=[Link];
symbol=[Link];
mass=[Link];
N=NN;
}
//=================================================================
public void assign(Atom a)
{
number=[Link];
name=[Link];
symbol=[Link];
mass=[Link];
N=a.N;
}
//=================================================================
//boolean equals logical comparisons
public boolean equals(String s)
{
boolean b;
if([Link](s) || [Link](s))
return true;
else
return false;
}
public boolean equals(int n)
{
boolean b;
if(number==n)
return true;
else
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return false;
}
//=================================================================
public String toString()
{
String st=symbol;
if(N != 1.0)
if(N==[Link](N)) st = st + (int)N;
else st = st + N;
return st;
}
}
//=================================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
17 Chlorine Cl 35.4527
18 Argon Ar 39.938
19 Potassium K 39.0983
20 Calcium Ca 40.078
21 Scandium Se 44.95591
22 Titanium Ti 47.88
23 Vanadium V 50.9415
24 Chromium Cr 51.9961
25 Manganese Mn 54.93805
26 Iron Fe 55.587
27 Cobalt Co 58.9332
28 Nickel Ni 58.69
29 Copper Cu 63.546
30 Zink Zn 65.39
31 Gallium Ga 69.723
32 Germanium Ge 72.61
33 Arsenic As 74.92159
34 Selenium Si 78.96
35 Bromine Br 79.904
36 Kyrpton Kr 83.8
37 Rubidium Ru 85.4678
38 Strontium Sr 87.62
39 Yttirum Yt 88.90585
40 Zirconium Zr 91.224
41 Niobium Nb 92.90638
42 Molybdenium Mo 95.94
43 Technetium Tc 98
44 Ruthenium Sm 101.007
45 Rhodium Rh 102.9055
46 Palladium Pd 106.42
47 Silver Ag 107.8682
48 Cadmium Cd 112.411
49 Indium In 114.82
50 Tin Sn 118.71
51 Anthimony Sb 121.75
52 Tellerium Te 127.6
53 Iodine I 126.90447
54 Xenon Xe 131.29
55 Cesium Cs 132.90543
56 Barium Ba 137.327
57 Lanthanum La 138.9055
58 Cerium Ce 140.115
59Praseodymium Pr 140.90765
60 Neodymium Nd 144.24
61 Promethium Pm 145
62 Samarium Sc 150.36
63 Europium Eu 151.965
64 Gadolinium Gd 157.25
65 Terbium Tb 158.92534
66 Dysprosium Dy 162.5
67 Holmium Ho 164.93032
68 Erbium Er 167.26
69 Thulium Tm 168.93421
70 Ytterbium Yb 173.04
71 Lutetium Lu 174.967
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
72 Hafnium Hf 178.49
73 Tantalum Ta 180.9479
74 Tungsten W 183.85
75 Rhenium Re 186.207
76 Osmium Os 190.2
77 Iridium Ir 192.22
78 Platinium Pt 195.08
79 Gold Au 196.96654
80 Mercury Hg 200.59
81 Thallium Tl 204.3833
82 Lead Pb 207.2
83 Bismuth Bi 208.98037
84 Polonium Po 209
85 Astatine At 210
86 Radon Rn 222
87 Francium Fr 223
88 Radium Ra 226
89 Actinium Ac 227
90 Thorium Th 232.0381
91 Protactinium Pa 231
92 Uranium U 238.0289
93 Neptunium Np 237
94 Plutonium Pu 244
95 Americium Am 243
96 Curium Cm 247
97 Berkelium Bk 247
98 Californium Cf 251
99 Einsteinium Es 252
100 Fermium Fm 257
101 Mendelevium Md 258
102 Nobelium No 259
103 Lawrencium Lr 260
Program [Link] çýktýsý :
N2
O8
Burada hemen ºunu kaydedelim. Programdan da anlaºýlacaðý gibi [Link] java’yý öðretme
amacýyla hazýrlanmamýºtýr. Gazlarýn termodinamik özelliklerini hesaplayan bir program
gurubunun parçasý olarak hazýrlanmýºtýr.
10.4 RASLANTISAL ULAªIM DOSYASI OKU (RANDOM ACCESS FILE)
Raslantýsal Ulaºým Dosyasýnýn (Random Access File) Ardýºýk Dosya sisteminden temel farký,
Teyp kaydýyla CD kaydý arasýndaki fark gibidir. Ardýºýk dosyalar Teyp kaydý ºeklinde birbiri
ardý sýra gelen bilgilerden oluºur. Raslantýsal Ulaºým sisteminde ise CD gibi herhangi bir
kayýta kayýt numarasý kullanýlarak doðrudan ulaºmak mümkündür. Raslantýsal Ulaºým
dosyasý iºlemleri RandomAccessFile sýnýfý üzerinden yapýlýr. Bu sýnýfýn tanýmý :
public class RandomAccessFile extends Object implements DataOutput, DataInput
{
public RandomAccessFile(String name,String mode) throws IOException
public RandomAccessFile(File file,String mode) throws IOException
public final FileDescriptor getFD() throws IOException
public int read() throws IOException
public int read(byte b[],int off,int len) throws IOException
public int read(byte b[]) throws IOException
public final void readFully(byte b[]) throws IOException
public final void readFully(byte b[],int off,int len) throws IOException
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int skipBytes(int n) throws IOException
public void write(int b) throws IOException
public void write(byte b[]) throws IOException
public void write(byte b[],int off,int len) throws IOException;
public long getFilePointer() throws IOException;
public void seek(long pos) throws IOException;
public void seek(long pos) throws IOException;
public long length() throws IOException;
public void close() throws IOException;
public final byte readByte() throws IOException;
public final int readUnsignedByte() throws IOException;
public final short readShort() throws IOException;
public final int readUnsignedShort() throws IOException;
public final char readChar() throws IOException;
public final int readInt() throws IOException;
public final long readLong() throws IOException;
public final float readFloat() throws IOException;
public final double readDouble() throws IOException;
public final String readLine() throws IOException;
public final String readUTF() throws IOException;
public final void writeBoolean(boolean v) throws IOException;
public final void writeByte(int v) throws IOException;
public final void writeShort(int v) throws IOException;
public final void writeChar(int v) throws IOException;
public final void writeInt(int v) throws IOException;
public final void writeLong(long v) throws IOException;
public final void writeFloat(float v) throws IOException;
public final void writeDouble(double v) throws IOException;
public final void writeBytes(String s) throws IOException;
public final void writeChars(String s) throws IOException;
public final void writeUTF(String str) throws IOException;
}
Burada tanýmlanan metodlarýn görevlerine kýsaca bir bakacak olursak :
getFD() : dosya (File) tanýmýný verir
getFilePointer() : Dosyanýn (File) o anda hangi dosya referansýný gösterdiðini belirtir.
length() : Dosyadaki toplam referans sayýsýný verir.
read() : Byte (char deðiºkeni karºýlýðý) olarak dosyadan bilgiyi okur (bir byte).
read(byte[]) : Byte (char deðiºkeni karºýlýðý) olarak dosyadan bilgiyi okur (byte[] deðiºkeninin
boyu kadar) ve byte degiºkenine aktarýr.
read(byte[], int baslangýç_indisi, int indis_boyutu) : Byte (char deðiºkeni karºýlýðý) olarak
dosyadan bilgiyi okur (byte[] deðiºkeninin boyu kadar, baºlangýç indisinden baºlayarak,
indis_boyutu uzunluðunda) ve byte degiºkenine aktarýr.
readBoolean() : boolean deðiºken okur
readByte() : dosyadan integer tipi byte deðiºken (iºaretli 8-bit ) okur.
readChar() : Dosyadan Unicode karekter (character) okur.
readDouble() : Dosyadan double deðiºkeni okur.
readFloat() : Dosyadan float deðiºkeni okur.
readFully(byte[] b) : dosyadan byte olarak okur
readFully(byte[] b, int baslangýç_indisi, int toplam_boy) : dosyadan bte olarak sadece
byte boyutlu deðiºkeninin baºlangýc_indisi’nden baºlamak üzere taplam_boy kadar kýsmýný
okur.
readInt() : Dosyadan int deðiºkeni okur.
readLine() : Dosyadan “\n” = yeni satýr iºaretini veya “\r” satýrbaºý iºaretini veya herikisini
birden arka arkaya görene kadar yazýlan her ºeyi bütün bir satýr olarak okur.
readLong(): Dosyadan Long (Long integer) deðiºkeni okur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
readShort(): Dosyadan Short (Short integer) deðiºkeni okur.
readUnsignedByte(): ݺaretsiz Byte deðeri okur.
readUnsignedShort(): ݺaretsiz 16 bitlik Short integer deðeri okur.
readUTF() : UTF stringi okur
seek(long) : indisi herhangi bir bilgi gurubu indisine ayarlar.
skipBytes(int n) : n bit input deðerini okumadan atlar
Aºaðýdaki tanýmlar read tanýmlarýna parelel olan write terimleridir.
write(byte[]) : byte boyutlu deðiºkenini yazar.
write(byte[],int baslangýç_indisi, int toplam_boy) : dosyaya byte olarak sadece byte
boyutlu deðiºkeninin baºlangýc_indisi’nden baºlamak üzere taplam_boy kadar kýsmýný yazar.
write(int) : dosyaya byte boyutlu deðiºkenini yazar
writeBoolean(boolean) : dosyaya boolean boyutlu deðiºkenini yazar
writeByte(int) : dosyaya int girdisini byte olarak yazar
writeBytes(String) : dosyaya String girdisini byte boyutlu deðiºkeni olarak yazar
writeChar(int) : dosyaya int girdisini Char olarak yazar
writeChars(String) : dosyaya string girdisini char boyutlu deðiºkeni olarak yazar
writeDouble(double) : dosyaya double girdisini double olarak yazar.
writeFloat(float) : dosyaya float girdisini float olarak yazar
writeInt(int) : dosyaya int girdisini int olarak yazar.
writeLong(long) : dosyaya long(integer) girdisini long(integer) olarak yazar
writeShort(int) : dosyaya integer gidisini short(integer) olarak yazar.
writeUTF(String) : dosyaya String girdisini UTF string olarak yazar.
RandomAccessFile sýnýfýnýn tanýmýndan da görüldüðü gibi b sýnýf DataOutput ve DataInput
sýnýflarýný implement eder. DataOutput ve DataInput sýnýflarýnýný tanýmý :
public interface DataOutput
{
public abstract void write(int b) throws IOException
public abstract void write(byte b[]) throws IOException
public abstract void write(byte b[],int off,int len) throws IOException
public abstract void writeBoolean(boolean v) throws IOException
public abstract void writeByte(int v) throws IOException
public abstract void writeShort(int v) throws IOException
public abstract void writeChar(int v) throws IOException
public abstract void writeInt(int v) throws IOException
public abstract void writeLong(long v) throws IOException
public abstract void writeFloat(float v) throws IOException
public abstract void writeDouble(double v) throws IOException
public abstract void writeBytes(String s) throws IOException
public abstract void writeChars(String s) throws IOException
public abstract void writeUTF(String str) throws IOException
}
public interface DataInput
{
public abstract void readFully(byte b[]) throws IOException
public abstract void readFully(byte b[],int off,int len) throws IOException
public abstract int skipBytes(int n) throws IOException
public abstract boolean readBoolean() throws IOException
public abstract byte readByte() throws IOException
public abstract int readUnsignedByte() throws IOException
public abstract short readShort() throws IOException
public abstract int readUnsignedShort() throws IOException
public abstract int readInt() throws IOException
public abstract long readLong() throws IOException
public abstract float readFloat() throws IOException
public abstract double readDouble() throws IOException
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public abstract String readLine() throws IOException
public abstract String readUTF() throws IOException
}
RandomAccessFile Çok daha çabuk ulaºým olanaklarý yaratýr. Raslantýsal Ulaºým dosyasý
örneði olarak aºaðýdaki paketi veriyoruz. Kayit sýnýfý tek bir kayýtýn yazýlýp okunabilmesi için
gerekli olan bilgileri içeriyor. Kayýtlarýn hesap numarasý, isim, soyisim ve hesaptaki paradan
oluºtuðunu kabul ediyoruz. Bütün bu kayýtlarý bir arada yapmak için oku ve yaz metotlarý bu
sýnýfýn içindr tanýmlanmýºtýr. Raslantýsal ulaºým kanalýnýn dosyaya açýlmasý için :
try{
girdi=new RandomAccessFile("[Link]","rw");
} catch(IOException e)
{
[Link]("Dosya acma hatasi\n"+[Link]());
[Link](1);
}
yapýsý kullanbilir. Buradaki “rw” yapýsý dosyaya hem yazý yazýlýp hem okunabileceðini belirtir.
“r” sadece okumak için “w” sadece yazmak için kullanýlýr.
RandomAccessFile içinde yer alan
close() metodu RandomAccessFile (Raslantýsal Ulaºým Dosyasý) kanalýný ve ilgili tüm
sýnýflarý kapatýr. örnek olarak :
private void closeFile()
{
try{
[Link]();
[Link](0);
}
catch(IOException e)
{
[Link]("Error closing filr\n"+[Link]());
[Link](1);
}
}
metotu verilebilir.
ªimdi de örnek programýn listelerini verelim:
Program 10.10 [Link] raslantýsal ulaºým dosyasý kayýt programý
import [Link].*;
public class Kayit
{
private int hesap;
private String soyIsim;
private String Isim;
private double hesaptakiPara;
public void oku(RandomAccessFile dosya) throws IOException
{
//RandomAccessFile = Raslantisal Ulasim dosyasi
hesap=[Link]();
char first[]=new char[15];
for(int i=0;i<[Link];i++)
{ first[i]=[Link](); }
Isim=new String(first);
char last[]=new char[15];
for(int i=0;i<[Link];i++)
{ last[i]=[Link](); }
soyIsim=new String(last);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
hesaptakiPara=[Link]();
}
public void yaz(RandomAccessFile dosya) throws IOException
{
StringBuffer buf;
[Link](hesap);
if(Isim!=null)
buf=new StringBuffer(Isim);
else
buf=new StringBuffer(15);
[Link](15);
[Link]([Link]());
if(soyIsim!=null)
buf=new StringBuffer(soyIsim);
else
buf=new StringBuffer(15);
[Link](15);
[Link]([Link]());
[Link](hesaptakiPara);
}
public void yazhesap(int a) {hesap = a;}
public int okuhesap() {return hesap;}
public void yazIsim(String f){Isim=f;}
public String okuIsim() {return Isim;}
public void yazsoyIsim(String f){soyIsim=f;}
public String okusoyIsim() {return soyIsim;}
public void yazhesaptakiPara(double b) {hesaptakiPara=b;}
public double okuhesaptakiPara() {return hesaptakiPara;}
public static int boyut() {return 72;}
}
Program 10.11 RaslantisalUlasimDosyasiYarat .java programý
import [Link].*;
import [Link].*;
import [Link].*;
import Kayit;
public class RaslantisalUlasimDosyasiYarat
{
private Kayit hesapDosyasi;
private RandomAccessFile girdi;
public RaslantisalUlasimDosyasiYarat()
{
hesapDosyasi = new Kayit();
try{
girdi = new RandomAccessFile("[Link]","rw");
for(int i=0;i<100;i++)
{ [Link](girdi); }
} catch(IOException e)
{
[Link]("Dosya acma hatasi\n"+[Link]());
[Link](1);
}
}
public static void main(String args[])
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
RaslantisalUlasimDosyasiYarat H=
new RaslantisalUlasimDosyasiYarat();
}
}
Program 10.12 RaslantisalUlasimDosyasiYaz .java programý
import [Link].*;
import [Link].*;
import [Link].*;
import Kayit;
public class RaslantisalUlasimDosyasiYaz extends Frame implements ActionListener
{
private TextField hesapAlani,isimAlani,soyisimAlani,hesaptakiParaAlani;
private Button birsonraki,kapat;
private RandomAccessFile girdi;
private Kayit hesapDosyasi;
public RaslantisalUlasimDosyasiYaz()
{
super("Tesadufi ulasim dosyasina yaz");
hesapDosyasi=new Kayit();
try{
girdi=new RandomAccessFile("[Link]","rw");
} catch(IOException e)
{
[Link]("Dosya acma hatasi\n"+[Link]());
[Link](1);
}
setSize(300,150);
setLayout(new GridLayout(5,2));
add(new Label("Hesap numarasi:"));
hesapAlani=new TextField();
add(hesapAlani);
add(new Label("isim : "));
isimAlani=new TextField(20);
add(isimAlani);
add(new Label("Soyisim : "));
soyisimAlani=new TextField(20);
add(soyisimAlani);
add(new Label("Hesaptaki para : "));
hesaptakiParaAlani=new TextField(20);
add(hesaptakiParaAlani);
birsonraki=new Button("Gir");
[Link](this);
add(birsonraki);
kapat=new Button("cikis");
[Link](this);
add(kapat);
setVisible(true);
}
public void addKayit()
{
int accountNumber=0;
Double d;
if(![Link]().equals(""))
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try{
accountNumber=[Link]([Link]());
if(accountNumber0 && accountNumber <=100)
{
[Link](accountNumber);
[Link]([Link]());
[Link]([Link]());
d=new Double([Link]());
[Link]([Link]());
[Link]((long)(accountNumber-1)*[Link]());
[Link](girdi);
}
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
catch(NumberFormatException nfe)
{
[Link]("Hesap numarasi tamsayi degisken olamalidir");
}
catch(IOException io)
{
[Link]("Dosyaya yazarken hata olustu\n"+[Link]());
[Link](1);
}
}
}
public void actionPerformed(ActionEvent e)
{
addKayit();
if([Link]()==kapat)
{
try{ [Link]();}
catch(IOException io)
{
[Link]("Dosya kapatilamadi\n"+[Link]());
}
[Link](0);
}
}
public static void main(String args[])
{
new RaslantisalUlasimDosyasiYaz();
}
}
Program 10.13 RaslantisalUlasimDosyasiOku .java programý
import [Link].*;
import [Link].*;
import [Link].*;
import Kayit;
public class RaslantisalUlasimDosyasiOku extends Frame implements ActionListener
{
private TextField hesapAlani,isimAlani,soyisimAlani,hesaptakiParaAlani;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private Button birsonraki,kapat;
private RandomAccessFile girdi;
private Kayit hesapDosyasi;
public RaslantisalUlasimDosyasiOku()
{
super("Musteri dosyasini oku");
try{
girdi=new RandomAccessFile("[Link]","r");
} catch(IOException e)
{ [Link]("Dosya acilamadi\n"+[Link]());
[Link](1);
}
hesapDosyasi=new Kayit();
setSize(300,150);
setLayout(new GridLayout(5,2));
add(new Label("Hesap numarasi :"));
hesapAlani=new TextField();
add(hesapAlani);
add(new Label("isim : "));
isimAlani=new TextField(20);
add(isimAlani);
add(new Label("soyisim : "));
soyisimAlani=new TextField(20);
add(soyisimAlani);
add(new Label("Hesaptaki para : "));
hesaptakiParaAlani=new TextField(20);
add(hesaptakiParaAlani);
birsonraki=new Button("bir sonraki hesap");
[Link](this);
add(birsonraki);
kapat=new Button("cikis");
[Link](this);
add(kapat);
setVisible(true);
}
public void okuKayit()
{
int hesap;
String ilk,son;
double balance;
{
try{
do{
[Link](girdi);
} while([Link]()==0);
[Link]([Link]([Link]()));
[Link]([Link]([Link]()));
[Link]([Link]([Link]()));
[Link]([Link]([Link]()));
}
catch(EOFException eof)
{
closeFile();
}
catch(IOException io)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]("Dosyayý okurken hata olustu\n"+[Link]());
[Link](1);
}
}
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==birsonraki)
okuKayit();
else
closeFile();
}
private void closeFile()
{
try{
[Link]();
[Link](0);
}
catch(IOException e)
{
[Link]("Error closing filr\n"+[Link]());
[Link](1);
}
}
public static void main(String args[])
{
new RaslantisalUlasimDosyasiOku();
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
10.5 DOSYA SIKIªTIRILMASI (GZIP,GUNZIP,ZIP,UNZIP)
[Link] paketi veri sýkýºtýrmaya yarayan dosyalarýiçerir. Günümüz bilgisayar kullanýmýnda
GZIP ve ZIP adý verilen bu yapýlar ZLIB sýkýºtýrma algoritmasýnda tanýmlanmýºtýr. Bu algoritm
RFC 1950,RFC 1951 ve RFC 1952 dökümanlarýnda tanýmlanmýºtýr. Bu dökümanlara
[Link] adresinden ulaºýlabilir. Kullanma açýsýndan bu dökümanlara
ihtiyacýnýz yoktur. Gerekli programlar java zip paketinde bulunmaktadýr.
GZIP tek bir dosyayý sýkýºtýrarak [Link] ismiyle sýkýºtýrýlmýº dosya oluºturur. Bunun için
GZIPOutputStream dosyasýna bir FileOutptStream açmamýz kafidir. Program 10.4 den de
görüleceði gibi
GZIPOutputStream zipout;
try {
FileOutputStream out = new FileOutputStream(zipname);
zipout = new GZIPOutputStream(out);
}
catch (IOException e) {
[Link](null,"Dosya oluºturma hatasý : " + zipname + ".");
return;
}
deyimi dosyanýn gzip olarak yazýlmasý için gerekli kanalý oluºturur.
Program 10.14 [Link] dosya sýkýºtýrma programý
//dosya: [Link]
import [Link].*;
import [Link].*;
import [Link];
public class GZip {
public static int sChunk = 8192;
public static void main(String[] args) {
if ([Link] != 1) {
[Link](null,"KULLANIM: java GZip girisdosyasi");
return;
}
// çýktý doyasý oluºtur.
String zipname = args[0] + ".gz";
GZIPOutputStream zipout;
try {
FileOutputStream out = new FileOutputStream(zipname);
zipout = new GZIPOutputStream(out);
}
catch (IOException e) {
[Link](null,"Dosya oluºturma hatasý : " + zipname + ".");
return;
}
byte[] buffer = new byte[sChunk];
// dosyayý sýkýºtýr
try {
FileInputStream in = new FileInputStream(args[0]);
int length;
while ((length = [Link](buffer, 0, sChunk)) != -1)
[Link](buffer, 0, length);
[Link]( );
}
catch (IOException e) {
[Link](null,"Dosya sýkýºtýrma hatasý : " + args[0] + ".");
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try { [Link]( ); }
catch (IOException e) {}
}
}
GZIP iºleminin tersini yapmak içinse parelel olarak :
GZIPInputStream zipin;
try {
FileInputStream in = new FileInputStream(zipname);
zipin = new GZIPInputStream(in);
}
catch (IOException e) {
[Link](null,"Dosya açma hatasý : " + zipname + ".");
return;
}
yapýsý kullanýlýr.
Programlarýn çalýºmasý için java isim deyiminden sonra dostya ismini vermek kafidir.
C:\co\java\prog>java Gzip [Link]
veya
C:\co\java\prog >java Gunzip [Link]
gibi.
Program 10.15 [Link] dosya sýkýºtýrýlmýº dosyayý açma programý
//dosya : [Link]
import [Link].*;
import [Link].*;
import [Link];
public class GUnzip {
public static int sChunk = 8192;
public static void main(String[] args) {
if ([Link] != 1) {
[Link](null,"KULLANIM: java GUnzip girisdosyasi");
return;
}
// girdi dosyasýný incele
String zipname, source;
if (args[0].endsWith(".gz")) {
zipname = args[0];
source = args[0].substring(0, args[0].length( ) - 3);
}
else {
zipname = args[0] + ".gz";
source = args[0];
}
GZIPInputStream zipin;
try {
FileInputStream in = new FileInputStream(zipname);
zipin = new GZIPInputStream(in);
}
catch (IOException e) {
[Link](null,"Dosya açma hatasý : " + zipname + ".");
return;
}
byte[] buffer = new byte[sChunk];
// dosyayý aç (decompress)
try {
FileOutputStream out = new FileOutputStream(source);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int length;
while ((length = [Link](buffer, 0, sChunk)) != -1)
[Link](buffer, 0, length);
[Link]( );
}
catch (IOException e) {
[Link](null,"Dosya sýkýºtýrýlmasý açýlma hatasý : " + args[0] + ".");
}
try { [Link]( ); }
catch (IOException e) {}
}
}
ZIP ve UNZIP biraz daha kompleks bir yapýya sahiptir. Çünki bu proseste direktory içindeki
dosyalarýn açýlma iºlemi söz konusudur.
Prosesi izah etmek için önce ZIP iºlemi yapan bir programa göz atalým :
Program 10.16 [Link] dosya sýkýºtýrma programý
// dosya : [Link]
// Turhan Çoban 24.2.2001
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
public class zip {
public static int sChunk = 8192;
public static String[] dosyalistesi(String p)
{
File path=new File(p);
if([Link]())
{
Vector x=new Vector();
File files[];
files=[Link]();
int n=[Link];
int n1=0;
for(int i=0;i<n;i++)
{
if(!files[i].isDirectory())
{
[Link](files[i].toString());
n1++;
}
}
String s1[];
s1=new String[n1];
Enumeration nn=[Link]();
int k=0;
while([Link]())
{
s1[k++]=(String)[Link]();
}
return s1;
}
else
{
String[] s1 = new String[1];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s1[0]=p;
return s1;
}
}
public static void main(String[] args) {
String str="";
FileOutputStream out;
ZipOutputStream zout;
String zipname, source;
String s="KULLANIM: \n"+
"java zip zipdosyasý dosya(veyadirectory)ismi1 dosya(veyadirectory)ismi1...\n"+
" zip dosyasý yarat ve dosya(veya directorylerdeki dosyalarý) sýkýºtýr "+
" alt direktoryler atlanmaktadýr tekrar tanýmla";
// anahtarý kontrol et
if([Link]<1 )
{
String s1="zipdosyasý [Link] tanýmlanmadý lütfen argümanlarý giriniz\n"+s;
[Link](null,s1);
[Link](0);
return;
} // girdi dosyasýný incele
else if([Link]<2)
{
String s1="sýkýºtýrýlacak dosya(veya direktory) isimleri tanýmlanmadý\n"+
" lütfen argümanlarý giriniz\n"+s;
[Link](null,s1);
[Link](0);
return;
}
if (args[0].endsWith(".zip")) {
zipname = args[0];
source = args[0].substring(0, args[0].length( ) - 3);
}
else {
zipname = args[0] + ".zip";
source = args[0];
}
//zip kanalýný tanýmla
try {
out = new FileOutputStream(zipname);
zout=new ZipOutputStream(out);
}
catch (IOException e) {
[Link](null,"Dosya oluºturma hatasý : " + zipname + ".");
return;
}
int k=1;
while(k<[Link])
{
try
{
String ss[];
ss=dosyalistesi(args[k]);
int j=0;
byte[] buffer=new byte[sChunk];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
while(j<[Link])
{
ZipEntry giris=new ZipEntry(ss[j]);
[Link](giris);
try {
FileInputStream in=new FileInputStream(ss[j]);
int length;
while((length=[Link](buffer,0,sChunk))!=-1)
[Link](buffer,0,length);
[Link]();
} //try sonu
catch (IOException e)
{
[Link](null,"Dosya sýkýºtýrma hatasý : " +ss[j] );
} //catch sonu }
str+="ss["+j+"] = "+ss[j]+" "+giris+" iceri girdi\n";
j++;
}//while sonu
} //try sonu
catch(IOException io) {}
k++;
} //while(k< sonu
try{
[Link]();
[Link]();
}
catch(IOException e){}
[Link](null,str);
[Link](0);
}
}
örnek program girdisi :
java zip [Link] c:\co\java\prog\a [Link] c:\co\java\prog\a\b
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link];
public class Unzip {
public static int sChunk = 8192;
public static void main(String[] args) {
String zipname, source;
String s="";
if ([Link] != 1) {
[Link](null,"KULLANIM: java Unzip girisdosyasi");
[Link](0);
return;
}
// girdi dosyasýný incele
if (args[0].endsWith(".zip")) {
zipname = args[0];
source = args[0].substring(0, args[0].length( ) - 3);
}
else {
zipname = args[0] + ".zip";
source = args[0];
}
s+="zip dosyasý : "+zipname+" içideki sýkýºtýrýlmýº \n";
try {
FileInputStream in = new FileInputStream(zipname);
ZipInputStream zin=new ZipInputStream(in);
byte[] buffer = new byte[sChunk];
// dosyayý aç (decompress
try{
ZipEntry z;
do
{
z=[Link]();
try {
FileOutputStream out = new FileOutputStream([Link]());
int length;
while ((length = [Link](buffer, 0, sChunk)) != -1)
[Link](buffer, 0, length);
[Link]( );
}
catch (IOException e) {
[Link](null,
"Dosya sýkýºtýrma hatasý : " + args[0] + ".");
[Link](0);
}
s+=" "+[Link]()+" \n";
}while(z!=null);
} catch(NullPointerException npe)
{ s+="dosyalarý açýldý";[Link](null,s);
[Link](0);
}
try { [Link](); } catch (IOException e) {}
}
catch(IOException e)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](null,"Dosya açýlma hatasý : " + zipname);
[Link](0);
}
}
}
programý
java unzip [Link]
komutu kullanarak çalýºtýrýrsak :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public ZipInputStream(InputStream in) ;
public ZipEntry getNextEntry() throws IOException;
public void closeEntry() throws IOException;
public int available() throws IOException ;
public int read(byte[] b, int off, int len) throws IOException;
public long skip(long n) throws IOException ;
public void close() throws IOException;
private ZipEntry readLOC() throws IOException;
private static String getUTF8String(byte[] b, int off, int len) throws IOException;
protected ZipEntry createZipEntry(String name) throws IOException;
private void readEnd(ZipEntry e) throws IOException;
private void readFully(byte[] b, int off, int len) throws IOException;
private static final int get16(byte b[], int off);
private static final long get32(byte b[], int off);
}
ZipOutputStream’in tanýmý ise :
public class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
private ZipEntry entry;
private Vector entries;
private Hashtable names ;
private CRC32 crc;
private long written;
private long locoff ;
private String comment;
private int method ;
private boolean finished;
private boolean closed = false;
private void ensureOpen() throws IOException
public static final int STORED ;
public static final int DEFLATED;
public ZipOutputStream(OutputStream out)
public void setComment(String comment)
public void setMethod(int method
public void setLevel(int level)
public void putNextEntry(ZipEntry e) throws IOException
public void closeEntry() throws IOException
public void close() throws
private void writeLOC(ZipEntry e) throws IOException
private void writeEXT(ZipEntry e) throws IOException
private void writeCEN(ZipEntry e) throws IOException
private void writeEND(long off, long len) throws IOException
private void writeShort(int v) throws IOException
private void writeInt(long v) throws IOException
private void writeBytes(byte[] b, int off, int len) throws IOException
private static byte[] getUTF8Bytes(String s)
}
ºeklindedir. Ayrýca zip dosyasýnýn içindeki elemanlar ZipEntry sýnýfýnda tanýmlanmaktadýr.
ZipEntry sýnýfý :
public class ZipEntry implements ZipConstants, Cloneable
{
String name;
long time;
long crc ;
long size;
long csize;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int method;
byte[] extra;
String comment;
int flag;
int version;
long offset;
public static final int STORED ;
public static final int DEFLATED;
private static native void initIDs();
public ZipEntry(String name)
public ZipEntry(ZipEntry e
ZipEntry(String name, long jzentry
ZipEntry(long jzentry)
public String getName()
public void setTime(long time)
public long getTime()
public void setSize(long size)
public long getSize()
public long getCompressedSize()
public void setCompressedSize(long csize)
public void setCrc(long crc)
public long getCrc()
public void setMethod(int method)
public int getMethod()
public void setExtra(byte[] extra)
public byte[] getExtra()
public void setComment(String comment)
public String getComment()
public boolean isDirectory()
public String toString()
private static long dosToJavaTime(long dtime)
private static long javaToDosTime(long time)
public int hashCode()
public Object clone()
}
ºeklinde tanýmlanmýºtýr. Burada ºu ana kadar verdiðimiz sýnýf tanýmlarý ile ilgili ºunu
söyliyelim. Tanýmlamalar sadece sýnýf ve deðiºken adlarýný vermektedir, gerçek programý
açtýðýnýzda göreceðiniz koda benzemezler sadece metod isimlerini taºýrlar.
10.6 ALIªTIRMALAR
1. [Link] programýný inceleyiniz. Bu programda sayýlar dosyadan okunup ortalamalarý
hesaplanmaktadýr.
Program 10.14 [Link] programý
import [Link].*;
import Text;
// (c) Ali SAYGIVAR
public class H9O1
{
public static void main(String[] args) throws IOException
{
DataInputStream input;
int[] i= new int[100];
String s1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Text cin= new Text();
[Link]("Lutfen dosya ismini giriniz: ");
s1 = [Link]();
File myfile = new File(s1);
BufferedReader b= new BufferedReader(new FileReader(myfile));
int toplam=0;
boolean EOF=false;
int j=0;
while (!EOF)
{
try
{
i[j]= [Link](b);
toplam+=i[j];
++j;
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
[Link]("Dosyanin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/20);
} //main
} //class
2. [Link] verilen iki sosyayý karºýlaºtýrmaktadýr. Dosya isimleri program kullanýmý
sýrasýnda verilecektir. Örnek :
java Karsilastir [Link] [Link]
Program 10.15 Karsilastir. java programý
import [Link].*;
public class Karsilastir {
//——————————————————————————————————————
// RandomAccessFile örneði
// program main()
//
// dýºarýdan iki tane dosya ismi giriniz
// dosyalarý açar ve içindekileri yükler
// dosyalarý deðerlendirir (karºýlaºtýrýr)
// dosyalarý kapatýr
//———————————————————————————————————
public static void main (String args[]) {
RandomAccessFile fh1 = null;
RandomAccessFile fh2 = null;
int bufsize; // en küçük dosyanýn byutu
long filesize1 = -1;
long filesize2 = -1;
byte buffer1[];
byte buffer2[];
// dýºarýdan okunan veriyi kontrol et
if ([Link] == 0 || args[0].equals("?") ) {
[Link] ("Random Acsess dosya Karºilaºtirma : ");
[Link] ("-----");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] ("KULLANIM : java Karsilastir <dosya1> <dosya2> | ?");
[Link] ();
[Link](0);
}
// birinci dosyayý okumak için aç
try {
fh1 = new RandomAccessFile(args[0], "r");
filesize1 = [Link]();
} catch (IOException ioErr) {
[Link] ("Dosya bulunamadi : " + args[0]);
[Link] (ioErr);
[Link](100);
}
// ikinci dosyayý okumak için aç
try {
fh2 = new RandomAccessFile (args[1], "r");
filesize2 = [Link]();
} catch (IOException ioErr) {
[Link] ("Dosya bulunamadi :" + args[1]);
[Link] (ioErr);
[Link](100);
}
if (filesize1 != filesize2) {
[Link] ("Dosya boyutlari ayni degil! ");
[Link] ("Dosya 1 : " + args[0] + "boyutu " + filesize1 + " bytes");
[Link] ("Dosya 2 : " + args[1] + "boyutu " + filesize2 + " bytes");
}
// iki dosyanýnda içeriðini alabilecek bir yer ayýr
bufsize = (int) [Link](filesize1, filesize2);
buffer1 = new byte [bufsize];
buffer2 = new byte [bufsize];
// dosyalarý toptan oku
try {
[Link] (buffer1, 0, bufsize);
[Link] (buffer2, 0, bufsize);
// ºimdi gelelim asýl iºimize...
for (int i = 0; i < bufsize; i++) {
if (buffer1[i] != buffer2[i]) {
[Link] ("dosyalar index " + i+"de degisiyor");
break;
}
}
} catch (IOException ioErr) {
[Link] ("HATA: dosyalarý icelerken bir hata oluºtu");
[Link] ([Link]());
} finally {
try {
[Link]();
[Link]();
} catch (IOException ignored) {}
}
}
}
3. File sýnýfý uygulamasý : [Link] programý istenilen directory ve alt dirctory dosyalarýný
sýrayla listeler.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 10.16 [Link] programý
//------------------------------------
import [Link].*;
import [Link].*;
public class dir {
static int indentLevel = -1;
dir (String path) {
listPath (new File (path));
}
void listPath (File path) {
File files[]; // directory'dekidosyalarýn listesi
indentLevel++; // sayýlýyor...
// bu directory'deki dosyalarýn listesini hazýrla
files = [Link]();
// Dosya isimlerini sýraya sok
[Link] (files);
for (int i=0, n=[Link]; i < n; i++) {
for (int indent=0; indent < indentLevel; indent++) {
[Link](" ");
}
[Link](files[i].toString());
if (files[i].isDirectory()) {
listPath(files[i]);
}
}
indentLevel--;
}
public static void main (String args[]) {
new dir(args[0]);
}
}
java dir c:\Driver\hpscanner\disk1
komutu sonucu :
C:\Drive\hpscanner\disk1\![Link]
C:\Drive\hpscanner\disk1\![Link]
C:\Drive\hpscanner\disk1\@[Link]
C:\Drive\hpscanner\disk1\@[Link]
C:\Drive\hpscanner\disk1\_inst32i.ex_
C:\Drive\hpscanner\disk1\_isdel.exe
4. [Link] sýnýfý içerisindeki public static String[] dosyalistesi(String p) metodu alt direktoryleri
okumadan atlamaktadýr. Alt direktoryleri de okuyup zipleyecek yeni bir [Link] programý
yazýnýz.
5. Bu problemde gerçek bir bilgisayar programlama örneðine göz atacaðýz. Program 10.8 de
[Link] programýna bakmýºtýk, bu problemde [Link] programý kullanýlarak yazýlmýº
olan [Link] programýna yer vereceðiz. Bu program ideal gazlarýn termodinamik özelliklerin
hesaplamak amacýyla yazýlmýºtýr. Program ideal gazlarýn verilerini [Link] dosyasýndan
akumaktadýr. Gaz isimleri kurucu metod tarafýndan aranan gaz isimlerine uyum saðladýðýnda
program geriye kalan veriyi okumaktadýr. Gazlar atomlardan yapýldýðýndan veride okunan
Atom isimlerine göre Atom özellikleri de bu sýnýfýn kurucu metodunda [Link] dosyasýndan
okunmakta ve deðerlendirilmektedir. Program çýktýsý almak için [Link]
programý da ayrýca verilmiºtir. Burada verilen kod özellikle bu kitap için yazýlmamýºtýr.
Uluslararasý projelerde kullanýldýðýndan açýklamalarý ingilizcedir.
Program 10.16 Gas .java programý
//======================================================
// Thermodynamic Package in java
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Class Gas Properties of perfect gases
// Dr. Turhan Coban
// TUBÝTAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : turhan@[Link]
// File Name : [Link]
// This file contains the Gas class
// this class sets basic properties of perfect gases
// required data is read from [Link]
// =====================================================
// Description : This file contains the gas class
// class gas calculates thermophysical properties of
// perfect gasses
// following properties can be calculated
// T() : Temperature degree K
// h(T) : enthalpy KJ/kmol
// hf : formation enthalpy KJ/kg
// ht(T) : total enthalpy KJ/kg (h+hf)
// M : molar mass kg/kmol
// HT(T) : total enthalpy KJ : M*ht(T)
// P() : presuure bar
// s(T,P) : entropy KJ/kmol K
// Cp(T) : specific heat at constant pressure KJ/kmol K
// Cv(T) : specific heat at constant volume KJ/kg K
// gamma(T): adiabatic constant Cp/Cv
// u(T) : Internal energy KJ/kmol
// c(T) : speed of sound m/s
// vis(T) : viscosity Ns/m^2
// k(T) : thermal conductivity KJ/kg K
// DATA FILE DEFINATION
// gas datas are written in the data file "[Link]"
// if gas data is not given in the data file, it can be curve fitted
// and added to the data file. Additional curve fitting programs supplied
// in Numerical Analysis package. Each data has the following form :
//------------------
// gasName
// n_equation M h0 hf sf
// xa[0] xb[0] xc[0] xd[0] tl[0] th[0]
// .........
// xa[n_equation-1] xb[n_equation-1]......th[n_equation-1]
// n_vis
// xvis[0]
// .........
// xvis[n_vis-1]
// n_k
// xk[0]
// .........
// xk[n_k-1]
//-------------------
// unit of the xa : kcal/kmol
// note : if any curvefitting applied for a new gas temperature values
// in K nad enthalpy values in the unit of [Link] should be supply
// for the Cp curve fitting
//============================================================
// VARIABLE IDENTIFICATION
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// all the variables that type is not defined is a double variable
// PROTECTED VARIABLES :
// xa,xb,xc,xd ,tl,th : double pointers. This values used to calculate
// specific heat at constant pressure from the following equation :
// Cp(T) = xa[i]+xb[i]*1e-3*T+xc[i]*1.0e5/T^2+xd[i]*1e-6*T^3
// where tl[i] <= T <= th[i]
// n_equation : number of equations (xa,xb,xc,xd,tl,th) for a gas
// xvis : real pointers to define viscosity according to formula :
// vis(T)=sum(xvis(i)*T^i) , for(i=0;i<n_vis;i++)
// n_vis : number of coefficients in polynomial viscosity curve fitting
// xk :real pointers to define thermal conductivity according to formula
// k(t)=sum(xk(i)*T^i) , for(i=0;i<n_k;i++)
// PUBLIC VARIABLES :
// gasName : name of the gas example : H2O :variable class str
// (class str is defined at file cstr.h and [Link], written by Timotyhy A. Budd)
// M : mol number of the gas example mol number of H2O is 18.016 kg/kmol
// h0 : value of enthalpy at 298 K in the unit of Kcal/kmol
// hf : formation enthalpy at 298 K in the unit of Kcal/kmol
// sf : value of enthalpy at 298 K and 1 bar pressure
// N : molar weight of the gas, kmol
// ierror : integer variable, error flag
//============================================================
import [Link].*;
import Text;
import Atom;
class Gas
{
double xa[],xb[],xc[],xd[],tl[],th[];
int n_equation;
int n_vis;
int n_k;
double xvis[];
double xk[];
int natom;
String gasName;
Atom atomList[];
double M; // molar mass of atom kg/kmol
double h0; // enthalpy at T=298 K
double hf; // enthalpy of formation
double sf; // entropy of formation kJ/kmol K
double N; // moles of gas kmol
int ierror;
BufferedReader fin;
File gasDir;
// definations of class functions
// constructors
//===================================================================
public Gas()
{
//empty constructor
int i;
gasName="******************************";
natom=1;
atomList=new Atom[natom];
M=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
N=1.0;
h0=0;
hf=0;
sf=0;
n_equation=6;
n_vis=10;
n_k=10;
xa=new double[6];
xb=new double[6];
xc=new double[6];
xd=new double[6];
tl=new double[6];
th=new double[6];
xvis=new double[10];
xk=new double[10];
for(i=0;i<n_equation;i++)
{xa[i]=0.0;xb[i]=0.0;xc[i]=0.0;xd[i]=0.0;tl[i]=293.0;th[i]=293.0;}
for(i=0;i<n_vis;i++)
{xvis[i]=0.0;}
for(i=0;i<n_k;i++)
{xk[i]=0.0;}
}
//===================================================================
public Gas(String gName,double Nnew) throws IOException
{
int i;
String aName;
double aN;
ierror=1;
N=Nnew;
String tempGasName="";
try{
fin=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try{
while(fin!=null)
{
tempGasName=[Link](fin);
if ([Link](gName)) {ierror=0;break;}
}
} catch(EOFException e_eof)
{
[Link]("error required gas "+tempGasName+" is not found");
[Link]();return;
}
gasName=gName;
natom=[Link](fin);
atomList=new Atom[natom];
M=0;
for(i=0;i<natom;i++)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
aName=[Link](fin);
aN=[Link](fin);
atomList[i]=new Atom(aName,aN);
M+=atomList[i].mass;
}
n_equation=[Link](fin);
h0=[Link](fin);
hf=[Link](fin);
sf=[Link](fin);
hf*=4.1868;
xa=new double[n_equation];
xb=new double[n_equation];
xc=new double[n_equation];
xd=new double[n_equation];
tl=new double[n_equation];
th=new double[n_equation];
for(i=0;i<n_equation;i++)
{
xa[i]=[Link](fin);
xb[i]=[Link](fin);
xc[i]=[Link](fin);
xd[i]=[Link](fin);
tl[i]=[Link](fin);
th[i]=[Link](fin);
}
n_vis=[Link](fin);
xvis=new double[n_vis];
for(i=0;i<n_vis;i++)
{
xvis[i]=[Link](fin);
}
n_k=[Link](fin);
xk=new double[n_k];
for(i=0;i<n_k;i++)
{
xk[i]=[Link](fin);
}
}
public Gas(String gName) throws IOException
{
double Nnew=1;
int i;
String aName;
double aN;
ierror=1;
N=Nnew;
String tempGasName="";
try{
fin=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
while(fin!=null)
{
tempGasName=[Link](fin);
if ([Link](gName)) {ierror=0;break;}
}
} catch(EOFException e_eof)
{
[Link]("error required gas "+tempGasName+" is not found");
[Link]();return;
}
gasName=gName;
//fin>>natom;
natom=[Link](fin);
atomList=new Atom[natom];
M=0;
for(i=0;i<natom;i++)
{
//fin>>aName>>aN;
aName=[Link](fin);
aN=[Link](fin);
atomList[i]=new Atom(aName,aN);
M+=atomList[i].mass;
}
//fin>>n_equation>>h0>>hf>>sf;
n_equation=[Link](fin);
h0=[Link](fin);
hf=[Link](fin);
sf=[Link](fin);
hf*=4.1868;
xa=new double[n_equation];
xb=new double[n_equation];
xc=new double[n_equation];
xd=new double[n_equation];
tl=new double[n_equation];
th=new double[n_equation];
for(i=0;i<n_equation;i++)
{
xa[i]=[Link](fin);
xb[i]=[Link](fin);
xc[i]=[Link](fin);
xd[i]=[Link](fin);
tl[i]=[Link](fin);
th[i]=[Link](fin);
}
n_vis=[Link](fin);
xvis=new double[n_vis];
for(i=0;i<n_vis;i++)
{
xvis[i]=[Link](fin);
}
n_k=[Link](fin);
xk=new double[n_k];
for(i=0;i<n_k;i++)
{
xk[i]=[Link](fin);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
public String readGasNames() throws IOException
{
String temp1="";
int natom;
String temp=new String("");
String pgasName;
String aName;
double aN;
double ppercent;
int n_equation;
double h0,hf,sf;
double xai,xbi,xci,xdi,tli,thi;
int n_vis,n_k;
double xvisi,xki;
int i;
try{
fin=new BufferedReader(new FileReader("[Link]"));
try {
while(fin!=null)
{
temp1=temp1+[Link](fin)+ " ";
natom=[Link](fin);
for(i=0;i<natom;i++)
{
aName=[Link](fin);
aN=[Link](fin);
}
n_equation=[Link](fin);
h0=[Link](fin);
hf=[Link](fin);
sf=[Link](fin);
for(i=0;i<n_equation;i++)
{
xai=[Link](fin);
xbi=[Link](fin);
xci=[Link](fin);
xdi=[Link](fin);
tli=[Link](fin);
thi=[Link](fin);
}
n_vis=[Link](fin);
for(i=0;i<n_vis;i++)
{
xvisi=[Link](fin);
}
n_k=[Link](fin);
for(i=0;i<n_k;i++)
{
xki=[Link](fin);
}
} //end of while
} catch(EOFException e_eof) {[Link]();}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch(FileNotFoundException fnfe) {[Link]("File [Link] not found");}
return temp1;
}
// ==============================================================
public Gas(Gas g) throws IOException
{
int i;
gasName=[Link];
natom=[Link];
atomList=new Atom[natom];
for(i=0;i<natom;i++)
{
atomList[i]=[Link][i];
}
M=g.M;
N=g.N;
h0=g.h0;
hf=[Link];
sf=[Link];
n_equation=g.n_equation;
n_vis=g.n_vis;
n_k=g.n_k;
xa=new double[n_equation];
xb=new double[n_equation];
xc=new double[n_equation];
xd=new double[n_equation];
tl=new double[n_equation];
th=new double[n_equation];
xvis=new double[n_vis];
xk=new double[n_k];
for(i=0;i<n_equation;i++)
{xa[i]=[Link][i];xb[i]=[Link][i];xc[i]=[Link][i];xd[i]=[Link][i];tl[i]=[Link][i];th[i]=[Link][i];}
for(i=0;i<n_vis;i++)
{xvis[i]=[Link][i];}
for(i=0;i<n_k;i++)
{xk[i]=[Link][i];}
}
//===================================================================
//change/assign new molar mass
// see also * operator for the similar function
public void changeN(double Nnew)
{
N=Nnew;
}
//===================================================================
public String toString()
{
//return the chemical symbol of the gas
String s="";
for(int i=0;i<natom;i++)
s=s+atomList[i].toString();
return s;
}
//===================================================================
public double vis(double T)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
// dynamic viscosity of the gas
double visg=0;
if(n_vis!=0.0)
{
visg=xvis[n_vis-1];
for(int i=n_vis-2;i>=0;i--)
{ visg=visg*T+xvis[i]; }
visg*=1.0e-7;
}
else
visg=0;
return visg;
}
//===================================================================
public double k(double T)
{
// thermal conductivity of the gas
double kg;
if(n_k!=0.0)
{
int nk=n_k-1;
kg=xk[nk];
for(int i=n_k-2;i>=0;i--)
{ kg+=kg*T+xk[i]; }
kg*=1.0e-3;
}
else
kg=0;
return kg;
}
//===================================================================
public double h(double T)
{
// enthalpy KJ/kmol
//integration of function dh=Cp(T)*dT
double hh = - h0;
for(int i=0;i<n_equation;i++)
{
if(((T>th[i]) && (i== (n_equation-1) ) )
|| ((T<tl[i]) && (i== 0 ) ) )
{
hh+= xa[i]*(T- tl[i])
+ xb[i]*1.0e-3/2.0*(T*T-tl[i]*tl[i])
- xc[i]*1e5*(1/T-1/tl[i])
+ xd[i]*1e-6*(T*T*T-tl[i]*tl[i]*tl[i])/3.0;
}
else if((T<= th[i]) && (T> tl[i]))
{
hh+= xa[i]*(T- tl[i])
+ xb[i]*1.0e-3/2.0*(T*T-tl[i]*tl[i])
- xc[i]*1e5*(1/T-1/tl[i])
+ xd[i]*1e-6*(T*T*T-tl[i]*tl[i]*tl[i])/3.0;
}
else if(T>th[i])
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
hh+= xa[i]*(th[i]- tl[i])
+ xb[i]*1.0e-3/2.0*(th[i]*th[i] - tl[i]*tl[i])
- xc[i]*1e5*(1/th[i]-1/tl[i])
+ xd[i]*1e-6*(th[i]*th[i]*th[i]-tl[i]*tl[i]*tl[i])/3.0;
}
}
return (hh*4.1868);
}
//===================================================================
public double ht( double t)
{
return h(t)+hf;
}
//===================================================================
public double H(double t)
{
return h(t)*N;
}
//===================================================================
public double HT(double t)
{
return ht(t)*N;
}
//===================================================================
public double u(double T)
{
// internal energy KJ/kmol
// Integration of function du = Cv(T)*dT
return (h(T) - 8.3145*T);
}
//===================================================================
public double v(double T,double P)
{
// specific volume of the gas m^3/kmol
return 8314.5*T/(P*1e5);
}
public double v(double T)
{
double P=1.0;
// specific volume of the gas m^3/kmol
return 8314.5*T/(P*1e5);
}
//===================================================================
public double c(double t)
{
// speed of sound m/s
return [Link](8314.5/M*t*gamma(t));
}
//===================================================================
public double s(double T, double P)
{
//entropy KJ/kmol K
//integration of function
// ds = Cp(T) * dt/T - R dP/P
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double ss=sf;
for(int i=0;i<n_equation;i++)
{
if( ( T > th[i] && i==n_equation - 1 )
||( T < tl[i] && i==0 ))
{
ss+=xa[i]*[Link](T/tl[i])
+ xb[i]*1.0E-3*(T-tl[i])
- xc[i]*1e5/2.0*(1.0/(T*T) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(T*T-tl[i]*tl[i]);
}
else if((T <= th[i]) && (T > tl[i]))
{
ss+=xa[i]*[Link](T/tl[i])
+ xb[i]*1.0E-3*(T-tl[i])
- xc[i]*1e5/2.0*(1.0/(T*T) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(T*T-tl[i]*tl[i]);
}
else if( T > th[i] )
{
ss+=xa[i]*[Link](th[i]/tl[i])
+ xb[i]*1.0E-3*(th[i]-tl[i])
- xc[i]*1e5/2.0*(1.0/(th[i]*th[i]) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(th[i]*th[i] - tl[i]*tl[i]);
}
}
ss*=4.1868;
return (ss-8.3145*[Link](P));
}
public double S(double T, double P)
{
return s(T,P)*N;
}
public double s(double T)
{
//entropy KJ/kmol K
//integration of function
// ds = Cp(T) * dt/T - R dP/P
double ss=sf;
for(int i=0;i<n_equation;i++)
{
if( ( T > th[i] && i==n_equation - 1 )
||( T < tl[i] && i==0 ))
{
ss+=xa[i]*[Link](T/tl[i])
+ xb[i]*1.0E-3*(T-tl[i])
- xc[i]*1e5/2.0*(1.0/(T*T) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(T*T-tl[i]*tl[i]);
}
else if((T <= th[i]) && (T > tl[i]))
{
ss+=xa[i]*[Link](T/tl[i])
+ xb[i]*1.0E-3*(T-tl[i])
- xc[i]*1e5/2.0*(1.0/(T*T) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(T*T-tl[i]*tl[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
else if( T > th[i] )
{
ss+=xa[i]*[Link](th[i]/tl[i])
+ xb[i]*1.0E-3*(th[i]-tl[i])
- xc[i]*1e5/2.0*(1.0/(th[i]*th[i]) - 1.0/(tl[i]*tl[i]))
+ xd[i]*1e-6/2.0*(th[i]*th[i] - tl[i]*tl[i]);
}
}
ss*=4.1868;
return ss;
}
//===================================================================
public double s0(double T)
{
return s(T);
}
//===================================================================
public double g(double T,double P)
{
return h(T)-T*s(T,P);
}
public double gt(double T,double P)
{
return h(T)+hf-T*s(T,P);
}
public double gt(double T)
{
return h(T)+hf-T*s(T,1);
}
public double g(double T)
{
double P=1.0;
return h(T)-T*s(T,P);
}
public double G(double T,double P)
{
return g(T,P)*N;
}
public double G(double T)
{
return g(T)*N;
}
public double GT(double T)
{
return gt(T)*N;
}
public double GT(double T,double P)
{
return gt(T,P)*N;
}
//===================================================================
public double g0(double T)
{
return h(T)-T*s0(T);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
//===================================================================
public double Cp(double T)
{
//specific heat at constant pressure KJ/kmol K
double cp=0.0;
for (int i=0;i<n_equation;i++)
{
if( ( T > th[i] && i==n_equation - 1 )
||( T < tl[i] && i==0 ))
{
cp=xa[i]+xb[i]*1.0e-3*T+xc[i]*1.0e5/T/T+xd[i]*1.0e-6*T*T;
break;
}
else if((T <= th[i]) && (T > tl[i]) )
{
cp=xa[i]+xb[i]*1.0e-3*T+xc[i]*1.0e5/T/T+xd[i]*1.0e-6*T*T;
break;
}
}
return (cp*4.1868);
}
//===================================================================
public double Cv(double T)
{
//specific heat at constant volume KJ/kmol K
double cv;
cv=Cp(T) - 8.3145;
return cv;
}
//===================================================================
public double gamma(double T)
{
//adiabatic constant
return Cp(T)/Cv(T);
}
//===================================================================
public double T( char name,double y0,double p)
{
// name can have values h : for enthalpy
// u : for internal energy
// s : for entropy
// v : specific volume
// yo : the value of the variable given by variable name
double t=300;
if(name=='v') {t= p*1e5*y0/8.3145e3;}
else
{
double dt=0;
int nmax=400;
double tolerance=1.0e-8;
for(int i=0;i<nmax;i++)
{
// apply newtons method for finding roots of equation
if (name=='h') dt=-( h(t) - y0 ) /Cp(t);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if(name=='u') dt=-( u(t) - y0 ) /Cv(t);
else if(name=='s') dt=-( s(t,p) - y0 ) /(Cp(t)/t);
else { [Link]("wrong name defined please try h,u,s ot v");}
t+=dt;
// if error range is less than tolerance, exit
if([Link](dt)<tolerance) break;
}
}
return t;
}
public double T( char name,double y0)
{
// name can have values h : for enthalpy
// u : for internal energy
// s : for entropy
// v : specific volume
// yo : the value of the variable given by variable name
double t=300;
double p=1.0;
if(name=='v') {t= p*1e5*y0/8.3145e3;}
else
{
double dt=0;
int nmax=400;
double tolerance=1.0e-8;
for(int i=0;i<nmax;i++)
{
// apply newtons method for finding roots of equation
if (name=='h') dt=-( h(t) - y0 ) /Cp(t);
else if(name=='u') dt=-( u(t) - y0 ) /Cv(t);
else if(name=='s') dt=-( s(t,p) - y0 ) /(Cp(t)/t);
else { [Link]("wrong name defined please try h,u,s ot v");}
t+=dt;
// if error range is less than tolerance, exit
if([Link](dt)<tolerance) break;
}
}
return t;
}
//===================================================================
public double P( char name,double y0,double t1)
{
// name can have values v : for specific volume
// s : for entropy
// note : for a perfect gas enthalpy and internal energy
// is not function of pressure
// yo : the value of the variable given by variable name
if(name=='v') return 8.3145e3*t1/y0*1e-5;
else if (name=='s') return [Link]((s(t1,1.0)-y0)/8.3145);
else { [Link]("wrong name defined please try s or v"); return 1.0;}
}
//===================================================================
public double Pr(double t)
{
// Prandtl number
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return Cp(t)*vis(t)/k(t)/M*1e3;
}
//===================================================================
public void assign(Gas g1) throws IOException
{
// assign operator (assigning a new gas to the gas variable)
int i;
ierror=1;
gasName=[Link];
N=g1.N;
n_equation=g1.n_equation;
n_k=g1.n_k;
n_vis=g1.n_vis;
M=g1.M;
h0=g1.h0;
hf=[Link];
sf=[Link];
natom=[Link];
atomList=new Atom[natom];
M=0;
for(i=0;i<natom;i++)
{
atomList[i]=new Atom([Link][i].name,[Link][i].N);
}
xa=new double[n_equation];
xb=new double[n_equation];
xc=new double[n_equation];
xd=new double[n_equation];
tl=new double[n_equation];
th=new double[n_equation];
xvis=new double[n_vis];
xk=new double[n_k];
for(i=0;i<n_equation;i++)
{ xa[i]=[Link][i];
xb[i]=[Link][i];
xc[i]=[Link][i];
xd[i]=[Link][i];
tl[i]=[Link][i];
th[i]=[Link][i];
}
for(i=0;i<n_vis;i++)
{ xvis[i]=[Link][i];}
for(i=0;i<n_k;i++)
{xk[i]=[Link][i];}
}
//===================================================================
public Gas multiply(double Nnew, Gas g1) throws IOException
{
Gas g2=new Gas(g1);
g2.N*=Nnew;
return g2;
}
public boolean equals(Gas g)
{
if([Link]([Link]))
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return true;
else
return false;
}
//=================================================================
}
//=================================================================
Gaz özelliklerinin yer aldýðý bilgi dosyasý [Link] (sadece iki örnek gaz ch4 ve c2h6 için veri
listelenmiºtir.) :
ch4
2
C1
H4
6 0 -17883.1088181 44.4764979459
.569592791684135E+01 .230885866354099E+02 .257021911461535E-03 -
.514500509673528E+02 298. 300.0
.549418872803147 23.348756180407 1.4381268667348 -6.89019972775113 300.0 1000.00
11.8834319588735 9.20574503493484 -21.4292411101953 -1.8024921550441 1000.0
2000.0
23.037791919106 1.1029857730146 -87.1157168947875 -.127020658512245 2000.0
3000.0
22.0766220965729 1.36002847842152 -59.4550709113699 -0.1402094192352699 3000.0
4000.0
25.8471557797976 -0.0210627042222442 -144.63391429225 0.00254109611861818
4000.0 6000.0
4
-.317434898401931E+01
.455271007474814E+00
-.273399388607163E-03
.895312831114117E-07
4
.399296677905716E+01
.551053536678452E-01
.172999763063988E-03
-.657213363465470E-07
c2h6
2
C2
H6
3 0 -20226.42591 54.8394955574
5.255293329509001 29.744079588767550 -1.128964437911497 -4.086756508274219
298.15 600.0
3.855945449740792 35.946345289228690 -1.504708264372915 -10.330104368611350
600.0 1000.0
21.017162073226170 15.065627352784930 -34.594573805677190 -3.233353234903328
1000.0 1473.15
3
-0.492854013060778E+01
0.379062761757185E+00
-0.148297458234132E-03
3
-0.173496859087276E+02
0.117899036192513E+00
0.399524288778580E-04
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 10.17 [Link] : bu program veri çýktýsýnýn bir parçasýdýr, çýktýyý tablo
formunda elde etmemiz amacýyla kullanýlmýºtýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class GasModel extends AbstractTableModel
{
Object[][] veri={
{"Gas Formula : ","0"," "},
{"M : ","0","kg/kmol"},
{"h, enthalpy : ","0","KJ/kmol"},
{"u, Internal energy : ","0","KJ/kmol"},
{"s, Entropy : ","0","KJ/kmol K"},
{"v, Specific volume : ","0","m^3/kmol"},
{"k, Thermal conductivity : ","0","W/m K"},
{"h+hf, enthalpy+formation enth. : ","0","KJ/kmol"},
{"Density : ","0","kg/m^3"},
{"Cp : ","0"," KJ/kmol K"},
{"Cv : ","0","KJ/kmol K"},
{"Cp/Cv adiabatic constant : ","0"," "},
{"c speed of sound : ","0","m/s"},
{"Viscosity : ","0","N s/m^2"},
{"Pr,Prandtl Number : ","0"," "}};
String[] baslik={"Property ","Value ","Units"};
public GasModel(Gas g1,double TK,double P)
{
setValues(g1,TK,P);
}
public int getRowCount() {return [Link];}
public int getColumnCount() {return [Link];}
public Object getValueAt(int satir,int sutun) {return veri[satir][sutun];}
public String getColumnName(int c) {return baslik[c];}
public void setValueAt(Object val, int row, int col)
{
veri[row][col] = val;
}
public void setValues(Gas g1,double T,double P)
{
double TK=T+273.0;
setValueAt([Link](),0,1);
setValueAt((""+g1.M),1,1);
setValueAt([Link](g1.h(TK)),2,1);
setValueAt([Link](g1.u(TK)),3,1);
setValueAt([Link](g1.v(TK,P)),4,1);
setValueAt([Link](g1.s(TK,P)),5,1);
setValueAt([Link](g1.k(TK)),6,1);
setValueAt([Link]([Link](TK)),7,1);
setValueAt([Link](g1.M/g1.v(TK)),8,1);
setValueAt([Link]([Link](TK)),9,1);
setValueAt([Link]([Link](TK)),10,1);
setValueAt([Link]([Link](TK)),11,1);
setValueAt([Link](g1.c(TK)),12,1);
setValueAt([Link]([Link](TK)),13,1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
setValueAt([Link]([Link](TK)),14,1);
}
public boolean isCellEditable(int row, int col) {return true;}
}
Program 10.18 [Link]
// ======================================================
// Thermodynamics package in java
// GasPropertySWF class to calculate properties of gases
// user interface (JFrame)
// Dr. Turhan Coban
// TUBITAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : [Link]@[Link]
// =====================================================
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import GasModel;
public class GasPropertySWF extends JFrame implements ActionListener,ItemListener
{
JPanel inputPanel;
JPanel outputPanel;
JPanel totalPanel;
JTextField promptGasName; // Label prompt GasName
JTextField promptTemperature; // Label prompt Temperature
JTextField promptPressure; // Label prompt Pressure
JComboBox inputGasName; // input GasName
JTextField inputTemperature; // input (from list )Temperature
JTextField inputPressure; // input Pressure
JTextArea outputTextArea;
GasModel gm;
JTable jt;
double T;
double P;
String gasName;
Gas g1;
protected File gmixFile;
protected StringTokenizer token;
String st[];
final static Color bg=[Link];
final static Color fg=[Link];
final static Color kirmizi=[Link];
final static Color beyaz=[Link];
public GasPropertySWF()
{
super("Properties of perfect gases ");
Container c=getContentPane();
[Link](new FlowLayout());
//adding max-min prompts and input fields
gasName=new String("air");
T=27.0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
P=1.0;
inputPanel=new JPanel();
[Link](new GridLayout(3,2));
outputPanel=new JPanel();
[Link](new BorderLayout());
totalPanel=new JPanel();
[Link](new BorderLayout());
try{
g1=new Gas(gasName);
token=new StringTokenizer([Link]());
st=new String[[Link]()];
} catch(IOException ioe) {[Link]("IOException");}
int i=0;
while([Link]())
{
st[i++]=new String((String)[Link]());
}
inputGasName=new JComboBox(st);
gasName=(String)[Link]();
try{
g1=new Gas(gasName);
} catch(IOException ioe) {[Link]("IOException");}
promptGasName= new JTextField(20);
[Link]("Name of gas mixture : ");
[Link]([Link]);
promptTemperature=new JTextField(20);
[Link]("Temperature (°C) : ");
[Link]([Link]);
inputTemperature=new JTextField(20);
[Link]([Link]);
promptPressure= new JTextField(20);
[Link]("Pressure (Bars) : ");
[Link]([Link]);
outputTextArea = new JTextArea();
[Link]([Link]);
inputPressure=new JTextField(20);
[Link]([Link]);
[Link](promptGasName);
[Link](inputGasName);
[Link](promptTemperature);
[Link](inputTemperature);
[Link](promptPressure);
[Link](inputPressure);
[Link](this);
[Link](this);
[Link](this);
gm=new GasModel(g1,T,P);
jt=new JTable(gm);
[Link]([Link]());
setArea();
[Link](outputTextArea,[Link]);
[Link](jt,[Link]);
[Link](inputPanel,[Link]);
[Link](outputPanel,[Link]);
[Link](totalPanel,[Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public void setArea()
{
double TK=T+273.0;
[Link]([Link](T));
[Link]([Link](P));
String s="additional data can be added to [Link] file \n";
s+="Dr. Turhan Çoban, TUBÝTAK Marmara Research Center\n";
s+="Energy Systems & Environmental Research Institute\n";
s+="PO Box 21, Gebze - Kocaeli, Turkey\n";
s+="email: [Link]@[Link]\n";
//note if you would like to list additional information on the screen
//add to string s
// s+="Gas Formula : "+[Link]("formula")+"\n";
// s+= "Gas Composition : "+[Link]("composition")+"\n";
[Link](g1,T,P);
[Link](s);
}
public void itemStateChanged(ItemEvent ev)
{
gasName=(String)[Link]();
try{
g1=new Gas(gasName);
} catch(IOException ioe1) {[Link]("IOException");}
setArea();
repaint();
}
public void actionPerformed( ActionEvent e)
{
Double valTemp=new Double([Link]());
T=[Link]();
Double valPressure=new Double([Link]());
P=[Link]();
getContentPane().setLayout(new FlowLayout([Link]));
setArea();
repaint();
}
public static void main(String[] args)
{
GasPropertySWF pencere= new GasPropertySWF();
[Link](
new WindowAdapter()
{
public void windowClosing(WindowEvent e) {[Link](0);}
} );
[Link]();
[Link](true);
}
}
Program çýktýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
6. Bu problemde bir önceki problemde verilen uygulamanýn bir kademe daha ilerine
gideceðiz. Burada Gazlarý karýºtýrýp bir gaz karýºýmý elde edecek ve bu gaz karýºýmýnýn
termodinamik özelliklerine bakacaðýz. Programýmýzýn ismi [Link], gazlarý karýºtýrdýðýmýz
veri dosyasý [Link] ve çýktý dosyalarýmýz [Link] ve [Link]
Program 10.19 [Link]
// ==============================================================
// File Name : [Link]
// Author : Dr. Turhan Coban
// TUBÝTAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : [Link]@[Link]
// Description : This file contains class gmix which calculates
// thermophysical properties of mixture of perfect gases.
// following properties can be calculated
// T() : Temperature degree K
// h(T) : enthalpy KJ/kmol
// hf : formation enthalpy KJ/kg
// ht(T) : total enthalpy KJ/kg (h+hf)
// M : molar mass kg/kmol
// HT(T) : total enthalpy KJ : M*ht(T)
// P() : presure bar
// s(T,P) : entropy KJ/kmol K
// Cp(T) : specific heat at constant pressure KJ/kmol K
// Cv(T) : specific heat at constant volume KJ/kg K
// gamma(T): adiabatic constant Cp/Cv
// c(T) : speed of sound m/s
// u(T) : Internal energy KJ/kmol
// vis(T) : viscosity
// k(T) : thermal conductivity KW/kg K
// DATA FILE DEFINATION
// gas mixture definations are given the data file "[Link]"
// if gas mixture data is not given in the [Link] user can be add
// his own data to the file which has the following format
//------------------
// gmixName
// ngas
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// gname_0 N_0
// .........
// gname_ngas-1 N_ngas-1
//-------------------
// and defination : gmix a(gmixName); will defined this gas mixture
// the same mixture can be defined directly in the main program as :
// -------------------
// Gas a_0=new Gas("a_0");
//.......
// Gas a_ngas=new Gas("a_ngas);
// Gmix a=new Gmix;
// a=N_0*a_0+...+N_ngas*a_ngas;
// -------------------
//============================================================
// VARIABLE IDENTIFICATION
// all the variables that type is not defined is a double variable
// PUBLIC VARIABLES :
// gasName : String class variable of gas mixture name
// ngas : int variable, number of simple gasses
// N : total molar mass of the gas mixture
// gasList :gas class vector variables
// All the other variables defined for class gas is also valid for gmix
import [Link].*;
import [Link].*;
import Text;
import Atom;
import Gas;
// ==============================================================
class Gmix{
// this class calculates perfect gas thermodynamic
// properties when the perfect gas constitutes of
// several single gases
public int ngas; // number of simple gasses inside of the gas mixture
String gasName;
public double M; // molar mass of atom kg/kmol
public double h0; // enthalpy at T=298 K
public double hf; // enthalpy of formation
public double sf; // entropy of formation kJ/kmol K
public double N; // moles of gas kmol
int ierror;
int natom; //number of unique atoms in the atom list
Gas gasList[]; //list of the component gasses
Atom atomList[]; //list of component atoms
File gmixFile; // File name and directory
BufferedReader cfin;
// construction methods :
//========definations of class gmix =============================
//constructor functions
public Gmix(String name) throws IOException
{
// class complex gas construction function
// this function reads the initial gases in
// the mixture and their molar weight from
// the file [Link] and construct mixed gas
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
cfin=new BufferedReader(new FileReader("[Link]"));
int ierror=1;
int i,j;
N=0;
M=0;
hf=0;
natom=0;
try{
while(cfin!=null)
{
gasName=[Link](cfin);
if([Link](name)) { ierror=0; break;}
} //end of while
} catch(EOFException e_eof)
{
[Link]("error required gas mixture "+name+" is not found");
[Link]();return;
}
//cfin>>ngas;
ngas=[Link](cfin);
gasList=new Gas[ngas];
//ierror=0;
String pgasName;
double ppercent;
Gas tempgas;
for(i=0;i<ngas;i++)
{
pgasName=[Link](cfin);
ppercent=[Link](cfin);
//cfin>>pgasName>>ppercent;
tempgas=new Gas(pgasName,ppercent);
ierror=[Link];
{
if(ierror!=1)
{
try{
gasList[i]=new Gas(tempgas);
} catch(IOException ioe) {[Link]("IOException");}
N+=tempgas.N;
M+=tempgas.N*tempgas.M;
hf+=tempgas.N*[Link];
}
else
{
[Link]("gas is not found in the list");
[Link]("this gas is not added to the list");
i--;
ngas--;
}
}
}
M=M/N;
hf=hf/N;
arrange_atoms();
} catch(FileNotFoundException fnfe) {[Link]("File not found");}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
// ==============================================================
public String readGmixNames() throws IOException
{
String temp=new String("");
String pgasName;
double ppercent;
try{
cfin=new BufferedReader(new FileReader("[Link]"));
try {
while(cfin!=null)
{
temp=temp+[Link](cfin)+ " ";
ngas=[Link](cfin);
for(int i=0;i<ngas;i++)
{
pgasName=[Link](cfin);
ppercent=[Link](cfin);
} //end of while
}
} catch(EOFException e_eof) {[Link]();}
}
catch(FileNotFoundException fnfe) {[Link]("File [Link] not found");}
return temp;
}
// ==============================================================
public void arrange_atoms() throws IOException
{
int i,j;
for(i=0;i<ngas;i++)
{
for(j=0;j<gasList[i].natom;j++)
{
add_atom(i,j);
}
}
}
public int add_atom(int i,int j) throws IOException
{
int k;
//Atom tempAtom=new
Atom(gasList[i].atomList[j].symbol,gasList[i].atomList[j].N*gasList[i].N/N);
for(k=0;k<natom;k++)
{
if(gasList[i].atomList[j].[Link](atomList[k].symbol))
{
atomList[k]=new
Atom(atomList[k].symbol,atomList[k].N+gasList[i].atomList[j].N*gasList[i].N/N);
return 1;
}
}
Atom atomL[];
atomL=new Atom[natom+1];
for(k=0;k<natom;k++)
atomL[k]=new Atom(atomList[k]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
atomL[natom]=new Atom(gasList[i].atomList[j].symbol,gasList[i].atomList[j].N*gasList[i].N/N);
atomList=atomL;
natom+=1;
return 2;
}
//===============================================================
public Gmix() throws IOException
{
//empty construction function
N=0;
M=0;
String pgasname="\0";
ngas=0;
}
// ==============================================================
public Gmix(Gmix g1) throws IOException
{
gasName=[Link];
gasName=gasName;
N=g1.N;
M=g1.M;
hf=[Link];
ngas=[Link];
natom=[Link];
gasList=new Gas[ngas];
for(int i=0;i<ngas;i++) gasList[i]=new Gas([Link][i]);
for(int i=0;i<natom;i++) atomList[i]=new Atom([Link][i]);
}
// ==============================================================
public Gmix(Gas g1) throws IOException
{
gasName=[Link];
gasName=gasName;
N=g1.N;
M=g1.M;
hf=[Link];
ngas=1;
natom=[Link];
gasList=new Gas[ngas];
for(int i=0;i<ngas;i++) gasList[i]=new Gas(g1);
for(int i=0;i<natom;i++) atomList[i]=new Atom([Link][i]);
}
// ==============================================================
public void changeN(double newN) throws IOException
{
normalise();
for(int i=0;i<ngas;i++)
{ gasList[i].N*=newN; }
N=newN;
}
// ==============================================================
public void add(Gas g1) throws IOException
{
// this function adds a single gas to the mixture
int gasflag=1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// if the gas exist in the list simply change N and M values
for(int i=0;i<ngas;i++)
{
if(gasList[i].[Link]([Link]))
{
gasflag=0;
M=M*N+g1.M*g1.N;
gasList[i].N+=g1.N;
N+=g1.N;
M=M/N;
}
}
if(gasflag!=0)
{
Gas newGas[];
newGas=new Gas[ngas+1];
for(int i=0;i<ngas;i++)
{
newGas[i]=new Gas(gasList[i]);
}
ngas++;
double MT=M*N+g1.M*g1.N;
N+=g1.N;
M=MT/N;
newGas[ngas-1]=new Gas(g1);
gasList=newGas;
}
arrange_atoms();
}
// ==============================================================
public void remove(String name) throws IOException
{
// this function removes a single gas
// from the list
int i,k;
for(i=0;i<ngas;i++)
{
if(gasList[i].[Link](name))
{
Gas newGas[];
newGas=new Gas[ngas];
M=0;
N=0;
for(k=0;k<i;k++)
{ newGas[k]=new Gas(gasList[k]);
M+=newGas[k].M*newGas[k].N;
N+=newGas[k].N;
}
for( k=i;k<(ngas-1);k++)
{
newGas[k]=new Gas(gasList[k+1]);
M+=newGas[k].M*newGas[k].N;
N+=newGas[k].N;
}
M=M/N;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ngas--;
gasList=newGas;
break;
}
}
arrange_atoms();
// correct dynamic memory size
}
// ==============================================================
public void add(String name,double Nnew) throws IOException
{
// this function adds a single gas to the mixture
Gas g1=new Gas(name,Nnew);
int gasflag=1;
// if the gas exist in the list simply change N and M values
for(int i=0;i<ngas;i++)
{
if(gasList[i].[Link]([Link]))
{
gasflag=0;
M=M*N+g1.M*g1.N;
gasList[i].N+=g1.N;
N+=g1.N;
M=M/N;
}
}
if(gasflag!=0)
{
Gas newGas[];
newGas=new Gas[ngas+1];
for(int i=0;i<ngas;i++)
{
newGas[i]=new Gas(gasList[i]);
}
ngas++;
double MT=M*N+g1.M*g1.N;
N+=g1.N;
M=MT/N;
newGas[ngas-1]=new Gas(g1);
gasList=newGas;
}
arrange_atoms();
}
// ==============================================================
public void simplify() throws IOException
{
// this function combines any single gas
// that repeated in the list
double ngasold=ngas;
int i,j,k;
for(i=0;i<ngas;i++)
{
for(j=i+1;j<ngas;j++)
{
if(gasList[i].[Link](gasList[j].gasName))
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
gasList[i].N+=gasList[j].N;
for(k=j;k<(ngas-1);k++)
{ gasList[k]=new Gas(gasList[k+1]); }
ngas--;
}
}
}
// correct dynamic memory size
if(ngasold!=ngas)
{
Gas newGas[];
newGas=new Gas[ngas];
for(i=0;i<ngas;i++)
{
newGas[i]=new Gas(gasList[i]);
}
gasList=newGas;
}
}
// ==============================================================
public void normalise() throws IOException
{
for(int i=0;i<ngas;i++)
{
gasList[i].N=gasList[i].N/N;
}
N=1.0;
arrange_atoms();
}
// ==============================================================
public void changeMix(double Nmix[]) throws IOException
{
// this function changes
// all the molar weights in the mixture
N=0;
M=0;
for(int i=0;i<ngas;i++)
{
gasList[i].N=Nmix[i];
N+=Nmix[i];
M+=Nmix[i]*gasList[i].M;
}
M=M/N;
arrange_atoms();
}
// ==============================================================
public double vis(double T)
{
// dynamic viscosity of the mixture
// note that viscosity of the mixture IS NOT the simple addition
// of viscosity of component gasses
double vmix=0;
for(int i=0;i<ngas;i++)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
T=T;
double fij;
double xj=0;
double p1;
double c1,c2,c3;
for(int j=0;j<ngas;j++)
{
double vratio;
double xi=gasList[i].M/gasList[j].M;
if(gasList[j].vis(T)!=0)
{
c1=gasList[i].vis(T)/gasList[j].vis(T);
vratio=[Link](c1);
}
else
vratio=0;
c2=[Link](xi,0.25);
p1=(1+vratio/c2);
c3=8.0+8.0*xi;
fij=p1*p1 / [Link](c3);
xj+=fij*gasList[j].N/N;
}
vmix+=gasList[i].N/N*gasList[i].vis(T)/xj;
}
return vmix;
}
// ==============================================================
public double k(double T)
{
// thermal conductivity of the mixture
// note that thermal conductivity of the mixture IS NOT the
// simple addition of the thermal conductivity of component gasses
double vmix=0;
for(int i=0;i<ngas;i++)
{
T=T;
double fij;
double xj=0;
double p1;
double c1,c2,c3;
for(int j=0;j<ngas;j++)
{
double vratio;
double xi=gasList[i].M/gasList[j].M;
if(gasList[j].k(T)!=0)
{
c1=gasList[i].k(T)/gasList[j].k(T);
// if(c1<0) [Link]("negative c1 value ");
vratio=[Link](c1);
}
else
vratio=0;
c2=[Link](xi,0.25);
p1=(1+vratio/c2);
c3= 8.0+8.0*xi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// if(c2<0) [Link](" negative c2 value ");
fij=p1*p1/[Link](c3);
xj+=fij*gasList[j].N/N;
}
vmix+=gasList[i].N/N*gasList[i].k(T)/xj;
}
return vmix;
}
// ==============================================================
public double Pr(double t)
{
// Prandtl number
return Cp(t)*vis(t)/k(t)/M*1e3;
}
// ==============================================================
public double h(double T)
{
//specific enthalpy of the mixture KJ/kmol
double HH=0;
for(int i=0;i<ngas;i++)
{ HH+=gasList[i].h(T)*gasList[i].N; }
return HH/N;
}
// ==============================================================
public double ht(double T)
{
//specific enthalpy of the mixture ht=h+hf
// hf : formation enthalpy
double HH=0;
for(int i=0;i<ngas;i++)
{ HH+=gasList[i].ht(T)*gasList[i].N; }
return HH/N;
}
// ==============================================================
public double H(double t)
{
//total enthalpy of the mixture KJ
return h(t)*N;
}
// ==============================================================
public double HT(double t)
//total enthalpy of the mixture HT=N*(h+hf) KJ
{
return ht(t)*N;
}
// ==============================================================
public double u(double T)
{
// specific internal energy of the mixture KJ/kmol
double UU=0;
for(int i=0;i<ngas;i++)
{ UU+=gasList[i].u(T)*gasList[i].N; }
return UU/N;
}
// ==============================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public double Cp(double T)
{
// Specific energy at constant pressure KJ/kmol K
double C=0;
for(int i=0;i<ngas;i++)
{ C+=gasList[i].Cp(T)*gasList[i].N; }
return C/N;
}
// ==============================================================
public double Cv(double T)
//Specific energy at constant volume KJ/kmol K
{
double C=0;
for(int i=0;i<ngas;i++)
{ C+=gasList[i].Cv(T)*gasList[i].N; }
return C/N;
}
// ==============================================================
public double gamma(double T)
{
//adiabatic constant
return Cp(T)/Cv(T);
}
// ==============================================================
public double c(double T)
//speed of sound m/s
{
return [Link](8314.5/M*T*gamma(T));
}
// ==============================================================
public double s(double T, double P)
{
//specific entropy KJ/kmol K
double SS=0;
for(int i=0;i<ngas;i++)
{
SS+=gasList[i].s(T,P)*gasList[i].N;
}
return SS/N;
}
public double s(double T)
{
//specific entropy KJ/kmol K
double P=1.0;
double SS=0;
for(int i=0;i<ngas;i++)
{
SS+=gasList[i].s(T,P)*gasList[i].N;
}
return SS/N;
}
// ==============================================================
public double v(double T, double P)
{
double VV=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<ngas;i++)
{ VV+=gasList[i].v(T,P)*gasList[i].N; }
return VV/N;
}
// ==============================================================
public double T( char name,double y0,double p)
{
double t=300;
if(name=='v') {t= p*1e5*y0/8.314e3;}
else
{
double dt;
int nmax=400;
double tolerance=1.0e-8;
for(int i=0;i<nmax;i++)
{
if (name=='h') dt=-( h(t) - y0 ) /Cp(t);
else if(name=='u') dt=-( u(t) - y0 ) /Cv(t);
else if(name=='s') dt=-( s(t,p) - y0 ) /(Cp(t)/t);
else { [Link]("wrong name defined please try h,u,s ot v"); break;}
t+=dt;
if([Link](dt)<tolerance) break;
}
}
return t;
}
// ==============================================================
public double P( char name,double y0,double t1)
{
if(name=='v') return 8.314e3*t1/y0*1e-5;
else if (name=='s') return [Link]((s(t1,1.0)-y0)/8.314);
else { [Link]("wrong name defined please try s or v"); return 1.0;}
}
// ==============================================================
public void multiplyassign(double Nx)
{
for(int i=0;i<ngas;i++)
{ gasList[i].N*=Nx; }
N*=Nx;
}
// ==============================================================
public void addassign(Gas g1) throws IOException
{
// this function adds a single gas to the mixture
int gasflag=1;
// if the gas exist in the list simply change N and M values
for(int i=0;i<ngas;i++)
{
if(gasList[i].gasName==[Link])
{
gasflag=0;
M=M*N+g1.M*g1.N;
gasList[i].N+=g1.N;
N+=g1.N;
M=M/N;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
if(gasflag!=0)
{
Gas newGas[];
newGas=new Gas[ngas+1];
for(int i=0;i<ngas;i++)
{
newGas[i]=new Gas(gasList[i]);
}
ngas++;
double MT=M*N+g1.M*g1.N;
N+=g1.N;
M=MT/N;
newGas[ngas-1]=new Gas(g1);
gasList=newGas;
}
}
// ==============================================================
public void addassign(Gmix right) throws IOException
{
// this function adds a gas mixture to the mixture
for(int i=0;i<[Link];i++)
{
add([Link][i]);
}
}
// ==============================================================
public Gmix multiply( double Nx,Gmix right) throws IOException
{
Gmix g1=new Gmix(right);
g1.N*=Nx;
for(int i=0;i<[Link];i++)
{
[Link][i].N*=Nx;
}
return g1;
}
// ==============================================================
public Gmix add(Gas l,Gas r) throws IOException
{
Gmix g1=new Gmix(r);
Gas g2=new Gas(l);
[Link](g2);
return g1;
}
// ==============================================================
public Gmix add(Gmix l,Gas r) throws IOException
{
Gmix g1=new Gmix(l);
Gas g2=new Gas(r);
[Link](g2);
return g1;
}
// ==============================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public Gmix add(Gas l,Gmix r) throws IOException
{
Gmix g1=new Gmix(r);
Gas g2=new Gas(l);
[Link](g2);
return g1;
}
// ==============================================================
public Gmix add(Gmix l,Gmix r) throws IOException
{
Gmix g1=new Gmix(l);
for(int i=0;i<[Link];i++)
{
[Link]([Link][i]);
}
return g1;
}
// ==============================================================
public void assign(Gmix g1) throws IOException
{
gasName=[Link];
N=g1.N;
M=g1.M;
ngas=[Link];
Gas newGas[];
newGas=new Gas[ngas];
for(int i=0;i<ngas;i++) newGas[i]=[Link][i];
gasList = newGas;
}
// ==============================================================
public void assign(Gas g1) throws IOException
{
// a single gas is assigned to the mixture
gasName=[Link];
N=g1.N;
M=g1.M;
ngas=1;
gasList=new Gas[ngas];
gasList[0]=new Gas(g1);
}
public String toString(String ch)
{
//return the c
String s="";
int i,j;
if([Link]("name"))
s=s+gasName+"\n";
else if([Link]("formula"))
{
for(i=0;i<ngas;i++)
{ s=s+" "+gasList[i].toString()+" "+gasList[i].N+"\n"; }
}
else if([Link]("composition"))
{
for(i=0;i<natom;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s=s+atomList[i].toString()+"\n";
}
return s;
}
}//end of class
Gmix veri dosyasý [Link] (kýsmi liste )
diesel1
25
c9h20 0.0122
c10h22 0.0243
c11h24 0.0517
c12h26 0.0912
c13h28 0.2007
c14h30 0.1959
c15h32 0.098
c16h34 0.049
c17h36 0.0245
c18h38 0.0122
c19h40 0.0061
c20h42 0.0031
c11h16 0.0027
c12h18 0.0041
c13h20 0.0055
c14h22 0.0058
c15h24 0.0059
c16h26 0.0065
c17h28 0.0030
c18h30 0.0020
c10h8 0.0302
c11h10 0.0654
c12h12 0.0453
c13h14 0.0322
c14h16 0.0215
metanolreformeryanmaodasi
4
co2 1
h2o 2.1
n2 7.5238
o2 0.5
biogaz
5
h2 0.116
co 0.174
ch4 0.082
co2 0.131
n2 0.382
yanmahavasi
2
o2 2.463
n2 9.26557
Program 10.20 [Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
class GmixModel extends AbstractTableModel
{
Object[][] veri={
{"M : ","0","kg/kmol"},
{"h, enthalpy : ","0","KJ/kmol"},
{"u, Internal energy : ","0","KJ/kmol"},
{"s, Entropy : ","0","KJ/kmol K"},
{"v, Specific volume : ","0","m^3/kmol"},
{"k, Thermal conductivity : ","0","W/m K"},
{"h+hf, enthalpy+form. enth. : ","0","KJ/kmol"},
{"Density : ","0","kg/m^3"},
{"Cp : ","0"," KJ/kmol K"},
{"Cv : ","0","KJ/kmol K"},
{"Cp/Cv adiabatic constant : ","0"," "},
{"c speed of sound : ","0","m/s"},
{"Viscosity : ","0","N s/m^2"},
{"Pr,Prandtl Number : ","0"," "}};
String[] baslik={"Property ","Value ","Units"};
public GmixModel(Gmix g1,double TK,double P)
{
setValues(g1,TK,P);
}
public int getRowCount() {return [Link];}
public int getColumnCount() {return [Link];}
public Object getValueAt(int satir,int sutun) {return veri[satir][sutun];}
public String getColumnName(int c) {return baslik[c];}
public void setValueAt(Object val, int row, int col)
{
veri[row][col] = val;
}
public void setValues(Gmix g1,double T,double P)
{
double TK=T+273.0;
setValueAt((""+g1.M),0,1);
setValueAt([Link](g1.h(TK)),1,1);
setValueAt([Link](g1.u(TK)),2,1);
setValueAt([Link](g1.v(TK,P)),3,1);
setValueAt([Link](g1.s(TK,P)),4,1);
setValueAt([Link](g1.k(TK)),5,1);
setValueAt([Link]([Link](TK)),6,1);
setValueAt([Link](g1.M/g1.v(TK,P)),7,1);
setValueAt([Link]([Link](TK)),8,1);
setValueAt([Link]([Link](TK)),9,1);
setValueAt([Link]([Link](TK)),10,1);
setValueAt([Link](g1.c(TK)),11,1);
setValueAt([Link]([Link](TK)),12,1);
setValueAt([Link]([Link](TK)),13,1);
}
public boolean isCellEditable(int row, int col) {return false;}
}
Program 10.21 [Link]
// ======================================================
// Thermodynamics package in java
// GmixPropertySWF class to calculate properties of perfect
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// gas mixtures user interface (JFrame)
// Dr. Turhan Coban
// TUBITAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : [Link]@[Link]
// =====================================================
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import GmixModel;
public class GmixPropertySWF extends JFrame implements ActionListener,ItemListener
{
final static String MAIN = "Main Page";
final static String GASFORMULA = "Gas Formula";
JTabbedPane tabbedPane;
JPanel inputPanel;
JPanel outputPanel;
JPanel totalPanel;
JTextField promptGmixName; // Label prompt GmixName
JTextField promptTemperature; // Label prompt Temperature
JTextField promptPressure; // Label prompt Pressure
JComboBox inputGmixName; // input GmixName
JTextField inputTemperature; // input (from list )Temperature
JTextField inputPressure; // input Pressure
JTextArea outputTextArea;
JTextArea outputTextArea1;
GmixModel gm;
JTable jt;
double T;
double P;
String GmixName;
Gmix g1;
protected File gmixFile;
protected StringTokenizer token;
String st[];
final static Color bg=[Link];
final static Color fg=[Link];
final static Color kirmizi=[Link];
final static Color beyaz=[Link];
public GmixPropertySWF()
{
super("Properties of perfect gas mixtures ");
Container c=getContentPane();
[Link](new FlowLayout());
tabbedPane = new JTabbedPane();
//adding max-min prompts and input fields
GmixName=new String("air");
T=27.0;
P=1.0;
inputPanel=new JPanel();
[Link](new GridLayout(3,2));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
outputPanel=new JPanel();
[Link](new BorderLayout());
totalPanel=new JPanel();
[Link](new BorderLayout());
try{
g1=new Gmix(GmixName);
token=new StringTokenizer([Link]());
st=new String[[Link]()];
} catch(IOException ioe) {[Link]("IOException");}
int i=0;
while([Link]())
{
st[i++]=new String((String)[Link]());
}
inputGmixName=new JComboBox(st);
GmixName=(String)[Link]();
try{
g1=new Gmix(GmixName);
} catch(IOException ioe) {[Link]("IOException");}
promptGmixName= new JTextField(20);
[Link]("Simple Gmix Name : ");
[Link]([Link]);
promptTemperature=new JTextField(20);
[Link]("Temperature (°C) : ");
[Link]([Link]);
inputTemperature=new JTextField(20);
[Link]([Link]);
promptPressure= new JTextField(20);
[Link]("Pressure (Bars) : ");
[Link]([Link]);
outputTextArea = new JTextArea();
[Link]([Link]);
outputTextArea1 = new JTextArea();
[Link]([Link]);
inputPressure=new JTextField(20);
[Link]([Link]);
[Link](promptGmixName);
[Link](inputGmixName);
[Link](promptTemperature);
[Link](inputTemperature);
[Link](promptPressure);
[Link](inputPressure);
[Link](this);
[Link](this);
[Link](this);
gm=new GmixModel(g1,T,P);
jt=new JTable(gm);
[Link]([Link]());
setArea();
[Link](outputTextArea,[Link]);
[Link](jt,[Link]);
[Link](inputPanel,[Link]);
[Link](outputPanel,[Link]);
[Link](MAIN, totalPanel);
[Link](GASFORMULA, outputTextArea1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](tabbedPane);
}
public void setArea()
{
double TK=T+273.0;
[Link]([Link](T));
[Link]([Link](P));
String s="additional data can be added to [Link] file \n";
s+="Dr. Turhan Çoban, TUBÝTAK Marmara Research Center\n";
s+="Energy Systems & Environmental Research Institute\n";
s+="PO Box 21, Gebze - Kocaeli, Turkey\n";
s+="email: [Link]@[Link]";
//note if you would like to list additional information on the screen
//add to string s
String s1="";
s1+="Gas mixture formula :\n";
s1+="=========================\n"+[Link]("formula")+"\n";
s1+="Gas mixture composition :\n";
s1+="=========================\n"+[Link]("composition")+"\n";
[Link](g1,T,P);
[Link](s);
[Link](s1);
}
public void itemStateChanged(ItemEvent ev)
{
GmixName=(String)[Link]();
try{
g1=new Gmix(GmixName);
} catch(IOException ioe1) {[Link]("IOException");}
setArea();
repaint();
}
public void actionPerformed( ActionEvent e)
{
Double valTemp=new Double([Link]());
T=[Link]();
Double valPressure=new Double([Link]());
P=[Link]();
getContentPane().setLayout(new FlowLayout([Link]));
setArea();
repaint();
}
public static void main(String[] args)
{
GmixPropertySWF pencere= new GmixPropertySWF();
[Link](
new WindowAdapter()
{
public void windowClosing(WindowEvent e) {[Link](0);}
} );
[Link]();
[Link](true);
}
}
Veri çýktýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Burada hemen bir noktaya dikkat çekelim. Gerçek programlamalarda asýl veriyi iºleyen
sýnýflar ve insan grafik arayüzü programlarý genelde ayrý tutulur. Bu problem seti ayný
zamanda sýnýflarýn birbiri üzerine inºasýnýn da güzel bir örneðini teºkil etmektedir.
6. Bu problemde bir önceki problemde verilen uygulamanýn bir kademe daha ilerine
gideceðiz. Burada Gaz karýºýmlarýný bir borudan akýtacaðýz. Borunun basýnç düºümü ýsý
transferi gibi çeºitli özelliklerini bu program yardýmýyla deðerlendireceðiz. Borularýn özellikleri
[Link] dosyasýnda tanýmlanmýºtýr. Gaz karýºýmý için Boru basýnç düºümü ve ýsý transferini
hesaplayan programýmýzýn ismi [Link]’dýr.
Program 10.22 [Link]
//===================================================================
// Thermodynamic package in java
// File Name : [Link]
// Author : Turhan Coban
// TUBÝTAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : turhan@[Link]
// Description : This file contains the pipe class
// class pipe calculates pressure drops
// and internal heat transfer of pipes
// DATA FILE DEFINATION
// pipe datas are written in the data file "[Link]"
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// if gas data is not given in the data file, it can be curve fitted
// and added to the data file. Each data has the following form :
//------------------
// pipeName
// shape
// gasName
// d1 d2 (or only d1 depends on shape)
// mass_flow_rate
//-------------------
// a constructor is also available to define this data as passing values
//============================================================
// VARIABLE IDENTIFICATION
// all the variables that type is not defined is a double variable
// pipeName : String class variable for name
// shape : String class variable for shape of the cross-section
// options :
// circular
// rectangular
// concentric_annulus
// circular_segment
// circular_sector
// right_triangle
// gasName : String class variable for name of the gas mixtures
// g : gmix class variable
// mass_flow_rate : mass flow rate of gas mixture flowing
// through pipe, kg/s
// eps : pipe equivalent roughness m
// -------------------------------------------
// value of equivalent roughness for some pipes:
// Pipe equivalent rougness m
// ------------- ---------------------
// Riveted steel 0.9e-3 - 9e-3
// Concrete 0.3e-3 - 3e-3
// Wood stave 0.18e-3 - 0.9 e-3
// Cast iron 0.26e-3
// Galvanised iron 0.15e-3
// Commercial steel 0.045e-3
// wrought iron 0.045e-3
// drawn tubing 0.0015e-3
// Plastic,glass 0.0 (smooth)
// -------------------------------------------
// P : Pressure bar
// l : length m
// dh : hydraulic diameter m
// A : pipe area m^2
// KL : local pressure drop coefficient
//
//============================================================
import [Link].*;
import Text;
import Gmix;
class pipe{
protected double d1,d2; // m pipe dimensions
// actual meaning of d1 and d2
// can be change according to shape
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String pipeName;
public String shape; //pipe shape "circular","rectangular"...
public String gasName; //name of a gas mixture
public Gmix g;
public double mass_flow_rate; // kg/s
public double eps ; // m
public double P ; // Pressure bar
public double l ; // length
public double dh; // hydraulic diameter
public double A; // pipe area m^2
public double KL; //additional local pressure drop
// pipe functions
//=============================================
public static double tanh(double x)
{
//I couldnt find hyperbolic tangent in java
return ([Link](x)-[Link](-x))/([Link](x)+[Link](-x));
}
public static double f(double Re,double eod)
{
// friction factor for turbulent flow 5000<Re<10^8
double f1=[Link](eod/3.7+5.74/ [Link](Re,0.9))/[Link](19);;
f1=1.325/(f1*f1);
return f1;
}
public static double fx(double X,double Re,double eod)
{
// colebrook equation to solve
// friction factor for turbulent flow 2000 < Re
double xx=2.0*[Link](eod/3.7+2.51/Re*X)/[Link](10.0)+X;
return xx;
}
public static double dfx(double X,double Re,double eod)
{
//derivative of colebrook equation
double xx;
xx = 1+2.0/(eod/3.7+2.51/Re*X)/[Link](10.0)*2.51/Re;
return xx;
}
public static double fcol(double Re,double eod)
{
//solution of the colebrook equation
// by using newton method
double fi=f(Re,eod);
double x=1.0/ [Link](fi,0.5);
int nmax=50;
double tolerance=1.0e-10;
for(int i=0;i<nmax;i++)
{
double fx1=fx(x,Re,eod);
x-=fx1/dfx(x,Re,eod);
if([Link](fx1)<tolerance) return 1.0/(x*x);
}
return 1.0/(x*x);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//==============================================
// implementation of constructors functions
// for class pipe
public pipe(String name,double le)
{
//this function reads pipe configuration
//from file [Link]
l=le;
//beginning of try block
try{
BufferedReader cfin=new BufferedReader(new FileReader("[Link]"));
int ierror=1;
//************
try{
while(cfin!=null)
{
pipeName=[Link](cfin);
if([Link](name)) { ierror=0; break;}
} //end of while
} catch(EOFException e_eof)
{
[Link]("error required pipe "+name+" is not found");
[Link]();return;
}
//************
if(ierror==1)
{[Link]("error required pipe name cannot be found in the data file\n");return;}
shape=[Link](cfin);
gasName=[Link](cfin);
g=new Gmix(gasName);
if(g==null)
{
[Link]("gmix is not found\n");
}
double pi=4.0*[Link](1.0);
if([Link]("circular"))
{
d1=[Link](cfin);
d2=0.0;
A=pi*d1*d1/4;dh=d1;
}
else if([Link]("rectangular"))
{
d1=[Link](cfin);
d2=[Link](cfin);
A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if([Link]("concentric_annulus"))
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=[Link](d2-d1);
A=pi*dh*dh/4.0;
}
else if([Link]("circular_segment"))
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));
A=pi*dh*dh/4.0;
}
else if([Link]("circular_sector"))
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=d2/(1+d2)*d1;
A=pi*dh*dh/4.0;
}
else if([Link]("right_triangle"))
{
d1=[Link](cfin);
d2=[Link](cfin);;
dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
}
eps=0.03e-3;
mass_flow_rate=[Link](cfin);
P=1.0;;
KL=0.0;
//end of try block
}
catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
}
public pipe(String name)
{
//this function reads pipe configuration
//from file [Link]
l=1.0;
//beginning of try block
try{
BufferedReader cfin=new BufferedReader(new FileReader("[Link]"));
int ierror=1;
while(cfin!=null)
{
pipeName=[Link](cfin);
if([Link](name)) {ierror=0;break;}
}
if(ierror==1)
{[Link]("error required pipe name cannot be found in the data file\n");return;}
shape=[Link](cfin);
gasName=[Link](cfin);
g=new Gmix(gasName);
if(g==null)
{
[Link]("gmix is not found\n");
}
double pi=4.0*[Link](1.0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link]("circular"))
{
d1=[Link](cfin);
d2=0.0;
A=pi*d1*d1/4;dh=d1;
}
else if([Link]("rectangular"))
{
d1=[Link](cfin);
d2=[Link](cfin);
A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if([Link]("concentric_annulus"))
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=[Link](d2-d1);
A=pi*dh*dh/4.0;
}
else if([Link]("circular_segment"))
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));
A=pi*dh*dh/4.0;
}
else if([Link]("circular_sector"))
{
d1=[Link](cfin);
d2=[Link](cfin);
dh=d2/(1+d2)*d1;
A=pi*dh*dh/4.0;
}
else if([Link]("right_triangle"))
{
d1=[Link](cfin);
d2=[Link](cfin);;
dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
}
eps=0.03e-3;
mass_flow_rate=[Link](cfin);
P=1.0;;
KL=0.0;
//end of try block
}
catch(IOException e)
{
[Link]("Error Opening File \n"+[Link]());
[Link](1);
}
}
void change_d1(double dim1)
{
d1=dim1;
double pi=4.0*[Link](1.0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(shape=="circular")
{ A=pi*d1*d1/4;dh=d1;}
else if(shape=="rectangular")
{
A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if(shape=="concentric_annulus")
{dh=[Link](d2-d1);A=pi*dh*dh/4.0;}
else if([Link]("circular_segment"))
{dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));A=pi*dh*dh/4.0;}
else if(shape=="circular_sector")
{dh=d2/(1+d2)*d1; A=pi*dh*dh/4.0; }
else if(shape=="right_triangle")
{
dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
A=d1*d2/2.0;
}
}
void change_d2(double dim2)
{
d2=dim2;
double pi=4.0*[Link](1.0);
if(shape=="circular")
{ d2=0;A=pi*d1*d1/4;dh=d1;}
else if([Link]("rectangular"))
{
A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if([Link]("concentric_annulus"))
{dh=[Link](d2-d1);A=pi*dh*dh/4.0;}
else if([Link]("circular_segment"))
{dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));A=pi*dh*dh/4.0;}
else if([Link]("circular_sector"))
{dh=d2/(1+d2)*d1; A=pi*dh*dh/4.0; }
else if([Link]("right_triangle"))
{
dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
A=d1*d2/2.0;
}
}
pipe(String pn,
String sh,
String gn,
double dim1,
double dim2,
double m,double e,
double pp,
double k,
double length)
{
// direct assignment constructor
// this constructor can assign all
// the required values directly without
// going to the data file
pipeName=pn;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
l=length;
shape=sh;
try{
g=new Gmix(gn);
} catch(IOException ioe) {[Link]("IOException");}
double pi= 4.0*[Link](1.0);
d1=dim1;
d2=dim2;
if([Link]("circular"))
//d1 is diameter of the pipe
{ A=pi*d1*d1/4;dh=d1;d2=0;}
else if([Link]("rectangular"))
// d1 and d2 are two sides of the rectangle
{ A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if([Link]("concentric_annulus"))
// d1 and d2 are inrernal and external diameters
//of the concentric annulus
{ dh=[Link](d2-d1);A=pi*dh*dh/4.0;}
else if([Link]("circular_segment"))
// d1 is diameter and d2 is the angle of the circular segment
{ dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));A=pi*dh*dh/4.0;}
else if([Link]("circular_sector"))
//d1 is the diameter, d2 is the height of the circular section
{ dh=d2/(1+d2)*d1; A=pi*dh*dh/4.0; }
else if([Link]("right_triangle"))
// d1 and d2 two sides of right triangle
{
dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
A=d1*d2/2.0;
}
eps=e;
mass_flow_rate=m;
P=pp;
KL=k;
}
pipe(String pn,
String sh,
Gmix gmix1,
double dim1,
double dim2,
double m,
double e,
double pp,
double k,
double length)
{
// direct assignment constructor
// this constructor can assign all
// the required valued directly without
// going to the data file
pipeName=pn;
shape=sh;
//setup gas name
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
g=new Gmix(gmix1);
} catch(IOException ioe) {[Link]("IOException");}
double pi= 4.0*[Link](1.0);
d1=dim1;
d2=dim2;
l=length;
if([Link]("circular"))
//d1 is diameter of the pipe
{ A=pi*d1*d1/4;dh=d1;d2=0;}
else if([Link]("rectangular"))
// d1 and d2 are two sides of the rectangle
{ A=d1*d2;dh=4.0*d1*d2/(2.0*d1+2.0*d2);
}
else if([Link]("concentric_annulus"))
// d1 and d2 are inrernal and external diameters
//of the concentric annulus
{ dh=[Link](d2-d1);A=pi*dh*dh/4.0;}
else if([Link]("circular_segment"))
// d1 is diameter and d2 is the angle of the circular segment
{ dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));A=pi*dh*dh/4.0;}
else if([Link]("circular_sector"))
//d1 is the diameter, d2 is the height of the circular section
{ dh=d2/(1+d2)*d1; A=pi*dh*dh/4.0; }
else if([Link]("right_triangle"))
// d1 and d2 two sides of right triangle
{ dh=2.0*d1*[Link](d2)/(1.0+[Link](d2)+[Link](d2)); A=pi*dh*dh/4.0;}
eps=e;
mass_flow_rate=m;
P=pp;
KL=k;
}
void change_gas(String str1)
{
try{
g=new Gmix(str1);
}
catch(IOException ioe) {[Link]("IOException");}
}
void change_pipe(
String pn,
String sh,
String gn,
double dim1,
double dim2,
double e,
double m,
double pp,
double k)
{
// change assignment
// this constructor can assign all
// the required valued directly without
// going to the data file
pipeName=pn;
shape=sh;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try{
g=new Gmix(gn);
} catch(IOException ioe) {[Link]("IOException");}
double pi= 4.0*[Link](1.0);
d1=dim1;
d2=dim2;
if([Link]("circular"))
//d1 is diameter of the pipe
{ A=pi*d1*d1/4;dh=d1;}
else if([Link]("rectangular"))
// d1 and d2 are two sides of the rectangle
{ A=d1*d2;dh=2.0*d1*d2/(d1+d2);
}
else if([Link]("concentric_annulus"))
// d1 and d2 are inrernal and external diameters
//of the concentric annulus
{ dh=[Link](d2-d1);A=pi*dh*dh/4.0;}
else if([Link]("circular_segment"))
// d1 is diameter and d2 is the angle of the circular segment
{ dh=d1*(1+[Link](2.0*d2)/2.0/(pi-d2));A=pi*dh*dh/4.0;}
else if([Link]("circular_sector"))
//d1 is the diameter, d2 is the height of the circular section
{ dh=d2/(1+d2)*d1; A=pi*dh*dh/4.0; }
else if([Link]("right_triangle"))
// d1 and d2 two sides of right triangle
{ dh=4.0*d1*d2/(d1+d2+ [Link]((d1*d1+d2*d2),0.5));
A=d1*d2/2.0;
}
eps=e;
mass_flow_rate=m;
P=pp;
KL=k;
}
public double get_d1()
//getting the first dimension
{
return d1;
}
public double get_d2()
//getting the first dimension
{
return d2;
}
public double velocity(double t)
{
// velocity of the pipe m/x
double d =g.M/g.v(t,P);
return (double)(mass_flow_rate/d/A);
}
public double Re(double t)
{
// reynold's number
double d=g.M/g.v(t,1.0);
double vis=[Link](t);
double vv=velocity(t);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double res=(dh*vv*d/vis);
return res;
}
public double f(double t)
{
// this function calculated friction coefficient
// for both laminar and turnulent flow for various
// cross sections
double Rey=Re(t); //Reynold's number
double C=64;
if(Rey<2000)
{
String c = "circular";
String r = "rectangular";
String co_an = "concentric_annulus";
String cir_seg = "circular_segment";
String cir_sec = "circular_sector";
String rig_tri;
rig_tri=new String("right_triangle");
if([Link](c))
//circular cross section, laminar flow
{ C=64.0; }
else if([Link](r))
{
// Laminar rectangular channel friction factor
double x=d1/d2;
if(x>1) x=1/x;
double a1[];
a1=new double[6];
a1[0]= .959923253176985E+02;
a1[1]= -.130364643234979E+03;
a1[2]= .188053177394400E+03;
a1[3]= -.166159826967448E+03 ;
a1[4]= .952739160606451E+02;
a1[5]= -.258949934514987E+02 ;
C=a1[5];
for(int i=4;i>=0;i--) { C=C*x+a1[i];}
}
else if([Link](co_an))
{
//concentric annulus laminar friction factor
double x=d2/d2;
if(x>1) x=1/x;
double a1[];
a1=new double[5];
a1[0]= .717068909524062E+02;
a1[1]= .932037998655195E+03;
a1[2]= -.947586946520906E+04;
a1[3]= .204346570871727E+05;
a1[4]= -.118665325115712E+05;
C=a1[4];
for(int i=4;i>=0;i--) {C=C*x+a1[i];}
}
else if([Link](cir_seg))
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//circular segment laminar friction factor
double a1[];
a1=new double[5];
a1[0]= .639999999999997E+02;
a1[1]= -.162338014624008E+01;
a1[2]= .162620455430327E+01;
a1[3]= -.827251633703104E+00 ;
a1[4]= .138590724447624E+00;
C=a1[4];
for(int i=3;i>=0;i--) {C=C*d2+a1[i];}
}
else if([Link](cir_sec))
{
//circular section laminar friction factor
double a1[];
a1=new double[4];
a1[0]= .480000000000000E+02;
a1[1]= .227909935649730E+02;
a1[2]= -.134959915493607E+02;
a1[3]= .325095868081599E+01;
C=a1[3];
for(int i=2;i>=0;i--) {C=C*d2+a1[i];}
}
else if([Link](rig_tri))
{
//right triangle laminar friction factor
double a1[];
a1=new double[5];
a1[0]= .480001792918036E+02;
a1[1]= .127207559700323E+02;
a1[2]= -.108590518340935E+02;
a1[4]= .158423382029386E+01;
a1[5]= .115425033696128E+01;
C=a1[5];
for(int i=4;i>=0;i--) {C=C*d2+a1[i];}
}
return C/Rey;
}
else
{
double eod=eps/dh;
double fc=fcol(Rey,eod);
return fc;
}
}
public double lentry(double t)
{
//hydraulic entry length
double Rey=Re(t);
double le;
if(Rey<2000) le=0.06*dh*Rey;
else le=4.4*dh* [Link](Rey,(1.0/6.0));
return le;
}
public double dP(double t,double P)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
// pipe pressure drop for the given length plus
// local KL factors
double V=velocity(t);
return (KL+f(t)*l/dh)*(g.M/g.v(t,P))*V*V/2.0*1e-5;
}
public double dP(double t)
{
double P=1;
// pipe pressure drop for the given length plus
// local KL factors
double V=velocity(t);
return (KL+f(t)*l/dh)*(g.M/g.v(t,P))*V*V/2.0*1e-5;
}
public double dPl_e(double t,double P)
{
double Q=mass_flow_rate*g.v(t,P)/g.M;
double a=d1/2.0;
double b=d2/2.0;
double x=0;
double pi=4.0*[Link](1.0);
for(int i=1;i<8000;i+=2)
{
x+=tanh(pi*b*i/d1)/(double)(i*i*i*i*i);
}
x=1.0-192.0*a/(pi*pi*pi*pi*pi*b)*x;
double xx=b*a*a*a/(6.0*[Link](t))*x;
xx=Q/xx*l*1e-5;
return xx;
}
void change_length(double l1)
{ l=l1; }
void change_mass_flow_rate(double mfr)
{ mass_flow_rate=mfr; }
void change_P(double Pin)
//change inlet pressure
{ P=Pin; }
void change_KL(double klin)
//change local pressure drop coefficient
{KL=klin; }
void change_e(double e)
{ eps=e; }
public double hc(double t)
{
//convective heat transfer coefficient
double Rey=Re(t);
double Nu=0;
if(Rey<2000)
{
if([Link]("circular"))
{ Nu=3.66; }
else if([Link]("rectangular"))
{
// Laminar rectangular channel friction factor
double x=d1/d2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(x>1) x=1/x;
double a1[];
a1=new double[7];
a1[0]= .754000000000580E+01;
a1[1]= -.193789080028494E+02;
a1[2]= .333861212302836E+02;
a1[3]= -.170496495070800E+02 ;
a1[4]= -.304226226912837E+02;
a1[5]= .495297442580787E+02;
a1[6]= -.206246852871550E+02;
Nu=a1[6];
for(int i=5;i>=0;i--) {Nu=Nu*x+a1[i];}
}
else if([Link]("concentric_annulus"))
{
double x=d2/d2;
if(x>1) x=1/x;
double a1[];
a1=new double[4];
a1[0]= .401698044199492E+01;
a1[1]= .921803331830132E+00;
a1[2]= -.307845192109755E+00;
a1[3]= .229092480046921E+00;
Nu=a1[3];
for(int i=2;i>=0;i--) {Nu=Nu*x+a1[i];}
}
else if([Link]("circular_segment"))
{
Nu=3.66;
}
else if([Link]("circular_sector"))
{
Nu=3.66;
}
else if([Link]("right_triangle"))
{
Nu=2.47;
}
}
else
{
double fr = f(t);
Rey = Re(t);
double Prt = [Link](t);
// Gnielinski equation
// Gnielinski, V, Int. Chem Eng., 16, 359,1976
// Valid for 2000 < Re <5e5, 0.5 < Pr < 2000
Nu=fr/8.0*(Rey-1000.0)*Prt/
(1+12.7* [Link](fr/8.0)*( [Link](Prt,(2.0/3.0))-1.0));
}
double kt = g.k(t);
// double Prt = [Link](t);
double result;
result=Nu*kt/dh;
return result;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public double Nu(double t)
//Nusselt's Number
{
return hc(t)*dh/g.k(t);
}
} //end of class pipe
Program veri dosyasý [Link] (sadece birkaç örnek durum listelenmiºtir.)
example
circular
air
0.1
0.11
p18_natural
circular
natural
18e-3
1.0589996e-4
p18_air
circular
air
18e-3
4.244105e-3
pipe_6
rectangular
prereformer_output
30e-3 1.6e-3
8.727136e-4
veri dosyasý boru ismi, boru ºekli(circular, rectangular..), gazkarýºýmýnýn adý([Link]
dosyasýnda tanýmlanmýº olmalýdýr), boru çapý veya boru en ve boyu ve akýº debisi(kg/s)
bilgilerini içerir. Bu programýn kullanýldýðý çýktý veren bir insan arayüzü programýna göz atalým
:
Program 10.23 [Link]
//======================================================
// Thermodynamics package in java
// pipeProperty class to calculate pipe
// user interface (applet)
// Dr. Turhan Coban
// =====================================================
import pipe;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
public class pipeProperty extends Applet implements ActionListener,ItemListener
{
protected Panel inputPanel;
protected Label promptGmixName; // Label prompt GmixName
protected Label promptTemperature; // Label prompt Temperature
protected Label promptPressure; // Label prompt Pressure
protected Label promptPipeLength; // Label prompt Pipe Length
protected Label promptShape; // Label prompt cross-section shape
protected Label promptD1; // Label prompt first dimension
protected Label promptD2; // Label prompt second dimension
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
protected Label promptKL; // LP local PD coefficient
protected Label promptMass; // LP mass flow rate
protected Label prompte; // LP pipe equivalent roughness
protected Choice inputGmixName; // input GmixName
protected TextField inputTemperature; // input Temperature
protected TextField inputPressure; // input Pressure
protected TextField inputPipeLength; // input pipe length
protected Choice inputShape;
protected String pipeShapeArray[]={"circular","rectangular",
"concentric_annulus","circular_segment","circular_sector","right_triangle"};
protected TextField inputD1;
protected TextField inputD2;
protected TextField inputKL;
protected TextField inputMass;
protected TextField inpute;
double T;
double P;
double TK;
double pipeLength;
String pipeShape;
double D1,D2;
String GmixName;
String pipeName;
double mass_flow_rate;
Gmix g1;
pipe p1;
double KL;
double e;
StringTokenizer token;
public void init()
{
//adding max-min prompts and input fields
inputPanel=new Panel();
[Link](new GridLayout(10,2));
GmixName=new String("natural");
try{
g1=new Gmix(GmixName);
token=new StringTokenizer([Link]());
} catch(IOException ioe) {[Link]("IOException");}
pipeName=new String("P18_natural");
T=27.0;
TK=T+273;
P=1.0;
pipeLength=1.0;
KL=0.0;
D1=0.005;
D2=0.005;
e=0.00001;
mass_flow_rate=0.01;
pipeShape =new String("circular");
promptGmixName= new Label(" Gas mixture Name : ");
inputGmixName=new Choice();
while([Link]())
{
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
//inputGmixName=new TextField(15);
promptTemperature= new Label(" Temperature (øC) : ");
inputTemperature=new TextField(15);
promptPressure= new Label(" Pressure (Bars) : ");
inputPressure=new TextField(15);
promptPipeLength= new Label(" Pipe Length, m : ");
inputPipeLength=new TextField(15);
promptShape= new Label(" Pipe Shape : ");
inputShape=new Choice();
for(int i=0;i<5;i++)
{
[Link](pipeShapeArray[i]);
}
promptD1= new Label(" Pipe Dimension D1, m : ");
inputD1= new TextField(15);
promptD2= new Label(" Pipe Dimension D2, m : ");
inputD2= new TextField(15);
promptKL= new Label(" Pipe Local PD coefficient, : ");
inputKL= new TextField(15);
promptMass= new Label(" mass flow rate , kg/s : ");
inputMass= new TextField(15);
prompte= new Label(" Pipe equivalent roughness, m: ");
inpute= new TextField(15);
//********
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
//********
[Link](promptGmixName);
[Link](inputGmixName);
[Link](promptTemperature);
[Link](inputTemperature);
[Link](promptPressure);
[Link](inputPressure);
[Link](promptPipeLength);
[Link](inputPipeLength);
[Link](promptShape);
[Link](inputShape);
[Link](promptD1);
[Link](inputD1);
[Link](promptD2);
[Link](inputD2);
[Link](promptKL);
[Link](inputKL);
[Link](promptMass);
[Link](inputMass);
[Link](prompte);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](inpute);
[Link]([Link](T));
[Link]([Link](P));
[Link]([Link](pipeLength));
[Link]([Link](D1));
[Link]([Link](D2));
[Link]([Link](KL));
[Link]([Link](mass_flow_rate));
[Link]([Link](e));
//[Link](GmixName);
[Link]([Link](D1));
[Link]([Link](D2));
[Link](false);
[Link]([Link](KL));
[Link]([Link](mass_flow_rate));
[Link]([Link](e));
setLayout(new BorderLayout());
add( inputPanel,[Link]);
p1= new pipe(pipeName,
pipeShape,
GmixName,
D1,
D2,
mass_flow_rate,
e,
P,
KL,
pipeLength);
}
public void itemStateChanged(ItemEvent ev)
{
//pipeShape=pipeShapeArray[[Link]()];
pipeShape=[Link]();
if([Link]("circular"))
{
[Link](false);
}
else
{
[Link](true);
}
GmixName=[Link]();
p1= new pipe(pipeName,
pipeShape,
GmixName,
D1,
D2,
mass_flow_rate,
e,
P,
KL,
pipeLength);
repaint();
showStatus(pipeShape);
}//end of itemStateChange
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paint(Graphics g)
{
TK=T+273;
[Link]("Pressure Drop , bars : ",20,250);
[Link](""+[Link](TK,P),250,250);
[Link]("f friction : ",20,265);
[Link](""+p1.f(TK),250,265);
[Link]("Velocity , m/s : ",20,280);
[Link](""+[Link](T),250,280);
[Link]("Reynold's number Re : ",20,295);
[Link](""+[Link](TK),250,295);
[Link]("Prandl's number Pr : ",20,310);
[Link](""+[Link](TK),250,2310);
[Link]("Nusselt's number Nu : ",20,325);
[Link](""+[Link](TK),250,325);
[Link]("Hydraulic entry length, m : ",20,340);
[Link](""+[Link](TK),250,340);
[Link]("Viscosity , N s/m^2 : ",20,355);
[Link](""+[Link](TK),250,355);
[Link]([Link]("formula"),20,370);
[Link]([Link]("composition"),20,385);
[Link]("shape : "+pipeShape,20,400);
}//end of method
public void actionPerformed( ActionEvent ee)
{
GmixName=[Link]();
Double valTemp=new Double([Link]());
T=[Link]();
Double valPressure=new Double([Link]());
P=[Link]();
Double valpipeLength=new Double([Link]());
pipeLength=[Link]();
Double valD1=new Double([Link]());
D1=[Link]();
Double valD2=new Double([Link]());
D2=[Link]();
Double valKL=new Double([Link]());
KL=[Link]();
Double valMass=new Double([Link]());
mass_flow_rate=[Link]();
Double valuee=new Double([Link]());
e=[Link]();
p1= new pipe(pipeName,
pipeShape,
GmixName,
D1,
D2,
mass_flow_rate,
e,
P,
KL,
pipeLength);
repaint();
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Appletviewer olarak program çýktýsý:
7. Thermodinamik özellikler serisinden bir adým daha ileri gidip gazlarý kimyasal
reaksiyonlara sokabiliriz. Bu sýnýfýmýz [Link] ismini taºýyor. Gazlarýn termodinamik
reaksiyona girdiklerinde enerji dengelerini,adyabatik alev sýcaklýklarýný ve reaksiyon
sabitlerini (k) hesaplama kapasitesinde bir program. Program veridosyasý [Link]
adýnda. Bu dosyada reaksiyonun ismi, toplam gaz sayýsý, bu gazýn reaksiyona giren ve
reaksiyondan çýkan moleküllerinin sayýsý liste olarak veriliyor. Reaksiyon kütle denklik hesabý
program tarafýndan yapýlmamaktadýr. Doðru molekül sayýlarýnýn verilmesi kullanýcýya
býrakýlmýºtýr.
Bu dosyadan birkaç örnek veri setine göz atalým:
hidrojen
3
h2o 1 0
h2 0 1
o2 0 0.5
c2h4comb
5
c2h4 1 0
o2 3 0
n2 11.28 11.28
co2 0 2
h2o 0 2
LPG
6
c3h8 0.3 0
c4h10 0.7 0
o2 6.05 0
n2 22.7595 22.7595
co2 0 3.7
h2o 0 4.7
dogal_1.05
8
ch4 0.906 0
c2h6 0.056 0
c3h8 8e-4 0
c4h10 2e-4 0
co2 0.018 0
n2 8.116375 8.116375
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
o2 2.155125 0.102625
h2o 0 2.017
dogal_1.1
8
ch4 0.906 0
c2h6 0.056 0
c3h8 8e-4 0
c4h10 2e-4 0
co2 0.018 0
n2 8.5024405 8.5024405
o2 2.27575 0.20525
h2o 0 2.017
Programýmýzýn listesi:
Program 10.24 [Link]
import [Link].*;
import [Link].*;
import Text;
class Reaction
{
//======================================================//
// Dr. Turhan Coban //
// TUBITAK Marmara Research Center //
// Energy Systems and Environmental Research Institute //
// Phone : 90 (262) 641 2300-3917 //
// email : turhan@[Link] //
//======================================================//
// Class Description :
//------------------------------------------------------
// This program calculates energy, adiabatic flame temperature
// entropy and gibbs free energy for a given reaction
// Basic reaction data is given in the file called [Link]
// Format of the data :
// reactionname
// number_of_the_chemicals
// gas_name reactant_mole prodoct_mole
// .......
// gas_name reactant_mole prodoct_mole
//-----------------
// sample data :
//-----------------
// c2h6combustion
// 5
// c2h6 1 0
// o2 3 0
// n2 11.28 11.28
// co2 0 2
// h2o 0 2
//------------------
// the available gas_name's can be checked from data file
// [Link]
// Variable Identification
//-----------------------------------------------------
// ngas : number of gases in reaction (integer variable)
// reacname : reaction name (String variable)
// gasR,gasP: gas objects for reactants and products
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// (array objects of class Gas)
// see [Link] for details
// natom : number of atoms in the reaction
// nr,np : number of Moles of reactants and products
// (double vector array)
// nrt,npt : total number of moles for reactants and products
// reacFile : reaction file channel variable (Class File)
// atomList : list of the atoms in the reaction
public int ngas;
String reacName;
Gas gasR[],gasP[];
public int natom;
Atom atomList[];
File reacFile;
double nr[],np[];
double nrt,npt;
public Reaction(String name) throws IOException
{
reacFile=new File("[Link]");
reacFile=new File([Link]());
try
{
DataInputStream cfin=new DataInputStream(new FileInputStream(reacFile));
int ierror=1;
natom=0;
try
{
while(cfin!=null)
{
reacName=[Link](cfin);
if([Link](name)) {ierror=0;break;}
}
}
catch(EOFException e_eof)
{
[Link]("error required gas mixture "+name+" is not found");
[Link]();return;
}
ngas=[Link](cfin);
gasR=new Gas[ngas];
gasP=new Gas[ngas];
nr=new double[ngas];
np=new double[ngas];
nrt=0;
npt=0;
String tempGasName;
Double n1,n2;
for(int i=0;i<ngas;i++)
{
tempGasName=[Link](cfin);
nr[i]=[Link](cfin);
np[i]=[Link](cfin);
nrt+=nr[i];
npt+=np[i];
gasR[i]=new Gas(tempGasName,nr[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
gasP[i]=new Gas(tempGasName,np[i]);
}
}
catch(FileNotFoundException fnfe) {[Link]("File Not Found");}
arrange_atoms();
} //end of constructor
public void arrange_atoms() throws IOException
{
// atomic structure of the reactants
int i,j;
for(i=0;i<ngas;i++)
{
for(j=0;j<gasR[i].natom;j++)
{
add_atom(i,j);
}
}
}
public int add_atom(int i,int j) throws IOException
{
//determine and order the atomic structure
int k;
for(k=0;k<natom;k++)
{
if(gasR[i].atomList[j].[Link](atomList[k].symbol))
{
atomList[k]=new Atom(atomList[k].symbol,atomList[k].N+gasR[i].atomList[j].N*gasR[i].N);
return 1;
}
}
Atom atomL[];
atomL=new Atom[natom+1];
for(k=0;k<natom;k++)
atomL[k]=new Atom(atomList[k]);
atomL[natom]=new Atom(gasR[i].atomList[j].symbol,gasR[i].atomList[j].N*gasR[i].N);
atomList=atomL;
natom+=1;
return 2;
}
public String toString()
{
// writes chemical reaction in chemistry norm
String s="";
for(int i=0;i<ngas;i++)
{
if(nr[i]==1)
{ s+=gasR[i].toString(); }
else if(nr[i]!=0)
{ s+=nr[i]+" "+gasR[i].toString(); }
if(i!=(ngas-1) && nr[i]!=0 ) s+=" + ";
}
if([Link](" + "))
s=[Link](0,[Link]()-3);
s+=" --> ";
for(int i=0;i<ngas;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
if(np[i]==1)
{ s+=gasP[i].toString(); }
else if(np[i]!=0)
{ s+=np[i]+" "+gasP[i].toString(); }
if(i!=(ngas-1) && np[i]!=0 ) s+=" + ";
}
if([Link](" + "))
s=[Link](0,[Link]()-3);
return s;
}
public String toString(String ch)
{
//return the c
String s="";
int i,j;
if([Link]("name"))
s=s+reacName+"\n";
else if([Link]("formula"))
{
s=toString();
}
else if([Link]("composition"))
{
for(i=0;i<natom;i++)
s=s+atomList[i].toString()+" ";
}
return s;
}
public double H(double TR,double TP)
{
//reaction enthalpy
double HH=0;
for(int i=0;i<ngas;i++)
{
HH+=gasP[i].HT(TP);
HH-=gasR[i].HT(TR);
}
return HH;
}
public double S(double TR,double TP,double pt)
{
//reaction entropy
double SS=0;
for(int i=0;i<ngas;i++)
{
if(np[i]!=0)
SS+=gasP[i].S(TP,np[i]/npt*pt);
if(nr[i]!=0)
SS-=gasR[i].S(TR,nr[i]/nrt*pt);
}
return SS;
}
public double S(double TR,double TP)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//reaction entropy
double SS=0;
for(int i=0;i<ngas;i++)
{
if(np[i]!=0)
SS+=gasP[i].S(TP,np[i]/npt);
if(nr[i]!=0)
SS-=gasR[i].S(TR,nr[i]/nrt);
}
return SS;
}
public double G(double TR,double TP,double pt)
{
// reaction gibbs energy
double GG=0;
for(int i=0;i<ngas;i++)
{
if(np[i]!=0)
GG+=gasP[i].GT(TP,np[i]/npt*pt);
if(nr[i]!=0)
GG-=gasR[i].GT(TR,nr[i]/nrt*pt);
}
return GG;
}
public double G(double TR,double TP)
{
// reaction gibbs energy
double GG=0;
for(int i=0;i<ngas;i++)
{
if(np[i]!=0)
GG+=gasP[i].GT(TP,np[i]/npt);
if(nr[i]!=0)
GG-=gasR[i].GT(TR,nr[i]/nrt);
}
return GG;
}
public double G0(double TR,double TP)
{
// reaction gibbs free energy
double GG=0;
for(int i=0;i<ngas;i++)
{
if(np[i]!=0)
GG+=gasP[i].GT(TP);
if(nr[i]!=0)
GG-=gasR[i].GT(TR);
}
return GG;
}
public double K(double TR,double TP)
{
//Equilibrium costant. Usually TR and Tp will be in
// thesame temperature
return [Link](G0(TR,TP)/(-8.3145*TP));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
public double Taf(double TR,double xl,double xu)
{
// Adyabatic flame temperature using Bisection method
// bisection method to find roots of zero energy change
// Q=0
// defination of variables :
// xl : lower guess
// xu : upper guess
// xr : root estimate
// es : stopping criterion
// ea :approximate error
// maxit : maximum iterations
// iter : number of iteration
double test;
double xr=0;
double es,ea;
double fxl,fxr;
int maxit=500,iter=0;
es=0.000001;
ea=1.1*es;
while((ea>es)&&(iter<maxit))
{
xr=(xl+xu)/2.0;
iter++;
if((xl+xu)!=0)
{ ea=[Link]((xu-xl)/(xl+xu))*100;}
fxl= H(TR,xl);
fxr= H(TR,xr);
test= fxl*fxr;
if(test==0.0) ea=0;
else if(test<0.0) xu=xr;
else
{
xl=xr;
}
} //end of while
return xr;
}
}
programýmýzý bir örnekte test edelim.
Program 10.25 [Link]
import [Link].*;
import Reaction;
class ReactionTest
{
public static void main(String args[]) throws IOException
{
Reaction R2;
R2=new Reaction("hid");
[Link]([Link]("name"));
[Link]([Link]("formula"));
[Link]([Link]("composition"));
double Tadyabatikalev= [Link](299,299, 3000)-273;
[Link]("T adyabatik alev = "+Tadyabatikalev+" derece C");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
program çýktýsý :
hid
0.17 H2 + 1.72 O2 + 6.47 N2 --> 1.635 O2 + 6.47 N2 + 0.17 H2O
H0.34 O3.44 N12.94
T adyabatik alev = 194.51268483046442 derece C
8. Termodinamik serisinden bir diðer program. Bu program gerçek gazlarýn termodinamik
özelliklerini hesaplýyor. Programýn ismi [Link], veri dosyasý [Link]
Program Listesi :
//======================================================
// Thermodynamic Package in java
// Class Lee Kesler Properties of real gases
// Dr. Turhan Coban
// TUBÝTAK Marmara Research Center
// Energy Systems and Environmental Research Institute
// email : turhan@[Link]
// File Name : [Link]
// This file contains the LeeKesler class
// this class sets basic properties of real gases
// required data is read from [Link]
// =====================================================
// Description : This file contains the LeeKesler class
// class LeeKesler calculates thermophysical properties of
// perfect gasses
// DATA FILE DEFINATION
// datas are written in the data file "[Link]"
//============================================================
// VARIABLE IDENTIFICATION
//============================================================
// GasEquation : String type variable
// values : "LeeKesler"
//
//
// Formula : Fluid chemical formula
// Name : Fluid name
// atomList : Array of atom class, structral information
// natom : number of atoms
// M : Molecular weight as calculated from atomic structure
// through class atom and atomList
// MolWt : Molecular Weigth from data file RealGas
// Tfp : Normal freezing point (1 atm), K
// Tb : Normal Boiling point (1 atm), K
// Tc : Critical temperature, K
// Pc : Critical pressure, bar
// Vc : Critical volume, cm^3/mole
// Zc : Critical compresibility factor PcVc/RTc
// Omega : Pitzer's accentric factor
// Dipm : Dipole moment, debyes
// CPVAPA,CPVAPB,CPVAPC,CPVAPD : constants to calculate the
// isobaric heat capacity of the ideal gas Cp kJ/(kmolK)
// DELHF : formation enthalpy, 298.2 K, 1.01325 bar, KJ/kmol
// DELGF : formation gibbs free energy, 298.2 K, 1.01325 bar,KJ/kmol
// Vpeq : vapor pressure equation number
// VPA,VPB,VPC,VPD : vapor pressure equation coefficients
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Tmin : minimum twmp. K
// Tmax : maximum temp. K
// LDEN : liquid density, g/cm^3
// TDEN : temperature that liquid density is given, K
//============================================================
// Reference : The Properties of Gases & Liquids,
// Robert C. Reid, John M. Prausnitz, Bruce E. Pouling
// McGraw-Hill Book Company, ISBN 0-07-051799-1
//==============================================
import [Link].*;
import Text;
import Atom;
import complex;
//==============================================
// implementation of constructors functions
// for class cubicEquationofState
public class LeeKesler
{
String GasEquation;
int natom;
Atom atomList[];
int No;
String Formula,Name;
double M,MolWt,Tfp,Tb,Tc,Pc,Vc,Zc,Omega,Dipm;
double CPVAPA,CPVAPB,CPVAPC,CPVAPD,DELHF,DELGF;
int VPEq;
double VPA,VPB,VPC,VPD,Tmin,Tmax,LDEN,TDEN;
int ierror;
BufferedReader fin;
double R=8314.5; //(J/kmolK)
double a,b,u,w;
//000000
//================================//
// Equation of State coefficients //
//================================//
//Simple Fluid (omega=0) :
//------------------------
double b0[]=new double[4];
double c0[]=new double[4];
double d0[]=new double[2];
double beta0;
double gama0;
double omega0;
//Reference Fluid (n-octane) :
//------------------------
double bR[]=new double[5];
double cR[]=new double[5];
double dR[]=new double[3];
double betaR;
double gamaR;
public LeeKesler(String s1,double le) throws IOException
{
GasEquation="Peng Robinson";
//setting the simple fluid coefficients :
b0[0]=0.1181193;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
b0[1]=0.265728;
b0[2]=0.15479;
b0[3]=0.030323;
c0[0]=0.0236744;
c0[1]=0.0186984;
c0[2]=0.0;
c0[3]=0.042724;
d0[0]=0.155488e-4;
d0[1]=0.623689e-4;
beta0=0.65392;
gama0=0.060167;
omega0=0.3978;
//setting the reference fluid coefficients :
bR[0]=0.2026579;
bR[1]=0.331511;
bR[2]=0.027655;
bR[3]=0.203488;
cR[0]=0.0313385;
cR[1]=0.0503618;
cR[2]=0.016901;
cR[3]=0.041577;
dR[0]=0.48736e-4;
dR[1]=0.0740336e-4;
betaR=1.226;
gamaR=0.03754;
int i;
String atomName[];
double atomN[];
int anatom;
ierror=1;
String tempName="";
String tempFormula="";
String aFormula,aName;
double aMolWt,aTfp,aTb,aTc,aPc,aVc,aZc,aOmega,aDipm ;
double aCPVAPA,aCPVAPB,aCPVAPC,aCPVAPD,aDELHF,aDELGF;
int aVPEq;
double aVPA,aVPB,aVPC,aVPD,aTmin,aTmax,aLDEN,aTDEN ;
try{
fin=new BufferedReader(new FileReader("[Link]"));
} catch(IOException e)
{
[Link]("Error Opening File [Link]\n"+[Link]());
[Link](1);
}
try{
while(fin!=null)
{
aFormula=[Link](fin);
aName=[Link](fin);
anatom=[Link](fin);
atomName=new String[anatom];
atomN=new double[anatom];
for(i=0;i<anatom;i++)
{
atomName[i]=[Link](fin);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
atomN[i]=[Link](fin);
}
aMolWt=[Link](fin);
aTfp=[Link](fin);
aTb=[Link](fin);
aTc=[Link](fin);
aPc=[Link](fin);
aVc=[Link](fin);
aZc=[Link](fin);
aOmega=[Link](fin);
aDipm=[Link](fin);
aCPVAPA=[Link](fin);
aCPVAPB=[Link](fin);
aCPVAPC=[Link](fin);
aCPVAPD=[Link](fin);
aDELHF=[Link](fin);
aDELGF=[Link](fin);
aVPEq=[Link](fin);
aVPA=[Link](fin);
aVPB=[Link](fin);
aVPC=[Link](fin);
aVPD=[Link](fin);
aTmin=[Link](fin);
aTmax=[Link](fin);
aLDEN=[Link](fin);
aTDEN=[Link](fin);
if ([Link](s1) || [Link](s1) )
{
Name=aName;
Formula=aFormula;
MolWt=aMolWt;
Tfp=aTfp;
Tb=aTb;
Tc=aTc;
Pc=aPc;
Vc=aVc;
Zc=aZc;
Omega=aOmega;
Dipm=aDipm;
CPVAPA=aCPVAPA;
CPVAPB=aCPVAPB;
CPVAPC=aCPVAPC;
CPVAPD=aCPVAPD;
DELHF=aDELHF;
DELGF=aDELGF;
VPEq=aVPEq;
VPA=aVPA;
VPB=aVPB;
VPC=aVPC;
VPD=aVPD;
Tmin=aTmin;
Tmax=aTmax;
LDEN=aLDEN;
TDEN=aTDEN;
natom=anatom;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
atomList=new Atom[natom];
M=0;
for(i=0;i<natom;i++)
{
atomList[i]=new Atom(atomName[i],atomN[i]);
M+=atomList[i].mass;
}
ierror=0;
break;
}
}
} catch(EOFException e_eof)
{
[Link]("error required gas "+s1+" is not found");
[Link]();return;
}
[Link]();
}
public String toString()
{
//return the chemical symbol of the gas
String s="";
for(int i=0;i<natom;i++)
s=s+atomList[i].toString();
return s;
}
public double Z(double T, double V)
{
double Tr=T/Tc;
double Vr=V/Vc;
double B0,C0,D0;
double BR,CR,DR;
double Z0,ZR,ZX;
B0=b0[0]-b0[1]/Tr-b0[2]/(Tr*Tr)-b0[3]/(Tr*Tr*Tr);
C0=c0[0]-c0[1]/Tr+c0[2]/(Tr*Tr*Tr);
D0=d0[0]+d0[1]/Tr;
Z0=1+B0/Vr+C0/(Vr*Vr)+D0/(Vr*Vr*Vr*Vr*Vr)
+ c0[3]/(Tr*Tr*Tr*Vr*Vr)*(beta0+gama0/(Vr*Vr))*[Link](-gama0/(Vr*Vr));
BR=bR[0]-bR[1]/Tr-bR[2]/(Tr*Tr)-bR[3]/(Tr*Tr*Tr);
CR=cR[0]-cR[1]/Tr+cR[2]/(Tr*Tr*Tr);
DR=dR[0]+dR[1]/Tr;
ZR=1+BR/Vr+CR/(Vr*Vr)+DR/(Vr*Vr*Vr*Vr*Vr)
+ cR[3]/(Tr*Tr*Tr*Vr*Vr)*(betaR+gamaR/(Vr*Vr))*[Link](-gamaR/(Vr*Vr));
ZX=Z0+Omega/0.3978*(ZR-Z0);
return ZX;
}
double P(double T, double V)
{
double Tr=T/Tc;
double Vr=V/Vc;
return Z(T,V)*Tr/Vr;
}
/*
public double V(double T, double P)
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return Z(T,P)*R*T/(P*1e5);
}
public double Pvp(double T)
{
switch ( VPEq)
double cPvp;
case 1:
{
cPvp=Pc*[Link]((VPA*x+VPB*[Link](x,1.5)+VPC*x*x*x+VPD*x*x*x*x*x*x)/(1-x));
break;
}
case 2:
{
cPvp=VPA-VPB/T+VPC*[Link](T)+VPD
break;
}
case 3:
{
break;
}
return cPvp;
}
*/
}
Programýn veri dosyasýndan bazý gazlarýn özelliklerini örnek olarak verirsek:
H2 Hydrogen
1
H2
2.016 14 20.3 33 12.9 64.3 0.303 -0.216 0
27.14 9.274e-3 -1.381e-5 7.645e-9 0 0
1 -5.57929 2.60012 -0.85506 1.70503 14 33 0.071 20
H2O Water
2
H2
O1
18.015 273.2 373.2 647.3 221.2 57.1 0.235 0.334 1.8
3.224 1.924e-3 1.055e-5 -3.596e-9 -2.42e5 -2.288e5
1 -7.76451 1.45838 -2.7758 -1.23303 275 647.3 0.998 293
CH4 Methane
2
C1
H4
16.043 90.7 111.6 190.4 46 99.2 0.288 0.011 0
19.25 5.213e-2 1.197e-5 -1.132e-8 -7.49e4 -5.087e4
1 -6.00435 1.1885 -0.83408 -1.22833 91 190.4 0.425 112
Sanýrým son birkaç örnek gerçek programlama ortamýnda veri dosyalarýnýn kullanýlmasý
hakkýnda daha iyi bir fikir vermiºtir. Buradaki tüm örnekler sýralý (sequential) tip veri dosyasý
iºlemektedir. Ayný iºlemler veri tabaný kullanýlarak da yapýlabilirdi.
11.0 GÝRݪ
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu bölümde çeºitli ileri bilgi iºleme ve boyut oluºturma kavramlarýna göz atacaðýz.
Biz bir cümle okuduðumuzda beynimiz cümleyi otomatik olarak kelimelerine ayýrýr. Java
Dilinde bu görevi StringTokenizer sýnýfý yerine getirir. StringTokenizer sýnýfýnýn yapýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
Program çýktýsý :
olacaktýr.
StringTokenizer sýnýfýnýn kullanýlmasýyla ilgili bir örnek daha verelim. Bu örnekte ninci
dereceden bir polinomun kokleri [Link] kütüphanesi (detaylar için bakýnýz bölüm 12)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kullanýlarak çözülür. girdi alanýnda tüm polinom katsayýlarý bir alan içinde tanýmlanmakta ve
sonra bu bileºik alandan StringTokenizer sýnýfý yardýmý ile katsayýlar tek tek çekilmektedir.
Program 11.2 [Link] progamý, n'inci dereceden polinomun köklerini hesaplar. Tek
bir string olarak girilen katsayýlar matrisinden katsayýlarý StringTokenizer sýnýfýný
kullanarak çeker.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import Matrix;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
z[i]=new complex();
}
int j=0;
while([Link]())
{
Double ax=new Double([Link]());
a[j++]=[Link]();
}
z=Matrix.poly_rootsC(a);
int i=0;
[Link]([Link](z));
[Link]("");
}
}
[Link]
ªekil 11.1 StringTokenizer sýnýfýný ve matrix sýnýfýný kullanarak ninci dereceden bir
polinomun koklerini hesaplayan [Link] programýnýn applet çýktýsý
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import Matrix;
JTextArea t;
JPanel YaziPaneli;
int n;
String s;
Container c;
public kokNSWF_2000()
c=getContentPane();
[Link](new FlowLayout());
YaziPaneli=new JPanel();
[Link](new Font("Serif",[Link],12));
t=new JTextArea();
[Link]([Link]());
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](prompt1);
[Link](prompt2);
[Link](input);
[Link](YaziPaneli);
[Link](t);
[Link](this);
s=[Link]();
[Link]("");
n=[Link]()-1;
int m=n+1;
for(int i=0;i<n;i++)
z[i]=new complex();
int j=0;
while([Link]())
a[j++]=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
z=Matrix.poly_rootsC(a);
int i=0;
[Link]([Link](z));
[Link]("");
[Link](new BasicWindowMonitor());
[Link](350,300);
[Link](true);
[Link]
ªekil 11.2 StringTokenizer sýnýfýný ve matrix sýnýfýný kullanarak ninci dereceden bir
polinomun koklerini hesaplayan kokNSWF_2000.java programýnýn JFrame çýktýsý
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
girdi stringinin sonuna ulaºýldýðýný gösterir
TT_EOL
satýr sonu okunduðunu bildirir
TT_NUMBER
bir sayi tokeni okunduðunu bildirir
TT_WORD
bir kelime(String) token'i okunduðunu bildirir..
ttype
nextToken metotu çaðrýldýkrtan sonra bu deðiºken en son okunan token (kelimenin)
türünü bildiri
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String deðiºkenleri içindir. StringBuffer sýnýfýna Append metotuyla dinamik olarak ilave
yapabiliriz.
package [Link];
public StringBuffer
public synchronized void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public StringBuffer append(int i)
public synchronized StringBuffer insert(int index, char str[], int offset, int
len)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 11.4 [Link], giren String deðiºkenini tersine çevirir.
class TersString {
public static String reverseIt(String source) {
int i, len = [Link]();
StringBuffer dest = new StringBuffer(len);
diðer bir StringBuffer metotu insert metotudur. Bu metot i inci elementten sonra verilen yeni
parçayý ilave edecektir.
import [Link].*;
class javaKahvesi {
public static void main (String args[])
{
StringBuffer sb = new StringBuffer("Java kahvesi ic!");
[Link](12, "ni sicak");
[Link]([Link]());
}
}
bu programý çalýºtýrdýðýmýzda
Java kahvesini sicak iç!
mesajýný verecektir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Deyimi bilgisayar belleðinde
1023400 b[0]
1023464 b[1]
1023528 b[2]
Buradaki sorun eðer bilgisayar belleðindeki toplam yer deðiºtirilmek istenirse bunun zor
olmasýdýr. Ayný zamanda bilgisayar boyutlu deðiºkenin adreslerini bilgisayar hafýzasýnda bir
referans tablosu olarak tuttuðundan boyut deðiºtirme bilgisayar hafýzasýný da zorlayan bir
iºlemdir. Pratik olarak yapýlan uygulama yeni bir boyutlu deðiºken oluºturup adresleri
deðiºtirmektir.
Daha geliºmiº bir bilgi yapýsý olarak Vector sýnýfýný kullanabiliriz. Vector sýnýfý [Link]
kütüphanesinde tanýmlanmýºtýr. Vector sýnýfýnda her bilgi elemaný ayný zamanda bir sonraki
bilgi elemanýnýn adresini taºýr. Boylece istenildiðinde dizinin son elemanýna yeni bir adres
ilave edilerek kolayca yeni elemanlar ilave edilebilir.
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class Vector extends AbstractList implements List, Cloneable,
[Link] {
public Vector();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public synchronized Object firstElement();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Vector sýnýfýnda tanýmlanan metotlarýn bazýlarýnýn anlamlarý ºunlardýr :
addElement(Object)
Vektöre object türü (herhangi bir sýnýf olabilir, vectörün hepsi bu sýnfta tanýmlanmýº
olmalýdýr.) bir eleman ekler.
capacity()
vektörün toplam kapasitesini verir.
clone()
vectorun bir kopye vectörünü verir.
contains(Object)
Vectörün içinde sorgulanan elemanýn olup olmadýðýný kontrol eder.
copyInto(Object[])
vectorü boyutlu deðiºkene aktarýr.
elementAt(int indeks)
Verilen indeksteki elemaný verir..
elements()
Tüm vektörü enumeration sýnýfýna aktarýr.
ensureCapacity(int yeni_kapasite)
eðer yeni_kapasite vector kapasitesinin üstündeyse vector yeni_kapasite’ye aktarýlýr.
firstElement()
Vectörün ilk elemanýný verir.
indexOf(Object)
Object’in indeks deðerini verir
indexOf(Object, int indeks)
Object’in indeks deðerini verir, arama indeks deðiºkeninden baºlayarak yapýlýr.
insertElementAt(Object, int indeks)
Vectörün ideks noktasýna Object ilave edilir.
isEmpty()
Vectörün boº olup olmadýðý kontrol edilir.
lastElement()
vectörün son elemanýnýn indeksini verir.
lastIndexOf(Object)
Object’in vectördeki son tekrarýnýn indeksini verir.
lastIndexOf(Object, int indeks)
indeks ten baºlayarak geriye doðru Objectin ilk tekrarlandýðý yeri bulur.
removeAllElements()
Vectördeki bütün elemanlarý siler.
removeElement(Object)
Vectördeki Object elemanýný siler.
removeElementAt(int indeks)
indeksle verilen elemaný siler.
setElementAt(Object, int indeks)
Objectin ideksini indeks olarak belirler.
setSize(int)
Sets the size of this vector.
size()
Vectördeki toplam eleman sayýsýný verir.
toString()
Vectörün String eºitini verir.
trimToSize()
Vectörün boyutunu dolu olan elemanlarýnýn boyutuna kýsaltýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Aºaðýda bu metotlarýn önemlilerinden bazýlarýný kullanan bir örnek program verilmiºtir.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](containsBtn);
[Link](this);
[Link](locationBtn);
[Link](this);
[Link](trimBtn);
[Link](this);
[Link](statsBtn);
[Link](this);
[Link](displayBtn);
add(YaziPaneli);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if([Link](searchKey) )
showStatus("Vektor elemanlar� " +searchKey);
else
showStatus("Aranan eleman Vektorde bulunamadi "+searchKey);
}
else if([Link]()==locationBtn)
{
showStatus("Eleman "+[Link]([Link]() )+" pozisyonunda bulundu");
}
else if([Link]()==trimBtn)
{
[Link]();
showStatus("Vector boyu eleman boyuna k�salt�ld�");
}
else if([Link]()== statsBtn)
{
showStatus("Boyut = "+[Link]()+"; Toplam kapasite = "+[Link]());
}
else if([Link]()== displayBtn)
{
Enumeration enum=[Link]();
StringBuffer buf = new StringBuffer();
while([Link]())
{
[Link]([Link]() );
[Link](" ");
}
showStatus([Link]() );
}
[Link]("");
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
boolean hasMoreElements();
Object nextElement();
ºeklindedir.
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
{
s1=(String)[Link]();
[Link](s1);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
kod parçacýðýnda vector sýnýfýnýn elements metotu,Enumeration sýnýfý ve Enumeration
sýnýfýnýn hasMoreElements ve nextElement metotlarý kullanýlarak nasýl döngü
oluºturulduðu görülmektedir.
Aºaðýdaki örnekte setA sýnýfý verilmiºtir. Bu örnekte bir kümelerin bileºim ve kesiºim
kümelerinin vector metodunu kullanarak nasýl oluºturulabileceði gösterilmektedir.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
class SetA
{
public Vector bilesim(Vector list1, Vector list2)
{
Vector bilesimVectoru = new Vector();
String s1,s2;
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
{
s1=(String)[Link]();
[Link](s1);
}
while([Link]())
{
s2=(String)[Link]();
if()
[Link](s2);
}
return bilesimVectoru;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](s);
}
return kesisimVectoru;
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 11.6 Vector sýnýfýný kullanarak iki kumenin bileºim ve kesiºim kümelerini
hesaplayan [Link] programý applet çýktýsý
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class SetTestSWF_2000 extends JFrame implements ActionListener
JTextField T1,T2;
JTextArea cikti;
// kullanarak aktar
Vector ansUn;
Vector ansInt;
Container c;
public SetTestSWF_2000()
c=getContentPane();
[Link](new FlowLayout());
T1 = new JTextField(30);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]());
T2 = new JTextField(30);
[Link]([Link]());
[Link](false);
[Link]("");
[Link]([Link]());
[Link](P1);
[Link](T1);
[Link](this);
[Link](P2);
[Link](T2);
[Link](this);
[Link](new Dimension(320,200));
[Link](jp);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
StringTokenizer tokens = new StringTokenizer(string);
while([Link]()) {
[Link](test);
while([Link]())
[Link]("\n");
if([Link]()==T1)
girdiA(stringToTokenize,list1);
else if([Link]()==T2)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
girdiA(stringToTokenize,list2);
ansUn = [Link](list1,list2);
ansInt = [Link](list1,list2);
[Link]("");
ciktiA(ansUn);
ciktiA(ansInt);
[Link](new BasicWindowMonitor());
[Link](400,350);
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 11.7 Vector sýnýfýný kullanarak iki kumenin bileºim ve kesiºim kümelerini
hesaplayan SetTestSWF_2000 programý JFrame çýktýsý
Yukarýdaki vektor sýnýfýnda ilk defa dinamik hafýza kullanabilen (vektor boyutunu program
çalýºýrken deðiºtirebilen) Vector sýnýfýný inceledik. Eðer vektor boyutlarý program çalýºýrken
azalýyor veya çoðalýyorsa, boyutlu deðiºkenler yerine dinamik hafýza kullanýmý toplam
bilgisayar hafýzasý kullanýmý açýsýnda çok daha verimlidir. Dinamik data yapýlarý sadece
vektorden ibaret deðildir. List(liste), Stack(dizin) ve Queue (sýra) ve Tree(agaç) yapýlarý da
oldukça sýk kullanýlar dinamik yapýlarý teºkil eder. Bunlardan List yapýsýnýn özellikleri
ºunlardýr :
Listenin ilk elemanýndan önce veya son elemanýndan sonra listeye dinamik
eleman ilavesi yapýlabilir.
Burada List kavramýnýn daha iyi anlaºýlabilmesi için önce kendi List sýnýfýmýz oluºturulmuº ve
bir örnek problemde kullanlmýºtýr. Bu program örneklerine bir göz atalým.
Program 11.9 [Link] programý. Bu program List yapýsýný tanýmlayan ListNode ve List
sýnýflarýný içerir
class ListNode
{
Object data;
ListNode next;
ListNode(Object o) {this(o,null);}
ListNode(Object o,ListNode nextNode)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
data=o;
next=nextNode;
}
Object getObject() {return data;}
ListNode getnext() {return next;}
}
public List(String s)
{
name=s;
firstNode=lastNode=null;
}
public List(){this("Liste");}
public synchronized void insertAtFront(Object insertItem)
{
if( isEmpty() )
firstNode = lastNode = new ListNode(insertItem);
else
firstNode = new ListNode(insertItem,firstNode);
}
public synchronized void insertAtBack(Object insertItem)
{
if(isEmpty())
firstNode=lastNode=new ListNode(insertItem);
else
lastNode=[Link]=new ListNode(insertItem);
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
throw new EmptyListException(name);
removeItem=[Link];
if([Link](lastNode))
firstNode=lastNode=null;
else
{
ListNode current=firstNode;
while([Link] != lastNode)
current=[Link];
lastNode=current;
[Link]=null;
}
return removeItem;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
import List;
import EmptyListException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
List yapýsýný kullanan örnek program [Link] nýn çýktýsý
Liste : true
Liste : $ true
Liste : 34567 $ true
Liste : hello 34567 $ true
hello cikarildi Liste : 34567 $ true
34567 cikarildi Liste : $ true
true cikarildi Liste : $
$ cikarildi Bos Liste
Burada List sýnýfýnýn girdisinin Object sýnýfý olduðun dikkatinizi çekelim. Object sýnýfý yine
dinamik object deðiºken yapýlarý olarak tanýmlanan Double, Byte, String, Integer, Boolean,
Float, Short, Long gibi deðiºken türleri için kullanýlan sýnýflarýn abstract sýnýfýný teºkil eder.
Bu yüzden bu sýnýflarýn hepsini temsil edebilir ve yerlerine kullanýlabilir (genel bir sýnýftýr.). Bu
sýnýflar normal deðiºken türlerine dönüºtürülebilirler. (daha önce de kullandýðýmýz intValue(),
doubleValue() gibi metotlarý kullanarak)
package [Link];
static {
registerNatives();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public final native void notifyAll();
[Link] paketinde List sýnýfý tanýmlanmýºtýr. Yukarýda kendi tanýmladýðýmýz List ile
yapabildiklerimizi ve daha fazlasýný tanýmlý List paketiyle a gerçekleºtirebiliriz.
package [Link];
int size();
boolean isEmpty();
Iterator iterator();
Object[] toArray();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
boolean retainAll(Collection c);
void clear();
int hashCode();
ListIterator listIterator();
/*
package [Link];
boolean hasNext();
Object next();
boolean hasPrevious();
Object previous();
int nextIndex();
int previousIndex();
void remove();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
void set(Object o);
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
"Neptün", "Pluto"};
[Link] (names[i]);
String s;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link]();
s = (String)[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link](s);
[Link]();
[Link]();
[Link]();
s = (String)[Link]();
[Link]();
[Link]();
[Link]();
[Link](s);
Iterator it = [Link]();
String ss="";
[Link](null,ss);
[Link](0);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 11.08 List sýnýfý, MovingPlanets çýktýsý
List sýnýfýnýn bir alt sýnýfý da LinkedList sýnýfýdýr. LinkedList sýnýfý List sýnýfýnda olmayan ilave
metodlar tanýmlamýºtýr.
public LinkedList()
public LinkedList(Collection c)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean add(Object o)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
static class Gezegen {
isim = s;
aySayisi = aylar;
return isim;
return aySayisi;
"Neptün", "Pluto"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String ss="";
[Link](null,ss);
[Link](0);
Program çýktýsý
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
11.5 DÝZÝ (STACK) SINIFI
Diziler veya ingilizce adýyla Stack aslýnda üstte tanýmladýðýmýz List sýnýfýnýn bir alt sýnýfýdýr.
dizin listeye göre daha sýnýrlý olan ºu koºullara sahiptir :
import [Link];
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class diziTesti
{
public static void main(String args[])
{
dizi d=new dizi();
Boolean b=new Boolean(true);
Character c=new Character('$');
Integer i=new Integer(34567);
String s=new String("hello");
[Link](b);
[Link]();
[Link](c);
[Link]();
[Link](i);
[Link]();
[Link](s);
[Link]();
Object cekilen;
try
{
while(true)
{
cekilen=[Link]();
[Link]([Link]()+" diziden cekildi");
[Link]();
}
}
catch(EmptyListException e)
{[Link]("\n"+[Link]());}
}
}
dizi : true
dizi : $ true
$ diziden cekildi
dizi : true
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
true diziden cekildi
Bos dizi
[Link] paketinde vector sýfýnýn yaný sýra Stack sýnýfý da tanýmlanmýºtýr. Java Stack
sýnýfýnda
push, pop ve peek metotlarý vardýr. push ve pop dizin programýný aynýsýdýr. peek ise listenin
en sonundaki elemanýn deðerini bu elemaný listeden uzaklaºtýrmadan alýr. (pop ile push
beraber kullanýlarak da ayný iºi yapabilirler)
Bu sýnýfýn tanýmý :
public Stack();
push
public Object push(Object item)
stack'in üstüne yeni eleman ilave eder
pop
public synchronized Object pop()
Stakin en tepesindeki elemaný çeker (Stack dizisinden kaldýrýr ve deðerini return eder)
Stack'in boº olmasý halinde EmptyStackException gönderir.
peek
public synchronized Object peek()
Stack'in en tepesindeki elemanýn deðerini okur(Stack dizisinden kaldýrmaz ve sadece
deðerini return eder)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Stack'in boº olmasý halinde EmptyStackException gönderir.
empty
public boolean empty()
Stack'in boº olup olmadýðýný kontrol eder, boº ise true, dolu ise false deðeri gönderir.
Tests if this stack is empty.
search
public synchronized int search(Object o)
Stack'in içindeki istenen Object'in yerini verir. Eðer object Stack'de yok ise -1 deðeri verir
Burada hemen Stack sýnýfýnýn Vector sýnýfýnýn alt sýnýfý olduðunu ve Vector sýnýfýnda mevcut
olan tüm metotlar Stack metotunda da geçerli olduðunu da hatýrlatalým.
Program 11.16 : [Link] kütüphanesinde yer alan Stack yapýsýný kullanan örnek
program [Link]
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]()+" de§eri listeden cekildi ");
[Link](d);
[Link]("---------------------");
}
}
catch(EmptyStackException e)
{[Link]("\n"+[Link]());}
}
true
true $
true $ 34567
true $ 34567 hello
hello degerine bakildi
true $ 34567 hello
hello degeri listeden cekildi
true $ 34567
---------------------
34567 degerine bakildi
true $ 34567
34567 degeri listeden cekildi
true $
---------------------
$ degerine bakildi
true $
$ degeri listeden cekildi
true
---------------------
true degerine bakildi
true
true degeri listeden cekildi
---------------------
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Sýra veya ingilizce adýyla queue aslýnda üstte tanýmladýðýmýz List sýnýfýnýn bir alt sýnýfýdýr. sýra
listeye göre daha sýnýrlý olan ºu koºullara sahiptir :
Sýra kavramýnýn oldukça yaygýn olarak kullanýldýðý ülkemizde oldukça yararlý olabilecek bir
sýnýfý deðilmi?
Yukardaki List tanýmýný kullanarak oluºturduðumuz sýra programý ve sýrayýi kullanan bir test
programý aºaðýda verilmiºtir.
import sira;
import EmptyListException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link](i);
[Link]();
[Link](st);
[Link]();
Object cekilen;
try
{
while(true)
{
cekilen=[Link]();
[Link]([Link]()+" sirasi geldi ”nden cikti");
[Link]();
}
}
catch(EmptyListException e)
{[Link]("\n"+[Link]());}
}
}
sira : true
sira : true $
sira : true $ 34567
sira : true $ 34567 merhaba
true sirasi geldi onden cikti
sira : $ 34567 merhaba
$ sirasi geldi onden cikti
sira : 34567 merhaba
34567 sirasi geldi onden cikti
sira : merhaba
merhaba sirasi geldi onden cikti
Bos sira
Queue sýnýfý Java'da direk olarak tanýmlanmamýºtýr, ancak üstteki sýra örneginin bir benzeri
Vector sýnýfýndan bizim tarafýmýzdan rahatlýkla yazýlabilir, veya yine LinkedList sýnýfýnýn
addFirst()/removeLast() metodlarýný kullanarak oluºturulabilir.
Elimizdeki bir gurup boyutlu deðiºkenin belli bir yapýda guruplandýrýlmasý veya aranmasý
gerektiðinde bu standart boyut kavramýnda oldukça kompleks bir yapý arzeder. Bilgi
guruplandýrma iºlemini çok daha basit bir ºekilde yapabilmek için Tree yapýlarý
öngörülmektedir. Tree temel olarak Vector gibi bir yapýdýr. fakat burada her Tree noktasý
(Nod'u) iki deðiºik adrese iºaret eder bu adreslerden birisi o nodedaki objenin kokdekinden
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
daha küçük olduðu bir deðeri, diðeri ise daha büyük olduðu bir deðeri taºýr. hiç bir deðer
taºýmýyorsa da null deðeriyle o Tree-aðaç dalý sona erer. Bu yapýyý kullanarak sayýlarý
büyükten küçüge veyaküçükten büyüðe veya daha deðiºik mantýklarla direk olarak sýralamak
mümkündür.
[Link]
ªekil 11.10 : Binary search Tree (ikili arama aðacý) yapýsýnýn grafiksel gösterimi
[Link]
ªekil 11.11 Binary search Tree (ikili arama aðacý ) yapýsýnýn bir rakam setine
uygulanmasýnýn grafiksel gösterimi
ªekil 11.10 de ikili arama aðacý yapýsýnýn seti görülmektedir. ªekil 11.11 de ise sayýsal bir
örnekle yapý gösterilmiºtir. Her bir dal kökü kendinden sonra gelen rakamý küçükse sol dala
büyükse sað dala göndermektedir. ve her yeni veri yeni bir dallanma oluºturmaktadýr. ªimdi
Tree yapýsýný oluºturacak bir örnek sýnýfý ve onun kullanýldýðý bir örnek problem sýnýfýný
oluºturarak kavramý biraz daha açmaya çalýºalým :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 11.19 : Binary search Tree (ikili arama aðacý) yapýsýnýn programlandýðý
TreeNode ve Tree sýnýflarýnýn ter aldýðý [Link] programý
class TreeNode
{
TreeNode sol;
int data;
TreeNode sag;
public TreeNode(int d)
{
data=d;
sol=sag=null;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void node_sagdal_soldal_siralayici(TreeNode node)
{
if(node==null) return;
[Link]([Link]+" ");
node_sagdal_soldal_siralayici([Link]);
node_sagdal_soldal_siralayici([Link]);
}
public void soldal_node_sagdal_siralayici(TreeNode node)
{
if(node==null) return;
soldal_node_sagdal_siralayici([Link]);
[Link]([Link]+" ");
soldal_node_sagdal_siralayici([Link]);
}
public void sagdal_node_soldal_siralayici(TreeNode node)
{
if(node==null) return;
sagdal_node_soldal_siralayici([Link]);
[Link]([Link]+" ");
sagdal_node_soldal_siralayici([Link]);
}
public void soldal_sagdal_node_siralayici(TreeNode node)
{
if(node==null) return;
soldal_node_sagdal_siralayici([Link]);
soldal_node_sagdal_siralayici([Link]);
[Link]([Link]+" ");
}
public void sagdal_soldal_node_siralayici(TreeNode node)
{
if(node==null) return;
sagdal_node_soldal_siralayici([Link]);
sagdal_node_soldal_siralayici([Link]);
[Link]([Link]+" ");
}
}
Program 11.20 : Binary search Tree (ikili arama aðacý) yapýsýnýn programlandýðý
TreeNode ve Tree sýnýflarýnýn kullanýlmasýný örnekleyen [Link] programý
import Tree;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("orijinal olarak Tree'ye girilen sayi dizini");
for(int i=0;i<=6;i++)
{
sayi=(int)([Link]()*45)+1;
[Link](sayi+" ");
[Link](sayi);
}
[Link]("\nSol dal - kok - sag dal siralama : ");
agac.soldal_node_sagdal_sirala();
[Link]("\nkok -Sol dal - sag dal siralama : ");
agac.node_soldal_sagdal_sirala();
[Link]("\nSol dal - sag dal - kok siralama : ");
agac.soldal_sagdal_node_sirala();
[Link]("\nSag dal - kok - sol dal siralama : ");
agac.sagdal_node_soldal_sirala();
[Link]("\nkok -Sag dal - sol dal siralama : ");
agac.node_sagdal_soldal_sirala();
[Link]("\nSag dal - sol dal - kok siralama : ");
agac.sagdal_soldal_node_sirala();
}
}
Program 11.17 : Binary search Tree (ikili arama aðacý) yapýsýnýn programlandýðý
TreeNode ve Tree sýnýflarýnýn kullanýlmasýný örnekleyen [Link] programýnýn
sonuçlarý. renkli olarak iºaretlenen satýrlarýn sayý dizisini küçükten büyüðe ve
büyükten küçüðe sýraladýðýna dikkat ediniz.
ªu ana kadar bu konuda gördüðümüz elemanlarda belli bir baðlantý kuralý kullanarak
elemanlarý birbirine baðlamýºtýk. Bu hafýza açýsýndan yoðun bir iºlemdir. Her seferinde hafýza
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
pozisyonunun araºtýrýlmasýný gerektirir. Java anahtar referans saðlayan daha deðiºik bir
yapýyý da içerir. Burada her elemanýn kendimiz tarafýndan verilen bir referans deðeri
mevcuttur, ve elemaný bulmak için bu referansý kullanabiliriz. Bu gurubun abstract sýnýfý
Dictionary sýnýfýdýr. Dictionary sýnýfýnýn altýnda Hashtable sýnýfý yer alýr. Dictionary sýnýfýnýn
tanýmý :
package [Link];
public Dictionary()
[Link] {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private static final long serialVersionUID = 1421746759512286392L;
public Hashtable(Map t)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Hashtables sýnýfý temel olarak Dictionary ve Map sýnýflarýndan türetilmiºtir. Map sýnýfý tanýmý
package [Link];
int size();
boolean isEmpty();
void clear();
int hashCode();
Object getKey();
Object getValue();
int hashCode();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
ºeklindedir.
import [Link];
import [Link];
import [Link];
"Neptün", "Pluton"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] (names[i], new Float (diameters[i]));
Object obj;
String ss="";
while ([Link]()) {
obj = [Link]();
[Link](null,ss);
[Link](0);
[Link]
Programdan da görüldüðü gibi çýktý hiçbir mantýksal sýralama düzeni içermemektedir, fakat
burada önemli olan gezegenlerin ve çaplarýnýn birbirleriyle olan iliºkilerinin listelenmesidir.
Hashtable bu tür iºlevleri en iyi bir ºekilde yerine getirir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
11.9 ARRAYS SINIFI VE SIRALAMA
Arrays sýnýfý boyutlu deðiºkenleri sýralamaya yarýyan bir java sýnfýdýr. Metodlarý:
boyutlu deðiºkenin tüm deðerlerini veya tanýmlanan bir bölümünü bir bölümünü ayný tür bir
deðiºken atayan
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class Gezegensirasi {
String s1 = [Link]().toLowerCase();
String s2 = [Link]().toLowerCase();
"Neptün", "Pluto",
"neptün", "pluto"
};
[Link](names);
String ss="";
ss+="\n";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
ss+="\n";
[Link](null,ss);
[Link](0);
[Link]
programda liste ikinci kere Comparator sýnýfý InsensitiveComp() kullanarak büyük ve küçük
harfi göz önüne almadan sýraya sokulmuºtur.
11.10 ALIªTIRMALAR
import [Link].*;
import Text;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String s1;
Text cin= new Text();
[Link]("Lutfen dosya ismini giriniz: ");
s1 = [Link]();
File myfile = new File(s1);
BufferedReader b= new BufferedReader(new FileReader(myfile));
int toplam=0;
boolean EOF=false;
int j=0;
while (!EOF)
{
try
{
j++;
[Link]([Link](b));
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
Enumeration enum=[Link]();
StringBuffer buf = new StringBuffer();
while([Link]())
{
[Link]([Link]());
Double d=new Double([Link]());
toplam+=[Link]();
}
[Link]("Dosyanin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/[Link]());
} //main
} //class
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
18.0 toplam: 171
19.0 toplam: 190
20.0 toplam: 210
dosyanýn ve yuklendigi vektorun icindeki sayilarin adedi: 20
Ortalama: 10.5
2. [Link] : List sýnýfý örnegi, H9O1 de boyutlu deðiºkenle çözülen dosyadan okunan
rakamlarýn ortalamasýnýn bulunmasý.
import [Link].*;
import Text;
import [Link].*;
import [Link];
import [Link];
while(![Link]())
{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double d=new Double((String)[Link]());
toplam+=[Link]();
[Link](""+d+" toplam: "+toplam);
}
[Link]("dosyan�n ve y�klendigi listenin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/j);
} //main
} //class
3. [Link] : dizi sýnýfý örnegi, H9O1 de boyutlu deðiºkenle çözülen dosyadan okunan
rakamlarýn ortalamasýnýn bulunmasý.
import [Link].*;
import Text;
import [Link].*;
import [Link];
import [Link];
//dizi ornegi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H10AL3
{
public static void main(String[] args) throws IOException
{
DataInputStream input;
dizi l= new dizi();
String s1;
Text cin= new Text();
[Link]("Lutfen dosya ismini giriniz: ");
s1 = [Link]();
File myfile = new File(s1);
BufferedReader b= new BufferedReader(new FileReader(myfile));
int toplam=0;
boolean EOF=false;
int j=0;
while (!EOF)
{
try
{
[Link]([Link](b));
j++;
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
while(![Link]())
{
Double d=new Double((String)[Link]());
toplam+=[Link]();
[Link](""+d+" toplam: "+toplam);
}
[Link]("dosyanin ve yuklendigi listenin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/j);
} //main
} //class
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
8.0 toplam: 182
7.0 toplam: 189
6.0 toplam: 195
5.0 toplam: 200
4.0 toplam: 204
3.0 toplam: 207
2.0 toplam: 209
1.0 toplam: 210
dosyanin ve yuklendigi listenin icindeki sayilarin adedi: 20
Ortalama: 10.5
import [Link].*;
import Text;
import [Link].*;
import [Link];
import [Link];
//sira ornegi
public class H10AL4
{
public static void main(String[] args) throws IOException
{
DataInputStream input;
sira l= new sira();
String s1;
Text cin= new Text();
[Link]("Lutfen dosya ismini giriniz: ");
s1 = [Link]();
File myfile = new File(s1);
BufferedReader b= new BufferedReader(new FileReader(myfile));
int toplam=0;
boolean EOF=false;
int j=0;
while (!EOF)
{
try
{
[Link]([Link](b));
j++;
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} //while
while(![Link]())
{
Double d=new Double((String)[Link]());
toplam+=[Link]();
[Link](""+d+" toplam: "+toplam);
}
[Link]("dosyanin ve yuklendigi listenin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/j);
} //main
} //class
import [Link].*;
import Text;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class H10AL5
{
public static void main(String[] args) throws IOException
{
DataInputStream input;
Stack l= new Stack();
String s1;
Text cin= new Text();
[Link]("Lutfen dosya ismini giriniz: ");
s1 = [Link]();
File myfile = new File(s1);
BufferedReader b= new BufferedReader(new FileReader(myfile));
int toplam=0;
boolean EOF=false;
int j=0;
while (!EOF)
{
try
{
[Link]([Link](b));
j++;
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
while(![Link]())
{
Double d=new Double((String)[Link]());
toplam+=[Link]();
[Link](""+d+" toplam: "+toplam);
}
[Link]("dosyanin ve yuklendigi listenin icindeki sayilarin adedi: "+j);
[Link]("Ortalama: "+(double)toplam/j);
} //main
} //class
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
7.0 toplam: 189
6.0 toplam: 195
5.0 toplam: 200
4.0 toplam: 204
3.0 toplam: 207
2.0 toplam: 209
1.0 toplam: 210
dosyanin ve yuklendigi listenin icindeki sayilarin adedi: 20
Ortalama: 10.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
12. [Link]
veri dosyasý [Link]'e e dizisini giriniz. [Link]'e d dizisini giriniz. program setText'ti
inceleyiniz. iki dizinin bileºim kümesini [Link] dosyasýna yazdýrýnýz.
Program 11.28 [Link] iki dizinin bileºim kümesini vektor sýnýfýný kullanarak
hesaplayan program
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import Text;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
EOF=false;
while (!EOF)
{
try
{
[Link]([Link](b2));
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
v=[Link](v1,v2);
[Link](ciktiA(v));
PrintWriter cfout=new PrintWriter(new BufferedWriter(new FileWriter("[Link]")));
[Link](ciktiA(v));
[Link]();
toplam=0;
Enumeration enum=[Link]();
while([Link]())
{
Double d=new Double((String)[Link]());
toplam+=[Link]();
}
[Link]("dosyanin ve yuklendigi vektorun icindeki sayilarin adedi: "+[Link]());
[Link]("Ortalama: "+(double)toplam/[Link]());
} //main
} //class
sonuçlar :
[Link]:
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
[Link]
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 1 2 3 4 5 6 7 8 9
8. H10OD2
alýºtýrma 7 deki sonuçlarý Tree sýnýfýný kullanarak küçükten büyüge doðru sýralanmýº olarak
[Link] dosyasýna yazdýrýnýz.
import [Link].*;
import Text;
import [Link].*;
import bolum11.Tree1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Vector v2= new Vector(1);
Vector v=new Vector(1);
String s1,s2;
Text cin= new Text();
[Link]("Lutfen ilk dosya ismini giriniz: ");
s1 = [Link]();
File myfile1 = new File(s1);
BufferedReader b1= new BufferedReader(new FileReader(myfile1));
[Link]("Lutfen ikinci dosya ismini giriniz: ");
s2 = [Link]();
File myfile2 = new File(s2);
BufferedReader b2= new BufferedReader(new FileReader(myfile2));
int toplam=0;
boolean EOF=false;
while (!EOF)
{
try
{
[Link]([Link](b1));
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
EOF=false;
while (!EOF)
{
try
{
[Link]([Link](b2));
}
catch (EOFException e)
{
[Link]();
EOF=true;
}
} //while
v=[Link](v1,v2);
Enumeration enum=[Link]();
while([Link]())
{
Integer d=new Integer((String)[Link]());
[Link]([Link]());
}
} //class
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
[Link] :
11 13 24 15 17 22 18 19 12 20 21 23 25 14 26 27 16 28 29 10
[Link]
1 8 9 11 12 3 4 13 10 18 19 14 15 16 2 5 6 7 17 20
sonuç (ekran)
package bolum11;
class TreeNode
{
TreeNode sol;
int data;
TreeNode sag;
public TreeNode(int d)
{
data=d;
sol=sag=null;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class Tree1
{
private TreeNode kok;
public Tree1() {kok=null;}
public synchronized void gir(int d)
{
if(kok==null) kok=new TreeNode(d);
else [Link](d);
}
13. H10OD3
Ekrandan bir rakam dizisini tek bir String olarak giriniz. Girdiginiz diziyi
StringTokenezer sýnýfý bir gerçek sayi rakam dizisine dönüºtürünüz ve vector sýnýfýna
yükleyiniz. daha sonra vector elemanlarýnýn karesinin ortalamasýný çýktý olarak veriniz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import Text;
import [Link].*;
import bolum11.Tree1;
sonuclar:
14. H10OD4
Ekrandan bir rakam dizisini tek bir String olarak giriniz. Girdiginiz diziyi
StringTokenezer sýnýfý bir gerçek sayi rakam dizisine dönüºtürünüz ve Stack sýnýfýna
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
yükleyiniz. daha sonra Stack elemanlarýnýn karesinin ortalamasýný çýktý olarak veriniz.
import [Link].*;
import Text;
import [Link].*;
import bolum11.Tree1;
// not stack vektor s�n�f�n�n bir alt s�n�f�d�r.
// bu uygulamada bu ”zellikten yararlan�lm�Ÿt�r.
sonuçlar :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 11.33 : [Link]: ikinci program (ayný program 11.20'nin deðiºik yazýlýºý ) :
[Link]
import [Link].*;
import Text;
import [Link].*;
import bolum11.Tree1;
sonuçlar :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
15. Java Vector uygulamasý [Link]
import [Link].*;
Gezegen (String s) {
isim = s;
"Neptün", "Pluto"};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] ([Link] (i));
import [Link].*;
import [Link];
isim = s;
aySayisi = aylar;
return isim;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public final int getMoonCount () {
return aySayisi;
"Neptün", "Pluto"};
Gezegen p;
String ss="";
while ([Link]()) {
p = (Gezegen)([Link]());
[Link](null,ss);
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
BÖLÜM 12: ÖRNEKLERLE SAYISAL ANALÝZ
Bu bölümümüzde bazý pratik matematik problemlerinin java ile nasýl çözülebileceðine göz
atacaðýz. Sayýsal analiz iºlemlerini yapmak amacýyla iki sýnýf oluºturduk bunlar Matrix ve
Numeric sýnýflarýdýr. Bu serinin devamý olan java ile numerik analiz kitabýnda bu sýnýflardaki
metotlarý tek tek incelemeye çalýºacaðým. Burada ise sadece program listeleri ve örnek
problemler vermekle yetineceðiz. Buradaki metodlar uluslararasý projelerde kullanýldýðýndan
metot isim ve tanýmlamalarý ingilizcedir. Sadece bu kitabýn kapsamý için deðil gerçek nümerik
problemlerde kullanýlmak amacýyla geliºtirilmiºlerdir. Burada ayrýca hemen ºunu da
belirtelim: sayýsal metodlarýn kullanýmý bu metodlar, sayýsal analiz ve bilgisayar
deðiºkenlerinin deðiºimi ile ilgili iyi bilgi gerektirmektedir. Bu sýnýf ve metodlarý ciddi bir
uygulamada kullanmadan önce verilen metodlar hakkýnda nümerik analiz kitaplarndan
yeterince bilgi sahibi olmanýzý ve test fonksiyonlarý kullanarak sizin istediðiniz görevi yapýp
yapamýyacaklarýný iyice kontrol etmenizi tavsiye ederim. Türkiyedeki nümerik analizle
ilgilenen arkadaºlar eðer ilgilenirlerse benim kendi projelerimde kullanmak için geliºtirdiðim
bu gurubu daha da geliºtirerek genel bir nümerik analiz kütüphanesine dönüºtürmemiz
mümkün olabilir.
Matrix sýnýfý double ve complex vektör (bir boyutlu deðiºken) ve matris (iki boyutlu deðiºken)
deðiºkenlerinin matematik iºlemlerini yapmak amacýyla tanýmlanmýºtýr. complex
(kompleks deðiºken sýnýfý) daha önce türkçe olarak tanýmlanan kompleks sýnýfýnýn
aynýdýr, fakat metot isimleri burada ingilizce olduðundan bu sýnýfýn tanýmýný tekrar verelim
:
//===========================================
//===========================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
// class complex
//
class complex {
// constructors
public complex()
nreal=0;
nimag=0;
nreal=nre;
nimag=nim;
nreal=numer;
nimag=0;
nreal=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
nimag=[Link]();
// accessor functions
return nreal;
return nimag;
nreal=r;
nimag=i;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return [Link](nreal*nreal+nimag*nimag);
return Math.atan2(nimag,nreal);
return Math.atan2(nimag,nreal)*45.0/[Link](1.0);
// assignments
nreal=[Link]();
nimag=[Link]();
nreal=nr;
nimag=ni;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void add(complex right)
double a=nreal*nreal+nimag*nimag;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{ // return sum of two complex numbers
complex result;
result=new complex(r1,i1);
return result;
complex result;
([Link]() - [Link]()));
return result;
complex result;
result=new complex
(([Link]()*[Link]() - [Link]()*[Link]()),
([Link]()*[Link]() + [Link]()*[Link]()));
return result;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static complex divide(complex left, complex right)
double a=[Link]()*[Link]()+[Link]()*[Link]();
complex result;
result=new complex
(([Link]()*[Link]() + [Link]()*[Link]())/a,
(-[Link]()*[Link]() + [Link]()*[Link]())/a);
return result;
double Rad,th;
Rad=[Link](left.R(),right);
th=right*[Link]();
complex result;
(Rad*[Link](th) ) );
return result;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean smaller_equal(complex left,complex right)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public boolean not_equal(complex left,complex right)
String b="";
if([Link]([Link]())!=1)
if([Link]() >= 0)
else
else
if([Link]() >= 0)
b=b+"("+[Link]()+" + i )";
else
b=b+"("+[Link]()+" - i )";
return b;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public String toString()
String b="";
if([Link](imaginary())!=1)
if(imaginary() > 0)
else
else
if(imaginary() > 0)
b=b+"("+real()+" + i )";
b=b+"("+real()+" - i )";
else
b=b+real()+" ";
return b;
// data areas
double nreal;
double nimag;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
};
ªimdi Matrix metoduna daha detaylý bakabiliriz. Ýlkönce Matrix sýnýfýnýn metot baºlýklarýný
verelim :
toString Metotlarý
left double matrisini String deðiºkeni olarak yazýma hazýr hale getirir.
public static String toString(complex[][] left)
left complex matrisini String deðiºkeni olarak yazýma hazýr hale getirir.
public static String toStringT(complex[] left)
left complex vektörünü String deðiºkeni sütun olarak yazýma hazýr hale getirir.
public static String toString(complex[] left)
left complex vektörünü String deðiºkeni satýr olarak yazýma hazýr hale getirir.
public static String toStringT(double[] left)
left double vektörünü String deðiºkeni sütun olarak yazýma hazýr hale getirir.
public static String toString(double[] left)
left complex vektörünü String deðiºkeni satýr olarak yazýma hazýr hale getirir.
Denklem çözümlerinde temel olarak iki sayýsal analiz tekniðinden yararlanýlmýºtýr. Birinci
metod tam pivotlu gauss eliminasyon yöntem,, diðeri ise LU ayrýºtýrma yöntemidir. Gauss
eliminasyon yöntemi matrisi eliminasyon yöntemi kullanarak bir üst üçgen matris haline
dönüºtürür, yani diagonal elementlerin altýnda kalan elemanlarý sýfýrlar. Böylece denklem
sistemi tek bilinmiyenli bir lineer denklemden baºayarak iki bilinmiyenli, üç bilinmiyenli vs bir
denklem sistemine dönüºür. Bu denklem sistemi bir bilinmiyenli denklemin çözülüp deðerinin
iki blinmiyenli denklemde yerine konulmasýyla ikincinin çözülmesi ve ayný iºlemin seri halde
devamýyla tüm bilinmeyenler çözülür. LU ayrýºtýrma metodunda ise matris önce bir üst üçgen
matris(U) ve bir alt üçgen matris (L) ye ayrýºtýrýlýr. Sistem L ve U matrislerini kullanarak
çözülür. Ýnverse (ters) matris hesabý da yine bu iki yöntemin kullanýlmasýyla gerçekleºtirilir.
Eðer sadece bir matris çözülecekse gauss eliminasyon ve LU yöntemleri arasýnda
hesaplama verimi farký yoktur, ancak sadece denklemin sað tarafý deðiºiyorsa LU daha
verimli olarak hesap yapar. Hesaplama hassasiyetini arttýrmak için pivoting adýverilen bir
metod kullanýlmýºtýr. Pivoting matrisin satýr ve sütunlarýnýn yerini deðiºtirerek yuvarlama
hatalarýnýn minimize edilmesi tekniðidir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] inv(double[][] a)
lineer denklem sistemini tam pivotlu gauss eliminasyon metodu yardýmýyla çözer.
Determinant hesaplarý
Determinant özel bir matris çarpým prosesidir. Tek bir sayýyla ifade edilir. Determinant hesabý
için LU metodu daha uygun olduðundan bu metod kullanýlmýºtýr. Aºaðýdaki metodlar aslýnda
tek bir metod olup, deðiºik isimleri verebilmek amacýyla üç ayrý metod olarak sunulmuºtur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double sayý - vektör çarpýmý
public static double[] multiply(double[] left,double right)
A/B = B*inv(A)
iki matrisin LU metodu kullanýlarak bölümü (birinci matrisin ikinci matrisin inversüyle
çarpýmý)
public static double[] LUdivide(double[] left,double[][] right)
Üst iºlemi : üst iºleminden anlaºýlan matristeki her elemanýn ayrý ayrý üssünü almaktýr
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Absulute matris : absolute matris, matris elemanlarýnýn tümünün deðerini positife çevirir.
Transpose matris : transpose matris matrisin satýr ve sütünlarýnýn yerini deðiºtirir, yani
satýrlar sütun, sütunlar satýr haline dönüºür. (aij) T =aji
Birim matris : birim matris diagonal elemanýnda (aii) 1 deðeri olan diðer elemanlarý ise 0
taºýyan (aij,j!=I) matristir.
Birim matris
public static double[] one(int n)
[A]{X}-[I]=0 olarak tanýmlanýr. Burada {X} denklemi saðlayan vektör setidir, eigen vektörü
(sýnýr deðer vektörü) olarak adlandýrýlýr. deðeri ise EigenValue(sýnýr deðeri) adýný alýr.
Buradaki [I] birim matrisdir. ªüphesiz, verilen bir matris için birden fazla eigenvektör ve
eigenvalue bulunabilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] Hessenberg(double b[][])
QR metodunun aynýdýr.
public static complex[] eigenValueC(double b[][])
Polinomun kökleri
Polinomun köklerinin bulunmasý aslýnda bir eigenvalue (sýnýrdeðer) problemidir. Herhangi bir
dereceden polinomun katsayýlarý verildiðinde karekteristikmatris adý verilen bir matris
eºdeðeri oluºturulabilir. Bu matrisin eigenvalue deðerleri verilen polinomun kökleridir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//=============================================================
// Numerical Analysis Packages in Java
// Matrix calculations class Matrix
// Author : Dr. Turhan Coban
//=============================================================
//Turhan Coban
import [Link].*;
import complex;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n,m;
String b;
b="";
n=[Link];
m=left[0].length;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
b=b+left[i][j].toString()+"\t";
}
b=b+"\n";
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<n;i++)
{
b=b+toString(left[i])+"\n";
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// inversion by using gaussian elimination
// with full pivoting
int n=[Link];
int m=a[0].length;
double b[][];
b=new double[n][n];
int indxc[];
int indxr[];
double ipiv[];
indxc=new int[n];
indxr=new int[n];
ipiv=new double[n];
int i,j,k,l,ll,ii,jj;
int icol=0;
int irow=0;
double big,dum,pivinv,temp;
if(n!=m)
{
[Link]("Matrix must be square ");
for(ii=0;ii<n;ii++)
for(jj=0;jj<n;jj++)
b[ii][jj]=0.0;
return b;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
b[i][j]=a[i][j];
for(i=0;i<n;i++)
{
big=0.0;
for(j=0;j<n;j++)
{
if(ipiv[j] != 1)
for(k=0;k<n;k++)
{
if(ipiv[k] == 0)
{
if([Link](b[j][k]) = big)
{
big=[Link](b[j][k]);
irow=j;
icol=k;
}
}
else if(ipiv[k] 1 )
{
[Link]("error : inverse of the matrix : singular matrix-1");
for(ii=0;ii<n;ii++)
for(jj=0;jj<n;jj++)
b[ii][jj]=0.0;
return b;
}
}
}
++ ipiv[icol];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if(irow != icol)
for(l=0;l<n;l++)
{
temp=b[irow][l];
b[irow][l]=b[icol][l];
b[icol][l]=temp;
}
indxr[i]=irow;
indxc[i]=icol;
if(b[icol][icol] == 0.0)
{
[Link]("error : inverse of the matrix : singular matrix-2");
for(ii=0;ii<n;ii++)
for(jj=0;jj<n;jj++)
b[ii][jj]=0.0;
return b;
}
pivinv=1.0/b[icol][icol];
b[icol][icol]=1.0;
for(l=0;l<n;l++) b[icol][l] *=pivinv;
for(ll=0;ll<n;ll++)
if(ll != icol)
{
dum=b[ll][icol];
b[ll][icol]=0.0;
for(l=0;l<n;l++) b[ll][l]-= b[icol][l]*dum;
}
}
for(l=n-1;l=0;l--)
{
if(indxr[l] != indxc[l])
for(k=0;k<n;k++)
{
temp=b[k][indxc[l]];
b[k][indxc[l]]=b[k][indxr[l]];
b[k][indxr[l]]=temp;
}
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
a=new double[n][n];
double vv[];
vv=new double[n];
double sum,dum,big,temp;
int i,j,k;
int imax;
int nmax=100;
double tiny=1.0e-40;
imax=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
a[i-1][j-1]=c[i-1][j-1];
}
d[0]=1;
for(i=1;i<=n;i++)
{
big=0.0;
for(j=1;j<=n;j++)
{
if([Link](a[i-1][j-1])big) big=[Link](a[i-1][j-1]);
}
if(big==0) {[Link]("singular matrix");return a;}
vv[i-1]=1.0/big;
}
for(j=1;j<=n;j++)
{
for(i=1;i<j;i++)
{
sum=a[i-1][j-1];
for(k=1;k<i;k++)
{
sum-=a[i-1][k-1]*a[k-1][j-1];
}
a[i-1][j-1]=sum;
}
big=0;
for(i=j;i<=n;i++)
{
sum=a[i-1][j-1];
for(k=1;k<j;k++)
{
sum-=a[i-1][k-1]*a[k-1][j-1];
}
a[i-1][j-1]=sum;
dum=vv[i-1]*[Link](sum);
if(dum=big)
{
imax=i;
big=dum;
}
} //end of i=0
if(j != imax)
{
for(k=1;k<=n;k++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
dum=a[imax-1][k-1];
a[imax-1][k-1]=a[j-1][k-1];
a[j-1][k-1]=dum;
}
d[0]=-d[0];
vv[imax-1]=vv[j-1];
} //end of if
indx[j-1]=imax;
if(a[j-1][j-1]==0) a[j-1][j-1]=tiny;
if(j!=n)
{
dum=1.0/a[j-1][j-1];
for(i=j+1;i<=n;i++)
a[i-1][j-1]*=dum;
}//endif
} //end for j=
return a;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(j=(i+1);j<=n;j++)
{
sum-=a[i-1][j-1]*b[j-1];
}
}
b[i-1]=sum/a[i-1][i-1];
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return e;
} //end of det
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n1=[Link];
int m2=[Link];
double[] b;
b=new double[m2];
if(n1 != m2)
{
[Link]("inner matrix dimensions must agree");
for(ii=0;ii<n1;ii++)
{
b[ii]=0;
}
return b;
}
for(i=0;i<m1;i++)
{
b[i]=0;
for(k=0;k<n1;k++)
b[i]+=left[i][k]*right[k];
}
return b;
//end of multiply of a matrix and a vector
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n=[Link];
int m=right[0].length;
double b[][];
b=new double[n][m];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
b[i][j]=right[i][j]*left;
}
return b;
//end of multiplying a matrix with a constant double
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return b;
}
//*************** end of multiply methods definitions **************
//=============== defination of power methods pow ==============
public static double[][] pow(double[][] right,double left)
{
// power of a matrix
int i,j;
double b[][];
int n=[Link];
int m=right[0].length;
b=new double[n][m];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(left==0.0)
{
b[i][j]=1.0;
}
else
{
b[i][j]=[Link](right[i][j],left);
}
}
}
return b;
//end of power of a matrix
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] add(double[][] left,double[][] right)
{
//addition of two matrices
int n1=[Link];
int m1=left[0].length;
int n2=[Link];
int m2=right[0].length;
int nMax,mMax;
int i,j;
if(m1=m2) mMax=m1;
else mMax=m2;
if(n1=n2) nMax=n1;
else nMax=n2;
double b[][];
b=new double[nMax][mMax];
for(i=0;i<n1;i++)
{
for(j=0;j<m1;j++)
{
b[i][j]=b[i][j]+left[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<m2;j++)
{
b[i][j]=b[i][j]+right[i][j];
}
}
return b;
//end of matrix addition method
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] substract(double[][] left,double[][] right)
{
//addition of two matrices
int n1=[Link];
int m1=left[0].length;
int n2=[Link];
int m2=right[0].length;
int nMax,mMax;
int i,j;
if(m1=m2) mMax=m1;
else mMax=m2;
if(n1=n2) nMax=n1;
else nMax=n2;
double b[][];
b=new double[nMax][mMax];
for(i=0;i<n1;i++)
{
for(j=0;j<m1;j++)
{
b[i][j]=b[i][j]+left[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<m2;j++)
{
b[i][j]=b[i][j]-right[i][j];
}
}
return b;
//end of matrix substraction method
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//============== division of the matrices
public static double[][] divide(double[][] left,double[][] right)
{
//division of two matrices
int n=[Link];
int m=right[0].length;
double b[][];
b=new double[n][m];
b=[Link]([Link](right),left);
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
b=b+[Link](left[i][j]);
}
return b;
}
//===============special matrices==============================
public static double[][] Transpose(double [][] left)
{
//transpose matrix (if A=a(i,j) Transpose(A)=a(j,i)
int i,j;
int n=[Link];
int m=left[0].length;
double b[][];
b=new double[m][n];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[j][i]=left[i][j];
}
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static complex[][] T(complex [][] left)
{
//transpose matrix (if A=a(i,j) T(A)=a(j,i)
int i,j;
int n=[Link];
int m=left[0].length;
complex b[][];
b=new complex[m][n];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[j][i]=new complex(left[i][j]);
}
}
return b;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return a;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
last=0;
g=1.0/f;
for(j=1;j<=n;j++) { a[i-1][j-1]*=g; }
for(j=1;j<=n;j++) { a[j-1][i-1]*=f; }
} //end of if( ((c+r..
}//end of for(i=1;i<=n....
} //end of while last==0
return a;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
y=a[i-1][m-2];
if(y!=0.0)
{
y=y/x;
a[i-1][m-2]=y;
for(j=m;j<=n;j++)
{
a[i-1][j-1]-=y*a[m-1][j-1];
}
for(j=1;j<=n;j++)
{
a[j-1][m-1]+=y*a[j-1][i-1];
}
}//end of if(y!=0..
}//end of for(i=(m+1)...
} //end of if(x != 0.0...
}//end of for(m=2;m<=(n-1)..
}//end of Hessenberg
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(i(j+1)) a[i-1][j-1]=0;
}
return a;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if (l == nn) {
wr[nn]=x+t;
wi[nn--]=0.0;
}
else {
y=a[nn-1][nn-1];
w=a[nn][nn-1]*a[nn-1][nn];
if (l == (nn-1)) {
p=0.5*(y-x);
q=p*p+w;
z=[Link]([Link](q));
x += t;
if (q = 0.0) {
z=p+[Link](z,p);
wr[nn-1]=wr[nn]=x+z;
if (z!=0) wr[nn]=x-w/z;
wi[nn-1]=wi[nn]=0.0;
}
else {
wr[nn-1]=wr[nn]=x+p;
wi[nn-1]= -(wi[nn]=z);
}
nn -= 2;
}
else {
if (its == 30) [Link]("Too many iterations in hqr");
if (its == 10 || its == 20) {
t += x;
for (i=1;i<=nn;i++) a[i][i] -= x;
s=[Link](a[nn][nn-1])+[Link](a[nn-1][nn-2]);
y=x=0.75*s;
w = -0.4375*s*s;
}
++its;
for (m=(nn-2);m=l;m--) {
z=a[m][m];
r=x-z;
s=y-z;
p=(r*s-w)/a[m+1][m]+a[m][m+1];
q=a[m+1][m+1]-z-r-s;
r=a[m+2][m+1];
s=[Link](p)+[Link](q)+[Link](r);
p /= s;
q /= s;
r /= s;
if (m == l) break;
u=[Link](a[m][m-1])*([Link](q)+[Link](r));
v=[Link](p)*([Link](a[m-1][m-1])+
[Link](z)+[Link](a[m+1][m+1]));
if ((double)(u+v) == v) break;
}
for (i=m+2;i<=nn;i++) {
a[i][i-2]=0.0;
if (i != (m+2)) a[i][i-3]=0.0;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for (k=m;k<=nn-1;k++) {
if (k != m) {
p=a[k][k-1];
q=a[k+1][k-1];
r=0.0;
if (k != (nn-1)) r=a[k+2][k-1];
if ((x=[Link](p)+[Link](q)+[Link](r)) != 0.0) {
p /= x;
q /= x;
r /= x;
}
}
if ((s=[Link]([Link](p*p+q*q+r*r),p)) != 0.0) {
if (k == m) {
if (l != m)
a[k][k-1] = -a[k][k-1];
}
else
a[k][k-1] = -s*x;
p += s;
x=p/s;
y=q/s;
z=r/s;
q /= p;
r /= p;
for (j=k;j<=nn;j++) {
p=a[k][j]+q*a[k+1][j];
if (k != (nn-1)) {
p += r*a[k+2][j];
a[k+2][j] -= p*z;
}
a[k+1][j] -= p*y;
a[k][j] -= p*x;
}
mmin = nn<k+3 ? nn : k+3;
for (i=l;i<=mmin;i++) {
p=x*a[i][k]+y*a[i][k+1];
if (k != (nn-1)) {
p += z*a[i][k+2];
a[i][k+2] -= p*r;
}
a[i][k+1] -= p*q;
a[i][k] -= p;
}
}
}
}
}
} while (l < nn-1);
}
for(i=0;i<n;i++)
{
rm[0][i]=wr[i+1];
rm[1][i]=wi[i+1];
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return rm;
} //end of QR
//roots of a polynomial
public static double[][] poly_roots(double c[])
{
//roots of a degree n polynomial
// P(x)=c[n]*x^n+c[n-1]*x^(n-1)+....+c[1]*x+c[0]=0;
int n=[Link]-1;
double a[][]=new double[n][n];
a=characteristic_matrix(c);
double d[][]=new double[2][n];
d=balancedEigenValue(a);
return d;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double d[][]=new double[2][n];
d=balancedEigenValue(a);
complex e[]=new complex[n];
for(int i=0;i<n;i++)
e[i]=new complex(d[0][i],d[1][i]);
return e;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for (k=1;k<=j;k++)
g += a[j-1][k-1]*a[i-1][k-1];
for (k=j+1;k<=l;k++)
g += a[k-1][j-1]*a[i-1][k-1];
e[j-1]=g/h;
f += e[j-1]*a[i-1][j-1];
}
hh=f/(h+h);
for (j=1;j<=l;j++) {
f=a[i-1][j-1];
e[j-1]=g=e[j-1]-hh*f;
for (k=1;k<=j;k++)
a[j-1][k-1] -= (f*e[k-1]+g*a[i-1][k-1]);
}
}
} else
e[i-1]=a[i-1][l-1];
d[i-1]=h;
}
d[1-1]=0.0;
e[1-1]=0.0;
/* Contents of this loop can be omitted if eigenvectors not
wanted except for statement d[i-1]=a[i-1][i-1]; */
for (i=1;i<=n;i++) {
l=i-1;
if (d[i-1] != 0) {
for (j=1;j<=l;j++) {
g=0.0;
for (k=1;k<=l;k++)
g += a[i-1][k-1]*a[k-1][j-1];
for (k=1;k<=l;k++)
a[k-1][j-1] -= g*a[k-1][i-1];
}
}
d[i-1]=a[i-1][i-1];
a[i-1][i-1]=1.0;
for (j=1;j<=l;j++) a[j-1][i-1]=a[i-1][j-1]=0.0;
}
return a;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int n=[Link];
int m,l,iter,i,j,k;
double s,r,p,g,f,dd,c,b;
for (i=2;i<=n;i++) e[i-2]=e[i-1];
e[n-1]=0.0;
double z[][]=new double[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
z[i][j]=a[i][j];
for (l=1;l<=n;l++) {
iter=0;
do {
for (m=l;m<=n-1;m++) {
dd=[Link](d[m-1])+[Link](d[m]);
if ((double)([Link](e[m-1])+dd) == dd) break;
}
if (m != l) {
if (iter++ == 30) [Link]("Too many iterations in QL");
g=(d[l]-d[l-1])/(2.0*e[l-1]);
r=[Link](g,1.0);
g=d[m-1]-d[l-1]+e[l-1]/(g+[Link](r,g));
s=c=1.0;
p=0.0;
for (i=m-1;i=l;i--) {
f=s*e[i-1];
b=c*e[i-1];
e[i]=(r=[Link](f,g));
if (r == 0.0) {
d[i] -= p;
e[m-1]=0.0;
break;
}
s=f/r;
c=g/r;
g=d[i ]-p;
r=(d[i-1]-g)*s+2.0*c*b;
d[i ]=g+(p=s*r);
g=c*r-b;
for (k=1;k<=n;k++) {
f=z[k-1][i ];
z[k-1][i ]=s*z[k-1][i-1]+c*f;
z[k-1][i-1]=c*z[k-1][i-1]-s*f;
}
}
if (r == 0.0 && i = l) continue;
d[l-1] -= p;
e[l-1]=g;
e[m-1]=0.0;
}
} while (m != l);
}
return z;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] eigenQL(double a[][])
{
// QL algoritm to solve eigen value problems
// symmetric matrices only (real eigen values)
// first column of the matrix returns eigen values
// second..n+1 column returns eigen vectors.
// Note : If matrix is not symmetric DO NOT use
// this method use eigenValue method (a QR algorithm)
int i,j;
int n=[Link];
double sum[]=new double[n];;
double d[]=new double[n];
double b[][]=new double[n][n];
double e[]=new double[n];
double z[][]=new double[n+1][n];
b=tridiagonal(a,d,e);
b=QL(d,e,b);
for(j=0;j<n;j++)
{
z[0][j]=d[j];
for(i=0;i<n;i++)
{
z[i+1][j]=b[i][j]/b[0][j];
if(z[i+1][j]<1e-13) z[i+1][i]=0;
}
}
return z;
}
Ýnverse matris : Inverse matrisi hesaplar. Buradaki temel hesaplama yolu tam pivotlu gauss
eliminasyon metodudur. Bu metod göreceli olarak küçük matrisler içindir. dev boyutlardaki
matrisler için tavsiye edilmez. Çok büyük boyutlarda iterativ metodlar daha az sayýda iºlemle
çözüme gidebilir. Bu metod hassas sonuç verebilme özelliðinden dolayý seçilmiºtir. ayný
zamanda LU (alt ve üst üçgen matris) parçalama metoduyla da çözebiliriz. Bu metodun
avantajý lineer bir denklem sistemi çözerken eðer ikinci taraf sürekli deðiºiyorsa ortaya çýkar.
tek bir çözüm için ilave bir avantaj getirmez.
import [Link].*;
import Numeric;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class Matrix3
{
public static void main(String args[]) throws IOException
{
/*
double a[][];
a=new double[5][5];
a[0][0]=1;
a[0][1]=2;
a[0][2]=0;
a[0][3]=0;
a[0][4]=0;
a[1][0]=-2;
a[1][1]=3;
a[1][2]=0;
a[1][3]=0;
a[1][4]=0;
a[2][0]=3;
a[2][1]=4;
a[2][2]=50;
a[2][3]=0;
a[2][4]=0;
a[3][0]=-4;
a[3][1]=5;
a[3][2]=-60;
a[3][3]=7;
a[3][4]=0;
a[4][0]=-5;
a[4][1]=6;
a[4][2]=-70;
a[4][3]=8;
a[4][4]=-9;
*/
double c[][]=new double[5][5];
double a[][]={{1,2,0,0,0},{-2,3,0,0,0},{3,4,50,0,0},{-4,5,-60,7,0},
{-5,6,-70,8,-9}};
double b[]=new double[5];
int d[]=new int[1];
b[0]=1;
b[1]=0;
b[2]=0;
b[3]=0;
b[4]=0;
[Link]("Original Matrix : ");
[Link]([Link](a));
[Link]("Inverse Matrix : (Method inv) ");
[Link]([Link]([Link](a)));
[Link]("Matrix * Inverse Matrix : (Method multiply) ");
[Link]([Link]([Link](a,[Link](a))));
[Link]("Solution of system of equation : ");
[Link]("with second side : ");
[Link]([Link](b));
[Link]([Link]([Link](b,a)));
int indx[]=new int[5];
d[0]=0;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
c=[Link](a,indx,d);
[Link]("LU decomposed matrix : (Method LU) ");
[Link]([Link](c));
[Link]("Matrix inversion by LU decomposition : (Method LUinv)");
[Link]([Link]([Link](a)));
[Link]("Matrix * Inverse Matrix (LU Decomposition) :");
[Link]([Link]([Link](a,[Link](a))));
}
}
Original Matrix :
1.0 2.0 0.0 0.0 0.0
-2.0 3.0 0.0 0.0 0.0
3.0 4.0 50.0 0.0 0.0
-4.0 5.0 -60.0 7.0 0.0
-5.0 6.0 -70.0 8.0 -9.0
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
0.0
0.0
0.4285714285714286
0.2857142857142857
-0.048571428571428564
-0.37551020408163255
-0.003628117913832162
import [Link].*;
import Numeric;
class Matrix5
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//calculation of an inverse matrix
double a[][];
a=new double[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
[Link]("Matrix : ");
[Link]([Link](a));
[Link]([Link]([Link](a)));
[Link]([Link]([Link](a,[Link](a))));
[Link]("Determinant = "+[Link](a));
Matrix :
1.0 2.0
3.0 4.0
Inverse Matrix :
-2.0 1.0
1.5 -0.5
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1.0 0.0
0.0 1.0
Determinant = -2.0
EigenValue - Sýnýr deðer problemi : matislerle ilgili belki de en ilginç proses eigen
value - sýnýr deðer problemidir. Sýnýr deðer hesaplamalarý iteratif bir problemdir. Simetrik
matrislerde sonuçlar gerçek sayý olarak çýkar. bu tür uygulamalarda QL metodu
kullanýlabilir. Simetrik olmayan matrislerin sýnýr deðerleri kompleks deðerlerdir (kompleks
ve gerçek deðerlerin karýºýmý olabilir.) burada temel olarak QR formülü kullanýlmýºtýr.
Eigen value problemleriyle direk olarak ilgili ilginç bir problem de ninci dereceden bir
polinomun köklerinin hesaplanmasý problemidir. polinom karakteristik matris ismi verilen
özel bir matrise dönüºtürülebilir. Bu matrisin eigen-value deðerleri polinomun da
kökleridir.
import [Link].*;
import Numeric;
class Matrix1
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String args[]) throws IOException
double c[][];
c=new double[5][5];
{-4,5,-60,7,0},{-5,6,-70,8,-9}};
[Link]("Matris : ");
[Link]([Link](a));
complex c1[];
int n=[Link];
c1=new complex[n];
c1=[Link](a);
[Link]([Link](c1));
Matris :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
50.0
(2.000000000000002 - 1.732050807568873i )
(2.000000000000002 + 1.732050807568873i )
7.000000000000001
-8.999999999999998
import [Link].*;
import Numeric;
class Matrix4
double a[][]=Matrix.characteristic_matrix(p);
[Link]([Link](p));
[Link]([Link](a));
[Link]([Link]([Link](a)));
[Link]([Link]([Link](a)));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("Polinomun kokleri : (poly_roots) ");
[Link]([Link](Matrix.poly_roots(p)));
[Link]([Link](Matrix.poly_rootsC(p)));
cözüm :
Orijinal Polinom :
Karekteristik matris :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Polinomun kokleri : (poly_roots)
Determinant ,
import [Link].*;
import Numeric;
class Matrix5
{
public static void main(String args[]) throws IOException
{
//calculation of an inverse matrix
double a[][];
a=new double[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
[Link]("Matrix : ");
[Link]([Link](a));
[Link]("Inverse Matrix : ");
[Link]([Link]([Link](a)));
[Link]("Matrix * Inverse Matrix :");
[Link]([Link]([Link](a,[Link](a))));
[Link]("Determinant = "+[Link](a));
}
}
cözümü :
Matrix :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1.0 2.0
3.0 4.0
Inverse Matrix :
-2.0 1.0
1.5 -0.5
1.0 0.0
0.0 1.0
Determinant = -2.0
Eigenvalue, EigenVektör : Burada verilen matris simetrik bir matristir. sýnýr deðer vektörü
QL metodu kullanýlarak hesaplanmýºtýr. Simetrik matris olduðundan sýnýr deðerler gerçek
deðerler olarak elde edilmiºtir.
import [Link].*;
import Numeric;
class Matrix6
{
public static void main(String args[]) throws IOException
{
//Eigen Value calculations using QL method
double a[][]={{3,-1,0},{-1,2,-1},{-0,-1,3}};
[Link]("Original Matrix : ");
[Link]([Link](a));
[Link]("eigen values and Eigen Vectors : ");
[Link]([Link]([Link](a)));
}
}
çözümü :
Original Matrix :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
eigen values and Eigen Vectors :
Numeric sýnýfý genel bir sayýsal analiz paketi olarak düºünülmüºtür. Bu pakette benim kiºisel
ihtiyaçlarým için yazdýðým yada baºka dillerde daha önceden yazýlmýº olan kodlardan adepte
ettiðim bazý programlar verilmiºtir. Bir paketin genel olarak herhangi bir fonksiyonla
kullanýlabilmesi için herhangi bir fonksiyonla birlikte kullanýlmasý gerekir. Bu yüzden
programlarda fonksiyonlar tanýmlanmýº abstract sýnýflar içinde yer almýºtýr. Gerçek
fonksiyonlar yazýlýrken abstract sýnýflardan türetilmeleri gerekmektedir. Numeric paketindeki
ve abstract sýnýflar ve metodlar ºu ºekilde tanýmlanmýºtýr :
veya
f1 xkare=new f1();
double y=[Link](xkare,x);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ºeklinde çaðýrýlýr.
örnek
f[0] = x[0]+sin(x[1]);
f[1] = x[0]*x[0]-x[1] ;
double a=0;
return a; } }
double x[]={1,2};
veya
double x[]={1,2};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
f2 xkare=new f2();
double y=[Link](xkare,x,0);
ºeklinde gerçekleºtirilir.
örnek
f[0]=x[0]+sin(x[1]);
f[1]=x[0]*x[0]-x[1];
a[0] = x[0]+sin(x[1]);
a[1] = x[0]*x[0]-x[1];
return a; }
double x[]={1,2};
veya
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double x[]={1,2};
f3 fx=new f3();
double y[]=[Link](fx,x);
ºeklinde gerçekleºtirilir.
örnek :
f[0][0]=x[0]+[Link](x[1]) f[0][1]=x[0]-x[1]
f[1][0]=x[0]*x[0]-x[1] f[1][1]=[Link](x[0]+x[1]*x[1]
f[0][0], f[0][1]
f[1][0], f[1][1]
double b[][];
f=new double[2][2];
f[0][0]= x[0]+[Link](x[1]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
f[0][1]= x[0]-x[1];
f[1][0]= x[0]*x[0]-x[1];
f[1][1]= [Link](x[0]+x[1]*x[1];
return f;
double x[]={1,2};
veya
double x[]={1,2};
f4 fx=new f4();
double y[][]=[Link](fx,x);
Türev : bu metotlar gurubu yukarýda tanýmlanan double sayý, vektor ve matris olarak verilen
bir fonksiyonun türevlerini alýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
türevin alýnacaðý nokta : double x
fi/xj
örnek fonksiyon
f[0] = x[0]+sin(x[1]);
f[1] = x[0]*x[0]-x[1] ;
fonksiyon abstract sýnýfý : f_xi
yukarýdaki örnek için türevin alýnacaðý nokta : double x[] ile belirlenmiºtir
fi/xj
örnek fonksiyon
f[0] = x[0]+sin(x[1]);
f[1] = x[0]*x[0]-x[1] ;
fonksiyon abstract sýnýfý : f_xi
yukarýdaki örnek için türevin alýnacaðý nokta : double x[] ile belirlenmiºtir
not1 : bir üsteki türev formülüyle bu türev formülünün temel farký, burada tanýmlanan
fonksiyonun tüm vektörü çýktý olarak vermesidir. sonuçlar her ikisinde de aynýdýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
fonksiyonlar için hassas deðerler vermiºtir. Nümerik türevlerle çözülmesi oldukça zor
olan boyutlu newton-raphson tekniðinde bile baºarýlý sonuçlar vermiºtir. Daha küçük
deðerler kullanýrken önce türevini bildiðiniz fonksiyonlarla sonuçlarý kontrol etmeniz
tavsiye edilir.
Ýntegral: Sayýsal olarak integral almak için çok çeºitli integrasyon metotlarý bulunmaktadýr.
Burada verilen metodlarda ana kriteria sonuçlarýn hassaslýðýdýr. Denklemler nümerik olarak
doðru sonuç çýkarmasý oldukça zor olan siyah cisim radyasyon fonksiyonu ve istatistik
fonksiyonlarda bile tam hassaslýk vermiºtir. integral 30 noktalý Gauss - Legendre integral
formülü kullanmaktadýr. trap, trapezoidal integral formülü romberg integrasyonunun temelini
teºkil etmek için hazýrlanmýºtýr, tekbaºýna da kullanýlabilir. Çok hassasiyet gereken
uygulamalarýnýz için kullanmanýzý tavsiye etmiyoruz. Romberg integrasyonu iterativ bir
integrasyon tekniðidir. Trapezoidal integrasyonla hesaplanan kök deðerlerini alarak
iterasyonla hata miktarýný azaltýr.
public static void trap (f_x ff,double a,double h, int j,int m,double R[][])
Non-linear denklem kökleri : non linear denklem veya denklem sistemlerinin çözümü
nümerik analizde en çok karºýmýza çýkan problemlerden biridir. Genelde tüm metodlar iteratif
yöntemler kullanýrlar. Bu metodlar içinde en verimli olarak hesap yapan metodun newton
metodu olduðu söylenebilir, fakat newton metodu fonksiyonun türevinin de hesaplanmasýný
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
gerekli kýlar. buradaki metodlarýn bir kýsmýnda türev girdi olarak alýnýrken, bir kýsmýnda da
yine nümerik metodlarla hesaplanmýºtýr. denklemin ikinci türevini de göz önüne alan
newton_2nd_derivative gibi metodlar da verilmiºtir. ayrýca secant, bisection gibi türev hesabý
gerektirmeyen metodlar da mevcuttur. Bisection metodu temelde bir arama metodudur ve
verimi en düºük metoddur, fakat verilen bölgeyi tam olarak taradýðý ve bir kök varsa
muhakkak bulabildiði için verimsiz bir metod için oldukça sýk tercih gören bir yöntemdir.
dy=2*x
fonksiyon abstract sýnýfý : f_x
dy=2*x
fonksiyon abstract sýnýfý : f_x
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double secant_2nd_derivative(double x,f_x y)
y(x) fonksiyonunun kökleri, 2nci türev formülü, secand metodu kullanýlmýºtýr (türev
formülü gerekmez)
örnek fonksiyon
y1=2*x1*x1*x2-3*x1
y2=2*x1+2*x2
dy1/dx1=4*x1*x2-3 dy1/dx2=2*x1
dy2/dx1=2 dy2/dx2=2
fonksiyon abstract sýnýfý : fi_xi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[] newton( double x[],fij_xi y)
yi (xi) fonksiyon sisteminin kökleri kökleri, dyi (x)/dx j fonksiyonu nümerik olarak
hesaplanmaktadýr, girdi deðildir.
örnek fonksiyon
y1=2*x1*x1*x2-3*x1
y2=2*x1+2*x2
polynom least square (en küçük kareler metodu) polinom uydurma, polinomun
katsayýlarýný kullanarak fonksiyon deðerini hesaplar
örnek çaðýrma : double y=Numeric. f_least_square (e,x);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
örnek çaðýrma : double y[]=Numeric. Orthogonal_polynomial_least_square (xi,yi,n);
ortogonal polynom least square (en küçük kareler metodu) polinom uydurma,
polinomun katsayýlarýný
Diferansiyel denklemler
4üncü dereceden Runge-Kutta diferansiyal denklem çözüm metodu, tek bir denklemi
çözmek için
örnek çaðýrma : double y[]=RK4 (new fxi(),x0,xn,N);
sistemini veya daha yüksek dereceden diferansiyel denklemleri çözmek için kulanýlýr.
//=============================================================
// Numerical Analysis Package in Java
// Numerical analysis calculation class Numeric
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Author : Dr. Turhan Coban
//=============================================================
import [Link].*;
import Matrix;
// f[0][0]=x[0]+[Link](x[1]) f[0][1]=x[0]-x[1]
// f[1][0]=x[0]*x[0]-x[1] f[1][1]=[Link](x[0]+x[1]*x[1]
// func(x) returns the value of f[0][0], f[0][1]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// f[1][0], f[1][1]
// as a two dimensional matrix
int i,m;
int n=7;
//derivative of a simple function
double T[][];
T=new double[n][n];
double h[];
h=new double[n];
//vector<double h(n,0);
for(i=0;i<n;i++)
{
h[i]=0;
for(int j=0;j<n;j++)
T[i][j]=0;
}
h[0]=h0;
double r=0.5;
for( i=1;i<n;i++)
{
h[i]=h0*[Link](r,i);
}
for(i=0;i<n;i++)
{
T[i][0]=( f_deriv.func(x + h[i]) - f_deriv.func( x - h[i]))/(2.0*h[i]);
}
for(m=1;m<n;m++)
{
for(i=0;i<n-m;i++)
{
T[i][m]=(h[i]*h[i]*T[i+1][m-1] - h[i+m]*h[i+m]*T[i][m-1])/
(h[i]*h[i]- h[i+m]*h[i+m]);
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double xx=T[0][n-1];
return xx;
}
for(i=0;i<n;i++)
{
x1[x_ref]+=h[i];
x2[x_ref]-=h[i];
T[i][0]=( f_deriv.func(x1,equation_ref) -
f_deriv.func(x2,equation_ref))/(2.0*h[i]);
x1[x_ref]=x[x_ref];
x2[x_ref]=x[x_ref];
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(m=1;m<n;m++)
{
for(i=0;i<n-m;i++)
{
T[i][m]=(h[i]*h[i]*T[i+1][m-1] -
h[i+m]*h[i+m]*T[i][m-1])/(h[i]*h[i] - h[i+m]*h[i+m]);
}
}
double xx=T[0][n-1];
return xx;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
h[i]=h0*[Link](r,i);
}
for(i=0;i<n;i++)
{
x1[x_ref]+=h[i];
x2[x_ref]-=h[i];
f1=f_deriv.func(x1);
f2=f_deriv.func(x2);
T[i][0]=( f1[equation_ref] - f2[equation_ref])/(2.0*h[i]);
x1[x_ref]=x[x_ref];
x2[x_ref]=x[x_ref];
}
for(m=1;m<n;m++)
{
for(i=0;i<n-m;i++)
{
T[i][m]=(h[i]*h[i]*T[i+1][m-1] - h[i+m]*h[i+m]*T[i][m-1])/(h[i]*h[i]
- h[i+m]*h[i+m]);
}
}
double xx=T[0][n-1];
return xx;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s[20] = .76831207407100990000E+00;
s[21] = .81026309149462140000E+00;
s[22] = .84892524739665800000E+00;
s[23] = .88388871605241310000E+00;
s[24] = .91478288119138420000E+00;
s[25] = .94128026789602640000E+00;
s[26] = .96310002371463720000E+00;
s[27] = .98001093248415370000E+00;
s[28] = .99183406163987350000E+00;
s[29] = .99844674203732480000E+00;
w[ 0] = .39840962480827790000E-02;
w[ 1] = .92332341555455000000E-02;
w[ 2] = .14392353941661670000E-01;
w[ 3] = .19399596284813530000E-01;
w[ 4] = .24201336415292590000E-01;
w[ 5] = .28746578108808720000E-01;
w[ 6] = .32987114941090080000E-01;
w[ 7] = .36877987368852570000E-01;
w[ 8] = .40377947614710090000E-01;
w[ 9] = .43449893600541500000E-01;
w[10] = .46061261118893050000E-01;
w[11] = .48184368587322120000E-01;
w[12] = .49796710293397640000E-01;
w[13] = .50881194874202750000E-01;
w[14] = .51426326446779420000E-01;
w[15] = .51426326446779420000E-01;
w[16] = .50881194874202750000E-01;
w[17] = .49796710293397640000E-01;
w[18] = .48184368587322120000E-01;
w[19] = .46061261118893050000E-01;
w[20] = .43449893600541500000E-01;
w[21] = .40377947614710090000E-01;
w[22] = .36877987368852570000E-01;
w[23] = .32987114941090080000E-01;
w[24] = .28746578108808720000E-01;
w[25] = .24201336415292590000E-01;
w[26] = .19399596284813530000E-01;
w[27] = .14392353941661670000E-01;
w[28] = .92332341555455000000E-02;
w[29] = .39840962480827790000E-02;
int n=30;
double z=0;
double x,y;
for(i=0;i<n;i++)
{
x=(b+a)/2.0+(b-a)/2.0*s[i];
y=f_xnt.func(x);
z+=(b-a)/2*w[i]*y;
}
for(i=0;i<n;i++)
{
x=(b+a)/2.0+(b-a)/2.0*(-s[i]);
y=f_xnt.func(x);
z+=(b-a)/2.0*w[i]*y;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return z;
}
public static void trap(f_x ff,double a,double h, int j,int m,double R[][])
{
// successive trapezoidal integration rule
// this program will be utilised in romberg integration
double sum=0;
int p;
for(p=1;p<=m;p++)
{ sum+=[Link](a+h*(2*p-1)); }
R[j][0]=R[j-1][0]/2.0+h*sum;
}
//==================================================
//Finding Non-linear Roots of Functions
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
int nmax=500;
double tolerance=1.0e-15;
double fx,dfx;
for(int i=0;i<nmax;i++)
{
fx=[Link](x);
dfx=[Link](x);
x-=fx/dfx;
if([Link](fx)<tolerance)
{
return x;
}
}
return x;
}
int nmax=500;
double tolerance=1.0e-15;
double fx,dfx;
for(int i=0;i<nmax;i++)
{
fx=[Link](x);
dfx=[Link](y,x);
x-=fx/dfx;
if([Link](fx)<tolerance)
{
return x;
}
}
return x;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
dfxm=[Link](x-dx);
d2fx=-6.0/dx/dx*(fx-fxm)+2.0/dx*(2.0*dfx+dfxm);
x-=(fx/dfx+.5*fx*fx/(dfx*dfx*dfx)*d2fx);
if([Link](fx)<tolerance)
{
return x;
}
}
return x;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
fx=[Link](x);
fxm=[Link](x-dx);
fxm1=[Link](x-dx1);
dfx=(fx-fxm)/dx;
dfxm=(fx-fxm1)/dx1;
d2fx=-6.0/dx/dx*(fx-fxm)+2.0/dx*(2.0*dfx+dfxm);
x-=(fx/dfx+.5*fx*fx/(dfx*dfx*dfx)*d2fx);
if([Link](fx)<tolerance)
{
return x;
}
}
return x;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[] newton( double x[],fi_xi y,fij_xi dy)
{
//solution of nonlinear system of equations
//by using newton raphson method.
//ti :weigth factor
//x independent value vector:
//y dependent function vector
//dy derivative of dependent function matrix
double ti=1.0;
int i;
int nmax=500;
double tolerance=1.0e-30;
int n=[Link];
double b[];
b=new double[n];
for(i=0;i<n;i++)
{
b[i]=1.0;
}
i=0;
while( i++ < nmax && [Link](b) tolerance )
{
b=[Link]([Link]([Link](x),[Link](x)),-ti);
x=[Link](x,b);
}
if(i = nmax) [Link]("warning maximum number"+
" of iterations results may not be valid");
return x;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
for(ii=0;ii<n;ii++)
{
for(jj=0;jj<n;jj++)
{
dy[ii][jj]=[Link](y,ii,x,jj);
}
}
b=[Link]([Link]([Link](x),dy),-ti);
x=[Link](x,b);
}
if(i = nmax) [Link]("warning maximum number of iterations"+
" results may not be valid" );
return x;
}
for(i=0;i<n+1;i++)
{
for(j=0;j<n+1;j++)
{
if(i==0 && j==0)
A[i][j]=l;
else
for(k=0;k<l;k++)
A[i][j] += [Link](xi[k],(i+j));
}
for(k=0;k<l;k++)
{
if(i==0)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
B[i]+= yi[k];
else
B[i] += [Link](xi[k],i)*yi[k];
}
}
X=[Link](B,A);
//X=B/A;
double max=0;
for(i=0;i<n+1;i++)
if([Link](X[i]) max) max = [Link](X[i]);
for(i=0;i<n+1;i++)
if(([Link](X[i]/max) 0) && ([Link](X[i]/max) < 1.0e-11)) X[i]=0;
return X;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double[][] orthogonal_polynomial_least_square
(double xi[],double fi[],int m)
//orthogonal polynomial least square curve fitting
//this method do not require any matrix solution
//variables xi,fi vector of data points wi weight functions
//m degree of curve fitting
{
int i,j,k;
int n=[Link];
int mp2=n+2;
int mp1=n+1;
//matrix<double p(m+2,n,0);
double p[][];
p=new double[mp2][n];
//vector<double gamma(m+1,0);
double gamma[];
gamma=new double[mp1];
//vector<double beta(m+1,0);
double beta[];
beta=new double[mp1];
//vector<double omega(m+1,0);
double omega[];
omega=new double[mp1];
//vector<double alpha(m+1,0);
double alpha[];
alpha=new double[mp1];
//vector<double b(m+1,0);
double b[];
b=new double[mp1];
//vector<double wi(n,1.);
double wi[];
wi=new double[n];
//matrix<double a(3,m+1);
double a[][];
a=new double[3][mp1];
for(i=0;i<n;i++)
{
p[1][i]=1.0;
p[0][i]=0.0;
}
gamma[0]=0;
for(i=0;i<n;i++)
{
gamma[0]+=wi[i];
}
beta[0]=0.0;
for(j=0;j<m+1;j++)
{
omega[j]=0;
for(i=0;i<n;i++)
{
omega[j]+=wi[i]*fi[i]*p[j+1][i];
}
b[j]=omega[j]/gamma[j];
if( j != m)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
alpha[j+1]=0;
for(i=0;i<n;i++)
{
alpha[j+1]+=wi[i]*xi[i]*p[j+1][i]*p[j+1][i]/gamma[j];
}
for(i=0;i<n;i++)
{
p[j+2][i]=(xi[i]-alpha[j+1])*p[j+1][i]-beta[j]*p[j][i];
}
gamma[j+1]=0;
for(i=0;i<n;i++)
{
gamma[j+1]+=wi[i]*p[j+2][i]*p[j+2][i];
}
beta[j+1]=gamma[j+1]/gamma[j];
}
}//end of j
for(j=0;j<m+1;j++)
{
a[0][j]=b[j];
a[1][j]=alpha[j];
a[2][j]=beta[j];
}
return a;
}
double yy=0;
int k;
int m=a[0].length-1;
int mp2=m+2;
double q[];
q=new double[mp2];
//vector<double q(m+2,0.0);
for(k=m-1;k=0;k--)
{
q[k]=a[0][k]+(x-a[1][k+1])*q[k+1]-a[2][k+1]*q[k+2];
yy=q[k];
}
return yy;
}
//minimization of a function
public static double amotry(double p[][], double y[], double psum[], int ndim,
f_xi ff, int ihi, double fac)
{
int j;
double fac1,fac2,ytry;
double ptry[]=new double[ndim];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
fac1=(1.0-fac)/ndim;
fac2=fac1-fac;
for (j=1;j<=ndim;j++) ptry[j-1]=psum[j-1]*fac1-p[ihi-1][j-1]*fac2;
ytry=[Link](ptry,0);
if (ytry < y[ihi-1]) {
y[ihi-1]=ytry;
for (j=1;j<=ndim;j++) {
psum[j-1] += ptry[j-1]-p[ihi-1][j-1];
p[ihi-1][j-1]=ptry[j-1];
}
}
return ytry;
}
public static void amoeba(double p[][], double y[], int ndim, double ftol,
f_xi ff, int nfunk)
{
int i,ihi,ilo,inhi,j,mpts=ndim+1;
int NMAX=5000;
double rtol,sum,swap,ysave,ytry;
double psum[]=new double[ndim];
nfunk=0;
for (j=1;j<=ndim;j++)
{
for (sum=0.0,i=1;i<=mpts;i++) sum += p[i-1][j-1];
psum[j-1]=sum;
}
for (;;) {
ilo=1;
//ihi = y[1]y[2] ? (inhi=2,1) : (inhi=1,2);
if(y[0]y[1])
{
inhi=2;
ihi=1;
}
else
{
inhi=1;
ihi=2;
}
for (i=1;i<=mpts;i++) {
if (y[i-1] <= y[ilo-1]) ilo=i;
if (y[i-1] y[ihi-1]) {
inhi=ihi;
ihi=i;
} else if (y[i-1] y[inhi-1] && i != ihi) inhi=i;
}
rtol=2.0*[Link](y[ihi-1]-y[ilo-1])
/([Link](y[ihi-1])+[Link](y[ilo-1]));
if (rtol < ftol) {
swap=y[0];
y[0]=y[ilo-1];
y[ilo-1]=swap;
for (i=1;i<=ndim;i++)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
swap=p[0][i-1];
p[0][i-1]=p[ilo-1][i-1];
p[ilo-1][i-1]=swap;
}
break;
}
if (nfunk = NMAX) [Link]("NMAX exceeded");
nfunk += 2;
ytry=amotry(p,y,psum,ndim,ff,ihi,-1.0);
if (ytry <= y[ilo-1])
ytry=amotry(p,y,psum,ndim,ff,ihi,2.0);
else if (ytry = y[inhi-1]) {
ysave=y[ihi-1];
ytry=amotry(p,y,psum,ndim,ff,ihi,0.5);
if (ytry = ysave) {
for (i=1;i<=mpts;i++) {
if (i != ilo) {
for (j=1;j<=ndim;j++)
psum[j-1]=0.5*(p[i-1][j-1]+p[ilo-1][j-1]);
p[i-1][j-1]=psum[j-1];
y[i]=[Link](psum,0);
}
}
nfunk += ndim;
for (j=1;j<=ndim;j++)
{
for (sum=0.0,i=1;i<=mpts;i++) sum += p[i][j];
psum[j]=sum;
}
}
} else --nfunk;
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(x=x0,i=0;x<xn;x+=h,i++)
{
xi[0]=x;
xi[1]=fi[i];
k[0]=h*[Link](xi,0);
xi[0]=x+h/2.0;
xi[1]=fi[i]+k[0]/2;
k[1]=h*[Link](xi,0);
xi[1]=fi[i]+k[1]/2.0;
k[2]=h*[Link](xi,0);
xi[0]=x+h;
xi[1]=fi[i]+k[2];
k[3]=h*[Link](xi,0);
fi[i+1]=fi[i]+k[0]/6.0+k[1]/3.0+k[2]/3.0+k[3]/6.0;
}
return fi;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return fi;
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
fi[0][j+1]=fi[0][j]+h;
fi[1][j+1]=fi[1][j]+16.0/135.0*k[0]+6656.0/12825.0*k[2]+
28561.0/56430.0*k[3]-9.0/50.0*k[4]+2.0/55.0*k[5];
j++;
}
else
{
if(Err==0) s=0;
else s=0.84*([Link](Tol*h/Err,0.25));
if(s<0.75 && h(2*Hmin) ) h/=2.0;
if(s1.5 && Hmax (2*h) ) h*=2.0;
}
}
double fj[][]=new double[2][j+1];
for(int i=0;i<=j;i++)
{
fj[0][i]=fi[0][i];
fj[1][i]=fi[1][i];
}
return fj;
}
import [Link].*;
import Numeric;
import complex;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
class Matrix2
{
public static void main(String args[]) throws IOException
{
//Solution of zero of functions of one or multivariable equations
f1 b1;
b1=new f1();
df1 db1;
db1=new df1();
f2 b2;
b2=new f2();
df2 db2;
db2=new df2();
double x[];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
x=new double[2];
x[0]=0;
x[1]=0.5;
double xx=13;
[Link]("Roots of equations : ");
[Link]("Newtons method y=f(x)=0 f(x) and df(x)/dx is given");
[Link]("Newton y,dy x= "+[Link](xx,b2,db2));
[Link]("");
[Link]("Newtons method y=f(x)=0 f(x) is given");
[Link]("Newton y, x= "+[Link](xx,b2));
[Link]("");
[Link]("Newtons method with 2nd derivative y=f(x)=0 ");
[Link]("f(x) and df(x)/dx is given ");
[Link]("Newton_2nd_derivative y,dy x= "+
Numeric.newton_2nd_derivative(xx,b2,db2));
[Link]("");
[Link]("Newtons method with 2nd derivative y=f(x)=0 ");
[Link]("f(x) is given only ");
[Link]("Newton_2nd_derivative y, x= "+
Numeric.newton_2nd_derivative(xx,b2));
[Link]("");
[Link]("Secant method with 2nd derivative y=f(x)=0 ");
[Link]("f(x) is given only ");
[Link]("Secant_2nd_derivative y, x= "+
Numeric.secant_2nd_derivative(xx,b2));
[Link]("");
[Link]("Newtons method for system of equations");
[Link]("yi=fi(xi)=0,i=0,n ");
[Link]("fi(xi) and dfi(xi)/dxj,i=1,n,j=1,n is given");
[Link](" "+[Link]([Link](x,b1,db1)));
[Link]("");
[Link]("Newtons method for system of equations");
[Link]("yi=fi(xi)=0,i=0,n ");
[Link]("fi(xi),i=1,n is given(derivative matrix is notrequired)");
[Link](" "+[Link]([Link](x,b1)));
}
}
Çözüm seti :
Roots of equations :
Newtons method y=f(x)=0 f(x) and df(x)/dx is given
Newton y,dy x= 1.895494267033981
Newtons method y=f(x)=0 f(x) is given
Newton y, x= 1.895494267033981
Newtons method with 2nd derivative y=f(x)=0
f(x) and df(x)/dx is given
Newton_2nd_derivative y,dy x= 1.895494267033981
Newtons method with 2nd derivative y=f(x)=0
f(x) is given only
Newton_2nd_derivative y, x= 1.895494267033981
Secant method with 2nd derivative y=f(x)=0
f(x) is given only
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Secant_2nd_derivative y, x= 1.895494267033981
Newtons method for system of equations
yi=fi(xi)=0,i=0,n
fi(xi) and dfi(xi)/dxj,i=1,n,j=1,n is given
1.0673460858066892
0.13922766688686042
Newtons method for system of equations
yi=fi(xi)=0,i=0,n
fi(xi),i=1,n is given(derivative matrix is notrequired)
1.0673460858066897
0.1392276668868614
//======================================================
// =====================================================
import [Link].*;
import Numeric;
import complex;
double func(double x)
return x*x;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
double func(double x)
return x;
//multivariable function
double a=0;
switch(x_ref)
case 0: a=(x[0]+x[1]*x[1]+x[2]*2);break;
case 1: a=(x[0]*3+x[1]*x[1]*x[1]+x[2]);break;
case 2: a=(x[0]-5*x[1]*x[1]+x[2]*x[2]*x[2]);break;
return a;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class fm2 extends fi_xi
//multivariable function
double a[];
a=new double[3];
a[0]=(x[0]+x[1]*x[1]+x[2]*2);
a[1]=(x[0]*3+x[1]*x[1]*x[1]+x[2]);
a[2]=(x[0]-5*x[1]*x[1]+x[2]*x[2]*x[2]);
return a;
class integ1
f1 b1;
b1=new f1();
f2 b2;
b2=new f2();
fm1 b3;
b3=new fm1();
double x[];
fm2 b4;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
b4=new fm2();
x=new double[3];
x[0]=1;
x[1]=2;
x[2]=3;
[Link](b1,0.0,1.0));
Numeric.integral_romberg(b1,0.0,1.0));
[Link](b2,0.0,1.0));
[Link](b1,1.0));
[Link](b2,1.0));
[Link](b3,1,x,0));
[Link](b4,1,x,0));
[Link](b3,1,x,0));
[Link](b4,1,x,0));
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
çözüm :
//===========================================
// Polynomial least square curve fitting
// Dr. Turhan Coban
//===========================================
import [Link].*;
import Numeric;
import Text;
class least
{
public static void main(String args[]) throws IOException
{
//polynomial least square curve fitting
double e[]; //coefficients of polynomial least square
e=new double[20];
double xi[];
xi=new double[500];
double yi[];
yi=new double[500];
DataInputStream cin=new DataInputStream([Link]);
[Link]("name of input file : ");
String in_name=[Link](cin);
[Link](" ");
DataInputStream fin=new DataInputStream(new FileInputStream(in_name));
PrintStream fout=new PrintStream(new FileOutputStream("[Link]"));
int i=-1;
try {
while(fin != null)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
i++;
xi[i]=[Link](fin);
yi[i]=[Link](fin);
[Link](" "+xi[i]+" "+yi[i]);
}
} catch(EOFException e_eof) {[Link]("end of file"); }
[Link]("degree of curve fitting : ");
int n=[Link](cin);
e=Numeric.poly_least_square(xi,yi,n);
[Link]([Link](e));
[Link]([Link](e));
[Link]("least square error : "+[Link](xi,yi,e));
[Link]("would you like to send curve fitted data to a data file (y/n) ");
char answer=[Link](cin);
if(answer=='y')
{
[Link]("name of output file : ");
String out_name=[Link](cin);
PrintStream fout1=new PrintStream(new FileOutputStream(out_name));
double xmin,xmax;
[Link]("minimum x : ");
xmin=[Link](cin);
[Link]("maximum x : ");
xmax=[Link](cin);
[Link]("number of data points : ");
int n_data=[Link](cin);
double x;
for(i=0;i<n_data;i++)
{
x=xmin+(xmax-xmin)/(n_data-1.0)*i;
[Link](" "+x+" "+Numeric.f_least_square(e,x));
[Link](" "+x+" "+Numeric.f_least_square(e,x));
} //end of for
}//end of if
}
}
least square polinom uydurma iºlevini biraz daha kullanýcýya cazip hale getirmek için grafik
formatýndaki [Link] programý geliºtirilmiºtir.
Problem 12.10 least square polinom uydurma, [Link] jFrame grafik programý
//======================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Dr. Turhan Coban
// =====================================================
/*
*/
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import Numeric;
import Text;
import [Link].*;
import [Link].*;
import Plot2D;
import PlotShapesSW;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class leastSW extends JFrame implements ItemListener,ActionListener
Plot2D jta;
StringTokenizer t;
double ee[];
double xi[];
double yi[];
BufferedReader fin;
File girdiDosyasi;
File ciktiDosyasi;
File plotDosyasi;
int nGirdi;
int nCikti;
double minX,maxX;
int PolinomDerecesi;
JLabel promptGirdi;
JTextField inputGirdi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JLabel promptPD;
JTextField inputPD;
JTextArea outputGirdi;
JLabel promptCikti;
JTextField inputCikti;
JTextArea outputCikti;
JTextArea outputFormul;
JLabel promptP1_1,promptP1_2,promptP1_3,promptP1_4;
JTextField inputP1_1,inputP1_2,inputP1_3,inputP1_4;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JTextField inputYmin; // input field Ymin
JButton printButton;
//===========================================================
super(s);
Border b=[Link]();
girdiDosyasi=new File("[Link]");
girdiDosyasi=new File([Link]());
ciktiDosyasi=new File("[Link]");
ciktiDosyasi=new File([Link]());
plotDosyasi=new File("[Link]");
plotDosyasi=new File([Link]());
oku();
nGirdi=[Link];
nCikti=nGirdi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
minX=xi[0];
maxX=xi[nGirdi-1];
ee=new double[nGirdi];
PolinomDerecesi=2;
ee=Numeric.poly_least_square(xi,yi,PolinomDerecesi);
[Link](new BorderLayout());
[Link](new GridLayout(1,8));
[Link](new GridLayout(1,8));
[Link](new GridLayout(3,2));
[Link](new GridLayout(4,2));
[Link](new BorderLayout());
//JScrollPane.VERTICAL_SCROLLBAR_ALWAYS;
[Link](new GridLayout(2,2));
//***************
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
promptGirdi=new JLabel("Girdi dosya ismi");
inputGirdi=new JTextField("[Link]");
inputPD=new JTextField(""+PolinomDerecesi);
outputGirdi=new JTextArea(yazxiyi(),20,40);
[Link](true);
[Link](b);
inputCikti=new JTextField("[Link]");
inputP1_2=new JTextField(""+nCikti);
inputP1_3=new JTextField(""+minX);
inputP1_4=new JTextField(""+maxX);
outputCikti=new JTextArea(yazCikti(),20,40);
[Link](b);
outputFormul=new JTextArea(yaze(),10,40);
[Link](true);
[Link](true);
[Link](b);
[Link](promptCikti);
[Link](inputCikti);
[Link](promptP1_2);
[Link](inputP1_2);
[Link](promptP1_3);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](inputP1_3);
[Link](promptP1_4);
[Link](inputP1_4);
[Link](PanelCikti1,[Link]);
[Link](new JScrollPane(outputFormul),[Link]);
[Link](new JScrollPane(outputCikti),[Link]);
[Link](promptGirdi);
[Link](inputGirdi);
[Link](promptPD);
[Link](inputPD);
[Link](PanelGirdi1);
[Link](new JScrollPane(outputGirdi));
[Link](PanelCikti2);
//***************
//*******
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
promptYLabel = new JLabel("y ekseni baºlýðý : ");
//*******
inputXntic=new JTextField(5);
inputYntic=new JTextField(5);
//*******
[Link](promptXmin);
[Link](inputXmin);
[Link](promptXmax);
[Link](inputXmax);
[Link](promptYmin);
[Link](inputYmin);
[Link](promptYmax);
[Link](inputYmax);
[Link](mpane,[Link]);
[Link](promptXntic);
[Link](inputXntic);
[Link](promptYntic);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](inputYntic);
[Link](promptXgridon);
[Link](inputXgridon);
[Link](promptYgridon);
[Link](inputYgridon);
[Link](xpane,[Link]);
//********
[Link](promptLabel);
[Link](inputLabel);
[Link](promptXLabel);
[Link](inputXLabel);
[Link](promptYLabel);
[Link](inputYLabel);
[Link](lpane,[Link]);
//*********
jta=new Plot2D();
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
printButton=new JButton("Yazdýr");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](jta);
[Link](printButton,[Link]);
[Link](girdi, pane3);
[Link](leastcikti, pane4);
[Link](PLOTPanel, pane2);
[Link](KONTROLPanel, pane1);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
inputP1_2.addActionListener(this); // nCikti
inputP1_3.addActionListener(this); // minX
inputP1_4.addActionListener(this); // maxX
[Link](this); // PolinomDerecesi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
leastCiktisiniPlotGirdisiOlarakYazdir();
//===========================================================
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
Object source=[Link]();
if(source==inputXgridon)
if ([Link]() == [Link])
[Link]=0;
else
[Link]=1;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
else if(source==inputYgridon)
if ([Link]() == [Link])
[Link]=0;
else
[Link]=1;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
//===========================================================
try
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]([Link]());
[Link]([Link]());
[Link]([Link]()+" 20 0 0 0 ");
[Link]();
catch(IOException e1)
catch(AccessControlException ace)
[Link]("least ciktisini plot girdisi olarak yazdir access kontrol hatasý : "+
plotDosyasi);
girdiDosyasi=new File([Link]());
PolinomDerecesi=[Link]();
ciktiDosyasi=new File([Link]());
nCikti=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double d3=new Double(inputP1_3.getText());
minX=[Link]();
maxX=[Link]();
try{
oku();
catch(IOException e1)
catch(AccessControlException ace)
ee=new double[PolinomDerecesi+1];
ee=Numeric.poly_least_square(xi,yi,PolinomDerecesi);
[Link](yazxiyi());
[Link](yazCikti());
[Link](yaze());
[Link]();
leastCiktisiniPlotGirdisiOlarakYazdir();
//===========================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void actionPerformed(ActionEvent e)
// eventi oluºturur
if( [Link]()==inputGirdi ||
[Link]()==inputPD ||
[Link]()==inputCikti ||
[Link]()==inputP1_2 ||
[Link]()==inputP1_3 ||
[Link]()==inputP1_4 )
sayfalariyenile();
//********************
if ([Link]()==printButton )
[Link]();
[Link]=[Link]();
[Link]=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Double valYmin=new Double([Link]());
[Link]=[Link]();
//*****
[Link]=[Link]();
[Link]=[Link]();
//*****
[Link]=[Link]();
[Link]=[Link]();
[Link]=[Link]();
[Link]=[Link]();
[Link]();
//===========================================================
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
fin=new BufferedReader(new FileReader(girdiDosyasi));
catch(FileNotFoundException e2)
[Link]([Link]());
nGirdi=0;
Vector v1,v2;
v1=new Vector(1);
v2=new Vector(1);
String X1,X2;
boolean EOF=false;
while(!EOF)
try{
X1=[Link](fin);
X2=[Link](fin);
[Link](X1);
[Link](X2);
nGirdi++;
}catch(EOFException e)
[Link]();
EOF=true;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
xi=new double[nGirdi];
yi=new double[nGirdi];
Enumeration enum1=[Link]();
Enumeration enum2=[Link]();
//for(int i=0;i<n;i++)
int i=0;
while([Link]())
X1=(String)[Link]();
X2=(String)[Link]();
xi[i]=[Link]();
yi[i]=[Link]();
i++;
//===========================================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
for(int i=0;i<[Link];i++)
return b;
//========================================================
for(int i=0;i<=PolinomDerecesi;i++)
b=b+"a["+i+"] = "+ee[i]+"\n";
return b;
//=========================================================
try{
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ObjectOutputStream fout=new ObjectOutputStream(new
FileOutputStream(ciktiDosyasi));
double x,y;
double nn=((maxX-minX)/(nCikti-1));
for(int i=0;i<nCikti;i++)
x=minX+nn*i;
y=Numeric.f_least_square(ee,x);
[Link](b);
try{
[Link]();
catch(IOException io)
[Link](1);
catch(IOException e1)
catch(AccessControlException ece)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
return b;
//===========================================================
leastSW frame = new leastSW( "En küçük kareler metodu eðri uydurma" );
[Link](new BasicWindowMonitor());
[Link](true);
[Link]
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
ªekil 12.1-4 en küçük kareler metoduyla polinaom eðri uyduran [Link] sýnýfý Jframe
çýktýlarýnýn çeºitli sayfalarýnýn görünümü.
[Link]
baºlýk
x ekseni
y ekseni
[Link] 20 0 0 0
[Link] 3 0 0 255
[Link]
1.0 0.9999999999999432
2.0 3.9999999999997726
3.0 8.999999999999488
4.0 15.99999999999909
5.0 24.99999999999858
6.0 35.999999999997954
7.0 48.999999999997215
8.0 63.99999999999636
9.0 80.9999999999954
10.0 99.99999999999432
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
cikti dosyasi :
1.0 0.9999999999999432
2.0 3.9999999999997726
3.0 8.999999999999488
4.0 15.99999999999909
5.0 24.99999999999858
6.0 35.999999999997954
7.0 48.999999999997215
8.0 63.99999999999636
9.0 80.9999999999954
10.0 99.99999999999432
Diferansiyel Denklemler :
//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import [Link].*;
import Numeric;
import complex;
import Matrix;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
}
class dif1
{
public static void main(String args[]) throws IOException
{
Çözüm seti :
1.0
1.02020134
1.0408107741377959
1.0618365464618167
1.0832870675613175
1.1051709179307265
1.1274968514019572
1.1502737986460576
1.1735108707455981
1.197217362839226
1.2214027578398445
1.2460767302279048
1.271249149921327
1.2969300862235986
1.3231298118516308
1.3498588070449815
1.3771277637580916
1.4049475899372086
1.4333294138837107
1.4622845887055762
1.4918246968587778
1.5219615547804188
1.5527072176154666
1.5840739840389706
1.6160744011756962
1.648721269619143
1.682027648551951
1.7160068609697496
1.7506724990105325
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
1.7860384293916938
1.8221187989569014
1.8589280403350215
1.896480877713363
1.9347923327275491
1.9738777304703714
2.0137527056220317
2.0544332087042223
2.095935512460547
2.1382762183658373
2.1814722632669596
2.2255409261577848
2.270499835091013
2.3163669742296302
2.363160691040814
2.4108997036351645
2.4596031082541976
2.5092903869090972
2.5599814151737794
2.611696470135386
2.6644562385053905
2.7182818248945586
Problem 12.12 : çok boyutlu RKF45 diferansiyel denklem çözüm metodu örneði,
[Link]
//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import [Link].*;
import Numeric;
import complex;
import Matrix;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
class dif2
{
public static void main(String args[]) throws IOException
{
Çözüm :
0.0 -1.0
0.0050 -0.9950377826066799
0.01 -0.9901501844020889
0.015 -0.9853368332473136
0.02 -0.9805973588593618
0.025 -0.9759313928019077
0.030000000000000002-0.9713385684760812
0.035 -0.9668185211113052
0.04 -0.9623708877561767
0.045 -0.9579953072693951
0.049999999999999996-0.9536914203107341
0.05499999999999999-0.94945886933206
0.05999999999999999-0.9452972985683943
0.06499999999999999-0.9412063540290199
0.06999999999999999-0.9371856834886335
0.075 -0.9332349364785408
0.08 -0.9293537642778962
0.085 -0.9255418199049855
0.09000000000000001-0.9217987581085532
0.09500000000000001-0.9181242353591716
0.10000000000000002-0.9145179098406548
0.10500000000000002-0.9109794414415133
0.11000000000000003-0.9075084917464531
0.11500000000000003-0.9041047240279163
0.12000000000000004-0.9007678032376644
0.12500000000000003-0.8974973959984025
0.13000000000000003-0.8942931705954467
0.13500000000000004-0.891154796968432
0.14000000000000004-0.8880819467030621
0.14500000000000005-0.8850742930228999
0.15000000000000005-0.8821315107811996
0.15500000000000005-0.8792532764527788
0.16000000000000006-0.8764392681259321
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
0.16500000000000006-0.8736891654943832
0.17000000000000007-0.8710026498492798
0.17500000000000007-0.8683794040712255
0.18000000000000008-0.8658191126223544
0.18500000000000008-0.8633214615384427
0.19000000000000009-0.8608861384210608
0.1950000000000001-0.8585128324297647
0.2000000000000001-0.856201234274326
0.2050000000000001-0.8539510362070005
0.2100000000000001-0.8517619320148359
0.2150000000000001-0.849633617012017
0.2200000000000001-0.8475657880322502
0.22500000000000012-0.8455581434211851
0.23000000000000012-0.843610383028874
0.23500000000000013-0.8417222082022695
0.24000000000000013-0.8398933217777589
0.24500000000000013-0.8381234280737365
0.2500000000000001-0.8364122328832122
0.2550000000000001-0.8347594434664576
0.2600000000000001-0.8331647685436885
0.2650000000000001-0.8316279182877833
0.27000000000000013-0.8301486043170393
0.27500000000000013-0.8287265396879636
0.28000000000000014-0.8273614388881004
0.28500000000000014-0.8260530178288946
0.29000000000000015-0.8248009938385901
0.29500000000000015-0.8236050856551641
0.30000000000000016-0.8224650134192967
0.30500000000000016-0.8213804986673754
0.31000000000000016-0.8203512643245341
0.31500000000000017-0.8193770346977273
0.3200000000000002-0.8184575354688391
0.3250000000000002-0.8175924936878259
0.3300000000000002-0.8167816377658933
0.3350000000000002-0.8160246974687078
0.3400000000000002-0.8153214039096416
0.3450000000000002-0.8146714895430517
0.3500000000000002-0.8140746881575915
0.3550000000000002-0.8135307348695573
0.3600000000000002-0.8130393661162659
0.3650000000000002-0.812600319649468
0.3700000000000002-0.8122133345287916
0.3750000000000002-0.8118781511152201
0.3800000000000002-0.8115945110646018
0.38500000000000023-0.8113621573211925
0.39000000000000024-0.8111808341112298
0.39500000000000024-0.8110502869365394
0.4 -0.8109702625681743
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
//======================================================
// Numerical Analysis package in java
// example to show differential equation solution
// and differentiation (derivative) functions
// Dr. Turhan Coban
// =====================================================
import [Link].*;
import Numeric;
import complex;
import Matrix;
class dif3
{
public static void main(String args[]) throws IOException
{
Çözüm :
-1.0
-0.9960239680320001
-0.992095744511233
-0.9882151385858677
-0.9843819601659565
-0.9805960199203918
-0.9768571292738785
-0.9731651004039156
-0.9695197462377918
-0.9659208804495921
-0.9623683174572164
-0.9588618724194105
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
-0.955401361232808
-0.9519866005289858
-0.9486174076715289
-0.945293600753109
-0.942014998592574
-0.9387814207320486
-0.9355926874340476
-0.9324486196785992
-0.9293490391603817
-0.9262937682858702
-0.9232826301704945
-0.9203154486358103
-0.9173920482066786
-0.9145122541084599
-0.9116758922642163
-0.9088827892919272
-0.9061327725017148
-0.903425669893081
-0.900761310152156
-0.898139522648956
-0.8955601374346547
-0.8930229852388627
-0.8905278974669202
-0.888074706197199
-0.8856632441784156
-0.8832933448269559
-0.8809648422242088
-0.8786775711139124
-0.8764313668995095
-0.8742260656415141
-0.872061504054888
-0.8699375195064296
-0.8678539500121697
-0.8658106342347813
-0.8638074114809979
-0.8618441216990421
-0.8599206054760645
-0.8580367040355941
-0.8561922592349969
-0.854387113562946
-0.8526211101369017
-0.8508940927006006
-0.8492059056215563
-0.8475563938885688
-0.8459454031092447
-0.8443727795075264
-0.8428383699212321
-0.8413420217996048
-0.8398835832008722
-0.8384629027898148
-0.8370798298353451
-0.8357342142080957
-0.8344259063780173
-0.8331547574119857
-0.8319206189714199
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
-0.8307233433099079
-0.8295627832708429
-0.8284387922850687
-0.8273512243685349
-0.826299934119961
-0.8252847767185101
-0.8243056079214711
-0.8233622840619519
-0.8224546620465801
-0.8215825993532133
-0.8207459540286591
-0.8199445846864039
-0.8191783505043502
-0.8184471112225643
ªu ana kadarki örneklerimizin hepsi konsol programý olarak verildi. simdi grafik (applet)
çýktýsýna da bir örnek olmak üzere ninci dereceden denklemin köklerini hesaplayan [Link]
programýný verelim.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import Matrix;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
add(t);
[Link](this);
}
Bu progamýn sonucu :
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 12.5 n inci dereceden polinomun köklerini bulan kokN programý, StringTokenizer
ve Matrix sýnýf örneði
12.5 ALIªTIRMALAR
5. f(x)=sin(x) denkleminin pi noktasýndaki türevini alýnýz. Bunun için bir java programý
yazýp çýktýyý hesaplatýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
BÖLÜM 13 VERÝ TABANI PROGRAMLAMASINA GÝRݪ
Database programlarýna Java dili üzerinden eriºmek için java JDBC API kullanýlýr. JDBC
bize herhangi bir Data Base (veri Tabaný) yapýsýna java üzerinden ulaºmamýzý ve Veri tabaný
dili olan SQL (Structured Query Language-Yapýsal Sorgulama Dili) dilinde direk olarak
programlama yapabilmemizi saðlar. JDBC ye geçmeden önce SQL dilinin bazý temel
yapýlarýna göz atalým. Burada göreceðimiz oldukça kompleks iºlemleri yapabileceðimiz
üçüncü kuºak bir bilgisayar dilidir. Bu kitabýn konusu Veri tabanlarý olmadýðý için biz fazla
detaya girmeyeceðiz. Dileyen arkadaºlar Veri Tabaný ile ilgili kitaplarda SQL ile ilgili çok daha
detaylý bilgi bulabilirler.
[Link]
ªekil 13.1 Kahve veri tabaný dosyasýnýn acsees veri tabaný programýnda görünüºü
komutunu kullanabiliriz. Buradaki temel komut CREATE TABLE komutudur. Veri tabaný
tablosu adý KAHVE ve Tablo sütun isimleri KAHVE_ISMI, NUMARA, FIYAT, SATIS ve
TOPLAM olarak tanýmlanmýstýr. deðisken isminden sonra SQL deðisken türleri verilmistir.
Deðiºken türlerinin isimleri deðisik SQL dillerinde deðiºebilir. yukarýdaký SQL deyimindeki
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
VARCHAR(32) javadaki double (veya float) deyiminin karºýlýðýdýr. INTEGER javadaký int
deyimine FLOAT javadaki float deyimine karºý gelir.
Bu tabloya belli deðerleri girmek için INTERT INTO deyimi kullanýlýr. Örneðin tablodaki ilk
satýr
Tablodan belli deðerleri geri çekmek için ise SELECT deyimi kullanýlýr. SELECT deyiminin en
genel ºekli
[WHERE ºart]
[HAVING ºart]
[ORDER BY kolon listesi] ºeklindedir. SELECT ve FROM herzaman için kullanýlýr, diðerleri
istenirse kullanýlýr. SELECT komutundan sonra çýktýda görmek istediðimiz kolon adlarý
bulunur. Tablonun tüm kolonlarýný görmek istersek * kullanabiliriz. FROM komutundan sonra
seçilen tablonun (veya tablolarýn) isimleri yer alýr. Tablo isimleri ‘,’ ile ayrýlýr. ALL veya
DISTINCT anahtarlarý eðer tekrar varsa bunlarýn verilip verilmeyeceðini bildirir. DISTINCT
secildiðinde tüm tekrarlar elimine edilir. ALL seçildiðinde tüm girdiler tekrar da olsa verilir.
WHERE deyimi javadaki if deyimi gibidir. ªart oluºturur. WHERE ile birlikte kullanýlan bazý
mantýk iºlemleri ºunlardýr :
AND : ve
OR : veya
NOT : olumsuzluk
BETWEEN : arasýnda (genellikle AND ile birlikte BETWEEN 20 AND 30 gibi kullanýlýr)
IN : içinde
LIKE : gibi,benzer(harf deðiºkenleri için eºittir yerine geçen bir yapýdýr, kullanýlýrken bazý
kýsýmlar boº býrakýlabilir LIKE ‘%ali%’ içinde ali geçen her ºeyi kapsar.)
NULL : boº
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ANY : herhangibiri
ALL : hepsi
EXIST : varsa
Rakamsal karºýlaºtýrmalarda
= : eºittir
> : büyüktür
< : küçüktür
Kullanýlabilir.
ORDER BY sýraya sokar ASC kelmesiyle birlikte kullanýldýðýnda küçükten büyüðe doðru,
DESC kelimesiyle birlikte kullanýldýðýnda büyükten küçüðe doðru sýralar.
GROUP BY belli bir kolona göre veriyi tasnif edebilir. HAVING deyimi GROUP by deyimiyle
birlikte kullanýlýr be GROUP By terimi için ilave ºart oluºturur.
deyimi
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sonucunu verir.
[Link]
sonucunu verir.
[Link]
Fiyatý 8.5 ila 9.0 arasýnda olan kahvelerin listesi sonucunu verecektir.
UPDATE KAHVE
SET TOPLAM=FIYAT*SATIS;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Komutu kullanarak TOPLAM kolonunun deðerlerini hesaplayabiliriz. Tablonun yeni hali :
[Link]
ªekil 13.4 UPDATE querry sonuçlarýnýn acsess veri tabaný nda görünümü
Sonucunu verir.
SQL de direk olarak hesap yapabilen fonksiyonlar da mevcuttur. Örneðin SUM(kolon ismi)
deðerleri toplar, MAX, maksimum deðeri verir, MIN, minumum deðeri verir, COUNT toplam
sütun sayýsýný sayar. Bu fonksiyonlara örnek olarak SUM fonksiyonunu kullanalým :
SELECT SUM(TOPLAM)
FROM KAHVE;
[Link]
ASC küçükten büyüðe DESC büyükten küçüðe sýraya koyar. Örneðin veri tabaný tablomuz
kahveyi KAHVE_ISMI’ne göre sýralamak istersek
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SELECT *
FROM KAHVE
[Link]
ªekil 13.6 SELECT..ORDERBY querry sonuçlarýnýn acsess veri tabaný nda görünümü
ªimdi bu iºlemleri direk olarak java programlama dili üzerinden nasýl yapacaðýmýzý
inceleyelim.
Java dilinde data base tanýmlamak için önce database ile bir baðlantý kurulmalýdýr. Burada
örnek olarak MS Access ile Window ortamýnda nasýl baðlantý tanýmlýyacaðýmýzý step-step
verelim
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Window 2000 (NT) ortamýnda access database ile baðlantý kurulmasý
import [Link].*;
import [Link].*;
import Text;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Buradaki
[Link]("[Link]");
deyimi java JdbcOdbcDriver ile baðlantý açmaktadýr. Eðer varsa kendi database driver'ýnýzý
kullanabilirsiniz Bunun size getireceði en büyük avantaj daha önce yazýlmýº bir database
programýna eriºmeyi mümkün kýlmasýdýr. JDBC driverlerinin en son listesi
http:/[Link]/products/jdbc/[Link]
sitesinden öðrenilebilir.
deyimi ise daha önce ismini prog olarak tanýmladýðýmýz (ismi siz database kaynak kotunun
ismine göre tanýmlýyabilirsiniz) prog database'ine ulaºmamýzý saðlamaktadýr.
Veri tabaný sonuçlarýný almak için ResultSet kullanýlýr. ResultSet interfaceinin alt metodlarý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
boolean getBoolean(String columnName) throws SQLException;
byte getByte(String columnName) throws SQLException;
short getShort(String columnName) throws SQLException;
int getInt(String columnName) throws SQLException;
long getLong(String columnName) throws SQLException;
float getFloat(String columnName) throws SQLException;
double getDouble(String columnName) throws SQLException;
BigDecimal getBigDecimal(String columnName, int scale) throws SQLException;
byte[] getBytes(String columnName) throws SQLException;
[Link] getDate(String columnName) throws SQLException;
[Link] getTime(String columnName) throws SQLException;
[Link] getTimestamp(String columnName) throws SQLException;
[Link] getAsciiStream(String columnName) throws SQLException;
[Link] getUnicodeStream(String columnName) throws SQLException;
[Link] getBinaryStream(String columnName)
throws SQLException;
SQLWarning getWarnings() throws SQLException;
void clearWarnings() throws SQLException;
String getCursorName() throws SQLException;
Object getObject(int columnIndex) throws SQLException;
Object getObject(String columnName) throws SQLException;
[Link] getCharacterStream(int columnIndex) throws SQLException;
[Link] getCharacterStream(String columnName) throws SQLException;
BigDecimal getBigDecimal(int columnIndex) throws SQLException;
BigDecimal getBigDecimal(String columnName) throws SQLException;
boolean isBeforeFirst() throws SQLException;
boolean isAfterLast() throws SQLException;
boolean isFirst() throws SQLException;
boolean isLast() throws SQLException;
void beforeFirst() throws SQLException;
void afterLast() throws SQLException;
boolean first() throws SQLException;
boolean last() throws SQLException;
int getRow() throws SQLException;
boolean absolute( int row ) throws SQLException;
boolean relative( int rows ) throws SQLException;
boolean previous() throws SQLException;
void setFetchDirection(int direction) throws SQLException;
int getFetchDirection() throws SQLException;
void setFetchSize(int rows) throws SQLException;
int getFetchSize() throws SQLException;
boolean rowUpdated() throws SQLException;
boolean rowInserted() throws SQLException;
boolean rowDeleted() throws SQLException;
void updateNull(int columnIndex) throws SQLException;
void updateBoolean(int columnIndex, boolean x) throws SQLException;
void updateByte(int columnIndex, byte x) throws SQLException;
void updateShort(int columnIndex, short x) throws SQLException;
void updateInt(int columnIndex, int x) throws SQLException;
void updateLong(int columnIndex, long x) throws SQLException;
void updateFloat(int columnIndex, float x) throws SQLException;
void updateDouble(int columnIndex, double x) throws SQLException;
void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException;
void updateString(int columnIndex, String x) throws SQLException;
void updateBytes(int columnIndex, byte x[]) throws SQLException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
void updateDate(int columnIndex, [Link] x) throws SQLException;
void updateTime(int columnIndex, [Link] x) throws SQLException;
void updateTimestamp(int columnIndex, [Link] x)
throws SQLException;
void updateAsciiStream(int columnIndex,
[Link] x,
int length) throws SQLException;
void updateBinaryStream(int columnIndex,
[Link] x,
int length) throws SQLException;
void updateCharacterStream(int columnIndex,
[Link] x,
int length) throws SQLException;
void updateObject(int columnIndex, Object x, int scale)
throws SQLException;
void updateObject(int columnIndex, Object x) throws SQLException;
void updateNull(String columnName) throws SQLException;
void updateBoolean(String columnName, boolean x) throws SQLException;
void updateByte(String columnName, byte x) throws SQLException;
void updateShort(String columnName, short x) throws SQLException;
void updateInt(String columnName, int x) throws SQLException;
void updateLong(String columnName, long x) throws SQLException;
void updateFloat(String columnName, float x) throws SQLException;
void updateDouble(String columnName, double x) throws SQLException;
void updateBigDecimal(String columnName, BigDecimal x) throws SQLException;
void updateString(String columnName, String x) throws SQLException;
void updateBytes(String columnName, byte x[]) throws SQLException;
void updateDate(String columnName, [Link] x) throws SQLException;
void updateTime(String columnName, [Link] x) throws SQLException;
void updateTimestamp(String columnName, [Link] x)
throws SQLException;
void updateAsciiStream(String columnName,
[Link] x,
int length) throws SQLException;
void updateBinaryStream(String columnName,
[Link] x,
int length) throws SQLException;
void updateCharacterStream(String columnName,
[Link] reader,
int length) throws SQLException;
void updateObject(String columnName, Object x, int scale)
throws SQLException;
void updateObject(String columnName, Object x) throws SQLException;
void insertRow() throws SQLException;
void updateRow() throws SQLException;
void deleteRow() throws SQLException;
void refreshRow() throws SQLException;
void cancelRowUpdates() throws SQLException;
void moveToInsertRow() throws SQLException;
void moveToCurrentRow() throws SQLException;
Statement getStatement() throws SQLException;
Object getObject(int i, [Link] map) throws SQLException;
Ref getRef(int i) throws SQLException;
Blob getBlob(int i) throws SQLException;
Clob getClob(int i) throws SQLException;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Array getArray(int i) throws SQLException;
Object getObject(String colName, [Link] map) throws SQLException;
Ref getRef(String colName) throws SQLException;
Blob getBlob(String colName) throws SQLException;
Clob getClob(String colName) throws SQLException;
Array getArray(String colName) throws SQLException;
[Link] getDate(int columnIndex, Calendar cal) throws SQLException;
[Link] getDate(String columnName, Calendar cal) throws SQLException;
[Link] getTime(int columnIndex, Calendar cal) throws SQLException;
[Link] getTime(String columnName, Calendar cal) throws SQLException;
[Link] getTimestamp(int columnIndex, Calendar cal)
[Link] getTimestamp(String columnName, Calendar cal)
throws SQLException;
}
int executeUpdate(String sql) throws SQLException : bir sonuç tablosu vermeyen SQL
terimlerini çalýºtýrýr. Komuttan etkilenen satýr sayýsýný iletir.
Boolean execute(String sql) throws SQLException : genel maksatlý SQL deyimi çalýºtýrýcý
Kahve verisini veri tabanýna yazdýran ve select deyimi kullanarak okutan program
[Link] nýn listesi aºaðýda verilmiºtir.
Program 13.2 kahve veri tabaný dosyasýna veri giriºi saðlayan [Link]
programý
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Connection con;
Statement stmt;
try {
[Link]("[Link]");
} catch([Link] e)
[Link]("ClassNotFoundException: ");
[Link]([Link]());
try {
con = [Link](url,
"myLogin", "myPassword");
stmt = [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ResultSet rs = [Link](query);
while ([Link]()) {
String s = [Link]("KAHVE_ISMI");
float f = [Link]("FIYAT");
[Link]();
[Link]();
} catch(SQLException ex) {
Program çýktýsý :
Espresso 9.99
Brezilya 7.99
ªeklindedir. Ayný programýn ºimdi de applet olarak yazýlmýº bir eºdeðerine göz atalým.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 13.3 [Link] programý InsertKahve programýnýn applet eºdeðeridir.
programýn thread olarak yazýldýðýna dikkat ediniz.
import [Link];
import [Link];
import [Link];
import [Link].*;
if (worker == null) {
[Link]();
try {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("[Link]");
} catch(Exception ex) {
return;
try {
"myLogin", "myPassword");
ResultSet rs = [Link](query);
while ([Link]()) {
String s = [Link]("KAHVE_ISMI");
float f = [Link]("FIYAT");
[Link](text);
[Link]();
[Link]();
setResults(results);
} catch(SQLException ex) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
if (queryResults == null)
[Link](message, 5, 50);
return;
int y = 30;
while ([Link]()) {
[Link](text, 5, y);
y = y + 15;
queryResults = null;
message = mess;
worker = null;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// And ask AWT to repaint this applet.
repaint();
queryResults = results;
worker = null;
repaint();
[Link]
Statement interface’inin alt metodlarýna biraz daha detaylý bakalým. Statement SQL
komutlarýný veritabaný programýna gönderen ve sonuçlarýný geri çaðýran ana sýnýftýr. SQL
komut istemi çeºitli metodlar üzerinden yapýlabilir
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ResultSet executeQuery(String sqldeyimi) throws SQLException
Bu metod çalýºtýrýldýðýnda tek bir SQL query çalýºtýrýlýr ve sonuçlarý ResultSet sýnýfýndan geri
alýnýr.
Bu metod çalýºtýrýldýðýnda tek bir SQL Query çalýºtýrýlýr, geriye sonuç iletmez, sadece kaç
satýr verinin bu deyimden etkilendiðini belirtir.
Bu metod çalýºtýrýldýðýnda genel bir SQL Query deyimi çalýºtýrýlýrýlabilir. Bilhassa çalýºtýrýlan
SQL deyiminin ne yapabileceði tam olarak bilinmiyorsa veya deðiºken sonuçlar elde
ediliyorsa kullanýlabilir. Bu deyim sonucu iletilen veriler GetResultSet(),getUpdateCount() ve
getMoreResults() metodlarý kullanýlarak alýnabilir.
En son çýkmýº olan sonuçlarý iletir. Eðer hiç bir sonuç mevcut deðildse null sonucu verir. Bir
kere okunduktan sonra sonuçlar silinir.
Update, insert ve delet deyimlerinin sonuçlarýnda aç satýrýn etkilendiðini verir. Eðer SQL
tarafýýndan bir sonuç seti verilmiºse veya herhangi bir veri deðiºtirilmemiºse –1 deðerini verir.
Birden fazla sonuçveya update sayýmý yapýlan durumlarda bir sonraki deðer setine geçer. Bu
metod ayný zamanda daha önce açýlmýº olan tüm ResultSet deyimi deðerlerini kapatýr.
ResultSet sýnýfý temel olarakveritabaný dosyasýndandeðerleri okumak için kullanýlýr. SQL veri
türleri çeºitli SQL veritabanlarýnýn varlýðýndan dolayý oldukça çeºitlilik gösterir. Temel olak
kullanýlan metodlar ve olarýn SQL veri larºýlýklarý ºunlardýr :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
getFloat : TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT, DOUBLE, DECIMAL,
NUMERIC, BIT, CHAR, VARCAHR, LONGVARCHAR
kalýn harfle yazýlý olan SQL tipleri bu metod için en uygun tiplerdir. Metodlar SQL tablo
kolonuna kolon ismi veya indeks numarasý kullanarak ulaºabilirler. Örneðin getDouble
metodu
ºeklinde tanýmlanmýºtýr.
ResultSetMetaData sýnýfý ResultSet’te tanýmlanan bilgi ile ilgili ilave sütun bilgisi aktarnmak
için kullanýlýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ResultSet rs=[Link](“SELECT Toplam FROM KAHVE”);
ResultSetMetaData rsmd=[Link]();
int getColumnCount() throws SQLException : kaç sütunluk bir set olduðunu tanýmlar
String getColumnName(int column) throws SQLException : veri tabaný sütun ismini verir
String getTableName(int column) throws SQLException : veri tabaný tablosunun ismini verir
Booean isReadOnly(int sütun) throws SQLException : sütunun sadece okunabilir olarak izni
olup olmadýðýný verir.
ªu ana kadar geliºtirdiðimiz veri tabaný programlarý uygulamaya özel idi. ªimdi biraz daha
genel bir uygulama oluºturalým. Bu uygulamada swing JTable sýnýfýný kullanacaðýz. Bu
programda oluºturduðumuz ilk sýnýf QuerryTableModel sýnýfý tabloya girmek için sorgu(query)
sonuçlarýný tablo giriº formatýnda hazýrlamaktadýr. Bu metodun bilgi iºlerken Vector sýnýfýný
kullandýðýna dikkatinizi çekeriz. Vector sýnýfý hakkýnda daha detaylý bilgi için ilgili bölüme
bakýnýz.
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Vector cache;
int colCount;
String[] headers;
Connection db;
Statement statement;
String currentURL;
public QueryTableModel()
cache=new Vector();
//new [Link]();
try
[Link]("[Link]");
catch([Link] e)
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public Object getValueAt(int row,int col)
return ((String[])[Link](row))[col];
if([Link](currentURL))
{return;}
closeDB();
initDB(url);
currentURL=url;
try{
ResultSet rs=[Link](q);
ResultSetMetaData meta=[Link]();
colCount=[Link]();
headers=new String[colCount];
headers[h-1]=[Link](h);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
while([Link]())
for(int i=0;i<colCount;i++)
{record[i]=[Link](i+1);}
[Link](record);
} //while'in sonu
fireTableChanged(null);
} //try'in sonu
catch(Exception e)
cache=new Vector();
[Link]();
} // setQuery sonu
try {
db=[Link](url);
statement=[Link]();
catch(Exception e)
[Link]("DataBase baºlatýlamadý");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
} //initDB sonu
try {
catch(Exception e)
[Link]("database kapatýlamadý");
[Link]();
} //closeDB sonu
Ýkinci sýnýfýmýz (Tabloyu gösterme sýnýfý) olan DataBaseTest programý ise girdi alanýndan
SQL komutunu ve veritabaný baðlantýsýný okumakta ve SQL sonuçlarýný tabloda vermektedir.
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
JTextField hostField;
JTextArea queryField;
QueryTableModel qtm;
public DatabaseTest()
addWindowListener(new BasicWindowMonitor());
setSize(350,200);
qtm=new QueryTableModel();
[Link](new GridLayout(3,2));
[Link](hostField=new JTextField("jdbc:odbc:prog"));
[Link](new ActionListener()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link]([Link]().trim());
[Link]([Link]().trim());
}); // [Link]
[Link](jb);
getContentPane().add(p1,[Link]);
getContentPane().add(scrollpane,[Link]);
} //DatabaseTest()
[Link](true);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 13.8 [Link] programýnýn JFrame’de ve JTable kullanýlarak
oluºturulan çýktýsý
13.3 ALIªTIRMALAR
1. Program örneði database dosyasýný girdi dosyasý olarak kullanan ve içindeki sayýlarýn
ortalamasýný alan [Link] programý : Bu programda sayýlar dosyadan okunmakta,
ortalamasý hem querry dilinde (SQL) hemde java dilinde hesaplanmaktadýr. Programý
inceleyiniz.
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double i= [Link]("T");
[Link]("Ortalama = "+i);
}
[Link]("metot 2 ortalamalar java dilinde hesaplandi");
double ortalama=toplam/j;
[Link]("metot 2 ortalama : "+ortalama);
[Link]();
[Link]();
}
catch (SQLException e)
{
[Link]([Link]());
} //catch
} //main
} //class
Sayi(0) = 1.232
Sayi(1) = 1.654
Sayi(2) = 3.562462
Sayi(3) = 2.6546
Sayi(4) = 2.64784
Sayi(5) = 1.4262
Sayi(6) = 2.98963
Sayi(7) = 3.76487648
Sayi(8) = 1.7368365
Sayi(9) = 4.2222487
Sayi(10) = 1.86327653
Sayi(11) = 1.973836
Sayi(12) = 3.687522
Sayi(13) = 1.7637836
Sayi(14) = 2.0832863
metot 1 ortalamalar query dilinde hesaplandi
Ortalama = 2.4841598739999995
metot 2 ortalamalar java dilinde hesaplandi
metot 2 ortalama : 2.4841598739999995
======================================================================
======
2. H9OD2_2000
[Link] acsess veri tabanýnda H9OD2_2000 veri tabaný tablosunu açýnýz. Bu dosyada x ve
y ve y2 baºlýklarý altýnda üç kolon yaratýnýz. x ve y kolonlarýna
1 1
1 4
2 9
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
3 16
4 25
5 36
veri setini giriniz. H9OD2_2000.java programýnda veri tabaný doyasýndan okutup ekranda
gösteriniz. Ayný zamanda y2 kolonuna x*x deðerlerini yazdýrýnýz.
import [Link].*;
String url="jdbc:odbc:prog";
Connection con;
Statement stmt;
try
[Link]("[Link]");
catch([Link] e)
{ [Link]([Link]()); }
try
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
con=[Link](url);
stmt=[Link]();
while ([Link]())
[Link](""+xi+" "+yi);
int jj = [Link](query2);
[Link](""+jj+"kolon deðiºtirildi");
[Link]();
[Link]();
catch (SQLException e)
[Link]([Link]());
} //catch
} //main
} //class
Program çýktýsý :
1.0 1.0
2.0 4.0
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
3.0 9.0
4.0 16.0
5.0 25.0
6.0 36.0
7.0 49.0
7 kolon degistirildi
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
ResultSet rs;
ResultSetMetaData rsm;
public H9OD2_2000a()
Container c=getContentPane();
String url="jdbc:odbc:prog";
Connection con;
Statement stmt;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String query1="select * from H9OD2_2000";
try
[Link]("[Link]");
catch([Link] e)
{ [Link]([Link]()); }
try
con=[Link](url);
stmt=[Link]();
int jj=[Link](query2);
rs= [Link](query1);
rsm=[Link]();
int j=[Link]();
baslik[h-1]=[Link](h);
[Link](jsp,[Link]);
[Link]();
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
catch (SQLException e)
[Link]([Link]());
} //catch
} //kurucu metod
int n=0;
while([Link]())
for(int k=0;k<j;k++)
a[n][k]=""+[Link]([Link](k+1));
n++;
for(int i=0;i<n;i++)
for(int k=0;k<j;k++)
b[i][k]= a[i][k];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return b;
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
} //class
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import QueryTableModel;
public H9OD2_2000b()
Container c=getContentPane();
String url="jdbc:odbc:prog";
[Link](url);
[Link](query1);
[Link](jsp,[Link]);
} //kurucu metod
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
} //class
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
======================================================================
======
3. Daha önce de kullandýðýmýz prog veritabanýnda e isimli bir tablo oluºturunuz, bu tablodaki
e sütununa gerçek sayý veri giriniz. Diðer bir tablo olarak e tablosunda e sütununu
oluºturunuz, bu tabloya da gerçek sayý deðerler giriniz. Ýki veri tabaný tablosundan deðerleri
okuyup, bileºim kümesini hesaplayýnýz ve yarattýðýnýz ed tablosuna ed deðerleri olarak
yazdýrýnýz.
import [Link].*;
import set;
import [Link].*;
import [Link].*;
import [Link];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
String s="";
double e,d,ed;
Vector ve,vd,ved;
ve =new Vector();
vd =new Vector();
String url="jdbc:odbc:prog";
Connection con;
Statement stmt;
try
[Link]("[Link]");
catch([Link] er)
{ [Link]([Link]()); }
try
con=[Link](url);
stmt=[Link]();
s+="e veritabaný:\n";
while ([Link]())
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
e = [Link]("e");
[Link](""+e);
s+=""+e+"\n";
[Link](null,s);
rs= [Link](query2);
while ([Link]())
d= [Link]("d");
[Link](""+d);
s+=""+d+"\n";
[Link](null,s);
ved=[Link](ve,vd);
Enumeration n=[Link]();
int i=1;
while([Link]())
String s1=(String)[Link]();
s+=s1+"\n";
[Link](s2);
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link](null,s);
[Link](0);
[Link]([Link]());
} //catch
} //main
} //class
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Object s1,s2;
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
s1=[Link]();
[Link](s1);
while([Link]())
s2=[Link]();
if()
[Link](s2);
return bilesimVectoru;
Object s;
Enumeration n = [Link]();
while([Link]())
s=[Link]();
if([Link](s))
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](s);
return kesisimVectoru;
Object ans;
while([Link]())
ans=[Link]();
if([Link](ans))
continue;
else
[Link](ans);
return subst;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Enumeration enum1= [Link]();
while([Link]())
ans1=[Link]();
if([Link](ans1))
continue;
else
[Link](ans1);
while([Link]())
ans2 = [Link]();
if([Link](ans2))
continue;
else
[Link](ans2);
return UMI;
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 13.11 H10OD1_2000.java, programýnýn oluºturduðu H10OD1_2000 veritabaný
dosyasý
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 13.12 H10OD1_2000.java
Bu program Gebze Yüksek teknoloji enstitüsü Java programla dili dersi, 2000 Güz dönemi
öðrencilerinden Deniz KAYA tarafýndan yazýlmýºtýr.
// Deniz KAYA
// Hafta 10 Ödevi
// yazdýrma iþlemi.
import [Link].*;
import [Link].*;
import [Link].*;
class SetA
String url="jdbc:odbc:prog";
Connection con;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Statement stmt;
try
[Link]("[Link]");
catch([Link] e)
[Link]([Link]());
try
con=[Link](url);
stmt=[Link]();
while ([Link]())
[Link](new Integer(xi));
[Link]();
[Link]();
catch (SQLException e)
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} //catch
return v;
} //
Object s1,s2;
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
s1=[Link]();
[Link](s1);
while([Link]())
s2=[Link]();
if()
[Link](s2);
return bilesimVectoru;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
Object s;
Enumeration n = [Link]();
while([Link]())
s=[Link]();
if([Link](s))
[Link](s);
return kesisimVectoru;
Object ans;
while([Link]())
ans=[Link]();
if([Link](ans))
continue;
else
[Link](ans);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return subst;
while([Link]())
ans1=[Link]();
if([Link](ans1))
continue;
else
[Link](ans1);
while([Link]())
ans2 = [Link]();
if([Link](ans2))
continue;
else
[Link](ans2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return UMI;
Enumeration e = [Link]();
String url="jdbc:odbc:prog";
Connection con;
Statement stmt;
try
[Link]("[Link]");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch([Link] ex)
[Link]([Link]());
try
con=[Link](url);
stmt=[Link]();
while([Link]())
Integer s = (Integer)[Link]();
[Link]([Link]());
[Link]();
[Link]();
[Link]([Link]());
} //catch
} // Main
}// H10OD1_2000
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 13.13 [Link]
class TreeNode
TreeNode sol;
int data;
TreeNode sag;
public TreeNode(int d)
data=d;
sol=sag=null;
if(d<data)
else {[Link](d);}
else if(d>data)
else {[Link](d);}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
else [Link](d);
if(node==null) return;
[Link]([Link]+" ");
node_soldal_sagdal_siralayici([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
node_soldal_sagdal_siralayici([Link]);
if(node==null) return;
[Link]([Link]+" ");
node_sagdal_soldal_siralayici([Link]);
node_sagdal_soldal_siralayici([Link]);
if(node==null) return;
soldal_node_sagdal_siralayici([Link]);
[Link]([Link]+" ");
soldal_node_sagdal_siralayici([Link]);
if(node==null) return;
sagdal_node_soldal_siralayici([Link]);
[Link]([Link]+" ");
sagdal_node_soldal_siralayici([Link]);
if(node==null) return;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
soldal_node_sagdal_siralayici([Link]);
soldal_node_sagdal_siralayici([Link]);
[Link]([Link]+" ");
if(node==null) return;
sagdal_node_soldal_siralayici([Link]);
sagdal_node_soldal_siralayici([Link]);
[Link]([Link]+" ");
3.
Bu program Gebze Yüksek teknoloji enstitüsü Java programla dili dersi, 2000 Güz dönemi
öðrencilerinden Deniz KAYA tarafýndan yazýlmýºtýr.
// Deniz KAYA
// H10OD2_2000
import Tree;
import TreeNode;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
String url="jdbc:odbc:prog";
Connection con;
Statement stmt;
try
[Link]("[Link]");
catch([Link] e)
[Link]([Link]());
try
con=[Link](url);
stmt=[Link]();
[Link]();
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch (SQLException e)
[Link]([Link]());
} //catch
};
if(node==null) return;
soldal_node_sagdal_siralayici([Link]);
veriyazdir([Link]);
soldal_node_sagdal_siralayici([Link]);
int sayi;
String url="jdbc:odbc:prog";
Connection con;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Statement stmt;
try
[Link]("[Link]");
catch([Link] e)
[Link]([Link]());
try
con=[Link](url);
stmt=[Link]();
while ([Link]())
[Link](xi);
agac.soldal_node_sagdal_sirala();
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
h.soldal_node_sagdal_siralayici([Link]);
catch (SQLException e)
[Link]([Link]());
} //catch
ID anahtar alan
isim
soyisim
adres
ilce
il
postakodu
ulke
emailadresi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
telefonev
telefonis
telefoncep
faks
webadresi
evadresi
alanlarý tanýmlanacaktýr.
Temel access veri tabaný tanýmlamasýný acsess’de yaptýk. veri tabaný dosyasýnýn ismi adres
olarak tanýmlandý. Veri tabanýnýn görünümü:
[Link]
ºeklindedir. Bu programý oluºturabilmek için bir dizi program tanýmý yapýldý. Bunlar
[Link], [Link], [Link], adressil, [Link], [Link],
[Link] ve [Link] programlarýdýr. Bu programlarýn kodlarýný verelim :
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class adresdefteri extends JFrame {
public adresdefteri()
Container c = getContentPane();
[Link] );
try {
url = "jdbc:odbc:adres";
[Link]( "[Link]" );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
catch ( ClassNotFoundException cnfex ) {
[Link]();
[Link]() );
[Link]();
[Link]() );
catch ( Exception ex ) {
[Link]();
[Link]( [Link]() );
controls =
show();
[Link](new BasicWindowMonitor());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
// [Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
query+=a[0]+ "', '";
query+=a[1]+ "', '" ;
query+=a[2]+ "', '" ;
query+=a[3]+ "', '" ;
query+=a[4]+ "', '" ;
query+=a[5]+ "', '" ;
query+=a[6]+ "', '" ;
query+=a[7]+ "', '" ;
query+=a[8]+ "', '" ;
query+=a[9]+ "', '" ;
query+=a[10]+ "', '" ;
query+=a[11]+ "', '" ;
query+=a[12]+ "', '" ;
query+=a[13]+ "')";
[Link]( "\nSQL query gönderiliyor: " +
[Link]( query )
+ "\n" );
int result = [Link]( query );
if ( result == 1 )
[Link]( "\nQuery baþarýyla çalýþtý\n" );
else {
[Link]( "\nQuery hata verdi\n" );
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link](" ");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
}
else
[Link]( "\nen azýndan isim ve soy isim girin ve sonra " +
"ekle dugmesine basýn\n" );
[Link]();
}
catch ( SQLException sqlex ) {
[Link]();
[Link]( [Link]() );
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// [Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
JTextArea o )
connection = c;
fields = f;
output = o;
try {
if ( ![Link]().equals( "" )
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String query = "SELECT * FROM adres " +
[Link]() + "'"+
[Link]() + "'";
[Link]( query )
+ "\n" );
display( rs );
[Link]();
[Link]() + "'";
[Link]( query )
+ "\n" );
display( rs );
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if ( ![Link]().equals( "" ) ) {
[Link]() + "'";
[Link]( query )
+ "\n" );
display( rs );
[Link]();
else
[Link](
[Link]();
[Link]( [Link]() );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
try {
[Link]();
if ( recordNumber != 0 ) {
[Link]([Link]( 2 ));
[Link]([Link]( 3 ));
[Link]([Link]( 4 ));
[Link]([Link]( 5 ));
[Link]([Link]( 6 ));
[Link]([Link]( 7 ));
[Link]([Link]( 8 ));
[Link]([Link]( 9 ));
[Link]([Link]( 10 ));
[Link]([Link]( 11 ));
[Link]([Link]( 12 ));
[Link]([Link]( 13 ));
[Link]([Link]( 14 ));
[Link]([Link]( 15 ));
else
[Link]();
[Link]( [Link]() );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
String query = "UPDATE adres SET ";
query+="isim ='";query+=[Link]();
query+="',soyisim ='";query+=[Link]();
query+="',adres ='";query+=[Link]();
query+="',ilce ='";query+=[Link]();
query+="',il ='";query+=[Link]();
query+="',postakodu ='";query+=[Link]();
query+="',ulke ='";query+=[Link]();
query+="',emailadresi ='";query+=[Link]();
query+="',telefonev ='";query+=[Link]();
query+="',telefonis ='";query+=[Link]();
query+="',telefoncep ='";query+=[Link]();
query+="',faks='";query+=[Link]();
query+="',webadresi ='";query+=[Link]();
query+="',evadresi ='";query+=[Link]();
query+="' WHERE ID=";query+=[Link]();
[Link]( "\nquery gönderiliyor : " +
[Link]( query ) + "\n" );
int result = [Link]( query );
if ( result == 1 )
[Link]( "\nkayýt baþarýyla deðiþtirildi \n" );
else {
[Link]( "\nkayit deðiþtirme iþlemi baþarýlamadý\n" );
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("" );
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
}
[Link]();
} //
} //end of if
else
[Link]( "\nsadece mevcut olan kayýtlarý deðiþtirebilirsiniz\n" );
}
catch ( SQLException sqlex ) {
[Link]();
[Link]( [Link]() );
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
fields = f;
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
[Link](" ");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](" ");
import [Link].*;
import [Link].*;
import [Link].*;
ilce, il,postakodu,ulke,emailadresi,telefonev,
telefonis,telefoncep,faks,webadresi,evadresi;
public adrespanel()
{ // Label
[Link](
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
new GridLayout( [Link], 1 ) );
// TextField panel
[Link](
id = new JTextField( 20 );
[Link]( false );
[Link]( id );
[Link]( isim );
[Link]( soyisim );
[Link]( adres );
[Link]( ilce );
il = new JTextField( 20 );
[Link]( il );
[Link]( postakodu );
[Link]( ulke );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]( emailadresi);
[Link]( telefonev );
[Link]( telefonis );
[Link]( telefoncep );
[Link]( faks );
[Link]( webadresi );
[Link]( evadresi );
add( labelPanel );
add( fieldsPanel );
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class ciktipaneli extends JPanel {
JTextArea t )
add( findName );
add( addName );
[Link](
new adresdegistir( c, s, t ) );
add( updateName );
add( clear );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
help = new JButton( "YARDIM" );
add( help );
import [Link].*;
import [Link].*;
import [Link].*;
output = o;
[Link]( "\nbir kayýt bulmak için isim ve/veya soyisim alanýna yazýp BUL
düðmesine basýnýz\n" +
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java programlama dili C dilinde yazýlmýºtýr. Bu yüzden C’den javaya geçiº oldukça kolay bir
ºekilde yapýlabilir. Bir örnekle birden fazla programlama dilinin nasýl kullanýlabildiðine
bakmadan önce, bir temel kavramý iyi anlamamýz gerekir. Java güvenlik açýsýndan
maksimum güvenliði verebilen bir dildir. Öte taraftan C maksimum hýzlara ulaºmayý
saðlayabilen bir dildir. C programlarýný java programlarýyla birlikte kullanmamýzýn temel
nedeni hýz gereken yerlerde bu hýzý saðlamaktýr. Ancak hýz saðlarken güvenlikten olan
kaybýmýzý her zaman hesaba katmamýz ve ikisi arasýnda bir denge bulmamýz biz
programcýlara býrakýlmýºtýr. Bu yüzden iki dilli programlamada oldukça dikkatli bir ºekilde
çalýºma gereksinimi oluºturur. Bu konu C++ dilini iyi bilen programcýlar içindir. Burada C
programlamasýna girmeyeceðiz. Eðer bu dili bilmiyorsanýz, bu konuya baºlamadan önce
öðrenmenizi veya java anadil programlamasýný hiç kullanmamanýzý tavsiye ederim. C++ dilini
kullanabilmek için, hele iki dili bir arada kullanabilmek için iyi bir programcý olmanýz gerekiyor,
eðer kendinizi güveniyorsanýz, bundan sonraki kýsma geçebilirsiniz.
14.2 Örnek problemle step step iki dilli program kodunun hazýrlanmasý ve çalýºtýrýlmasý
Çok dilli programlama birden fazla basamaðý gerektiren bir prosestir. Bir örnek problemler bu
basamaklarý inceleyelim :
C++ dili ile java dilinin beraber çalýºacaðý bir örnek oluºturalým. Ýlk step olarak java dilindeki
programýmýzý yazalým :
class JavaCpp
static
[Link]("jcpp");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
new JavaCpp().cdenaktar();
JavaCpp programýnda iki temel metod görüyoruz. Birinci metod cdenaktar() metodudur. Bu
metod biraz sonra C++ dilinde oluºturacaðýmýz fonksiyonu Java’nýn bir parçasý olarak çaðýrýr.
Ýkinci metod ise main metodudur. Cdenaktar metoduna bakarken bunun java metodu
olmadýðýný belirten native sözcüðü yer almaktadýr. Metodun türü void’dir, yani hiçbir ºey
aktarýlmýyacaktýr. Programýmýzý, herhangi bir java programýnda olduðu gibi önce
java [Link]
javah JavaCpp
#include <jni.h>
#ifndef _Included_JavaCpp
#define _Included_JavaCpp
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JavaCpp
* Method: cdenaktar
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* Signature: ()V
*/
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endif
ºeklinde olacaktýr. Bundan sonraki stepte C++ dilinde aºaðýdaki programý oluºturalým :
#include <iostream.h>
#include <jni.h>
#include "JavaCpp.h"
return;
c++ programýný derlemek için elbette bir derleyiciye ihtiyaç vardýr. Biz burada MS Visual C++
versiyon 6 derleyicisini kullandýk, herhangi bir dll dosyasý hazýrlayan derleyici (MS Windows
için) ayný iºi görebilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Bu derleyici ile derleme için ya direk olarak dos’ta
komutunu kullanýrýz, yada bu uzun komutu her sefer yazmamak için bir [Link] dosyasý
yaratýp bunu kullanabiliriz. Örneðin hazýrladýðýmýz [Link] dosyasý
java JavaCpp
Ýlk programýmýzda java ve C++ arasýnda herhangi bir deðiºken aktarýlmasý olmamýº, sadece
void türü fonksiyon kullanýlarak belli bir yazý yazan C++ fonksiyonu çaðýrýlmýºtýr. Ýkinci
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
örneðimizde java programýmýzdan String türü deðiºkeni C++ programlama diline aktaracak
ve kullanacaðýz.
Ýlk java programýmýz [Link]. bu programda ekrandan girilen bir string, yahut
ekrandan girilen bir string deðeri yoksa programýn içinde tanýmlanan bir stringle birlikte C++
programýna aktarýlýp burada ekrana yazýlmaktadýr.
static { [Link]("MsgI"); }
if([Link]==0)
else
[Link](args[0]);
//dosya : [Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
#include <jni.h>
#include <iostream.h>
#include <stdio.h>
#include "ShowMessage.h"
Java_ShowMessage_ShowMessage(JNIEnv* env,
env->ReleaseStringUTFChars(jMsg, msg);
veya
Çýktýsý alýnabilir. Programda veri aktarýmý yapmak amacýyla java tarafýnda metod tanýmý
yapýlýrken
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private native void ShowMessage(String msg);
tanýmý verilmiºtir. Buradaki String msg metodun dolayýsýyla C++ fonksiyonunun girdisini teºkil
etmektedir. C++ tarafýnda mesajý alýrken,
Java_ShowMessage_ShowMessage(JNIEnv* env,
Javada Stringler unicode (16 bit) olarak tanýmlanmýºtýr. C stringleri ise 8 bitlik ascii char
boyutlu deðiºkeni olarak tanýmlanýr. Bu yüzden string deðiºkenlerini javadan cye veya cden
javaya aktarýrken dönüºümler yapmak gerekir. Ayný zamnda java string deðiºkenleri length
(boyut) deðiºkenini de bünyelerinde taºýrlar. Cde ise boyut tanýmlanmamýºtýr. Ayrý bir
deðiºken üzerinden tanýmlanmasý gerekebilir. Bu dönüºümleri yapmak için bir dizi metod
tanýmlanmýºtýr.
GetStringChars
GetStringLength
GetStringUTFChars
GetStringUTFLength
NewString
NewStringUTF
ReleaseStringChars
ReleaseStringUTFChars
Buradaki ikinci örneðimizde java programýnda c++ dilindeki bir fonksiyonun (metod) yaptýðý
hesap sonuçlarýný aktaracaðýz. Programýmýz java’da çaðýrýlan bir C++ kare metodunu
kullanarak java dilinde girilen sayýnýn karesini hesaplayacaktýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 14.7 [Link] programý
class karesinifi {
double x=2.0;
double y = [Link](x);
static {
[Link]("kareI");
#include <jni.h>
#ifndef _Included_karesinifi
#define _Included_karesinifi
#ifdef __cplusplus
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
extern "C" {
#endif
/*
* Class: karesinifi
* Method: kare
* Signature: (D)D
*/
#ifdef __cplusplus
#endif
#endif
#include <stdio.h>
#include <jni.h>
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
#include "karesinifi.h"
return x*x;
burada metod isminin kare yerine Java_karesinifi_kare ºeklini aldýðýný görüyoruz. Double
deðiºkeni de yerini jdouble deðiºkenine býrakmýº durumda. Java anadilinde programlarý
yazarken metod isimleri
Java_sýnýfismi_metodismi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
deyimiyle derlenirse (MS Visual C++ 6), sonuç :
ºeklinde çýkacaktýr.
ªimdi de bu iºlemin tam tersini inceleyelim. Java’da yazýlmýº olan kare metodunu C++ ve C
dillerinde çaðýralým.
class karesinifi1 {
return x*x;
[Link]();
static {
[Link]("kare1I");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sýnýfýn alt sýnýfý olan kare’de girilen sayýnýn karesi hesaplanmaktadýr. NativeMethod metodu
da C (veya c++) dilleriyle baðlantý saðlamaktadýr. Metodumuzu yine java [Link] ile
derledikten sonra javah karesinifi1 komutuyla karesinifi1.h dosyasýný oluºtururuz. Bu dosya :
#include <jni.h>
#ifndef _Included_karesinifi1
#define _Included_karesinifi1
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: karesinifi1
* Method: nativeMethod
* Signature: ()V
*/
(JNIEnv *, jobject);
#ifdef __cplusplus
#endif
#endif
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
anadil tarafýnda program yazýlýrken bize yardýmcý olabilecek bir ara java programý javap de
mevcuttur.
Bu iºlemi yapmak zorunda deðiliz. Yapma sebebimizi c++ dili programýný inceleyince daha iyi
anlayacaksýnýz.
javap -s -p karesinifi1
karesinifi1();
/* ()V */
/* ()V */
/* (D)D */
/* ([Ljava/lang/String;)V */
static {};
/* ()V */
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
#include <stdio.h>
#include <iostream.h>
#include <jni.h>
#include "karesinifi1.h"
jclass cls=env->GetObjectClass(obj);
jmethodID mid=env->GetMethodID(cls,"kare","(D)D");
double x=2.0;
double y=env->CallDoubleMethod(obj,mid,x);
jclass cls=env->GetObjectClass(obj);
üzerinden yapýlýr. Burada sýnýf adresi cls deðiºkenine yüklenmiº olur. Alt metod karenin
tanýmý için
jmethodID mid=env->GetMethodID(cls,"kare","(D)D");
tanýmý kullanýlmýºtýr. Buradaki “(D)D” tanýmý program 14.12 de bize verilmiºti. Anlamý java
programýndaki kare metodunun double deðiºken giriºi olduðu ve çýkýºýnda double deðiºken
istediðidir. “kare” deyimiyle metodun javadaki ismi verilmiºtir. Cls ise üstte tanýmladýðýmýz
karesinifi1 java sýnýfýnýn adresine belirtmektedir.
double y=env->CallDoubleMethod(obj,mid,x);
Burada kullandýðýmýz D iºareti java deðiºken türünün double olduðunu belirtiyordu. Java
deðiºken tiplerinin iºaret karºýlýklarý Tablo 14.2 de verilmiºtir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Tablo 14.2 Java tiplerinin eºdeðer iºaretleri
CallBooleanMethod
CallByteMethod
CallCharMethod
CallDoubleMethod
CallFloatMethod
CallIntMethod
CallLongMethod
CallObjectMethod
CallShortMethod
CallVoidMethod
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
türleri kabul eder.
#include <stdio.h>
#include <jni.h>
#include "karesinifi1.h"
jclass cls=(*env)->GetObjectClass(env,obj);
jmethodID mid=(*env)->GetMethodID(env,cls,"kare","(D)D");
double x=2.0;
double y=(*env)->CallDoubleMethod(env,obj,mid,x);
jclass cls=env->GetObjectClass(obj);
komutu
jclass cls=(*env)->GetObjectClass(env,obj);
halini almýºtýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
jmethodID mid=env->GetMethodID(cls,"kare","(D)D");
komutu
jmethodID mid=(*env)->GetMethodID(env,cls,"kare","(D)D");
halini almýºtýr.
double y=env->CallDoubleMethod(obj,mid,x);
komutu ise
double y=(*env)->CallDoubleMethod(env,obj,mid,x);
halini almýºtýr. Sonuç olarak env yerine referans deðiºkeni (*env) gelmektedir ve env referans
deðiºkeni ayný zamanda metod deðiºkeni olarakda çaðýrýlmaktadýr. Bunun dýºýnda iºlemler
arasýnda bir fark yoktur.
2nin karesi = 4
sonucunu alýrýz.
Ýkinci bir sýnýf ulaºým örneði olarak UseObjects programýný verelim. Burada sýnýf,
MyJavaClass içinde bir int deðiºken ve bir void metod mevcuttur. Ýkinci bir metod olan
UseObjects metodu kullanýlarak native metod changeObject’e ulaºýlmakta ve bu metod c++
programýnda kullanýlarak sonuçlar hesaplanmaktadýr.
//[Link]
class MyJavaClass {
changeObject(MyJavaClass obj);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
static {
[Link]("UseObjImpl");
[Link] = 2;
[Link](anObj);
#include <jni.h>
#ifndef _Included_UseObjects
#define _Included_UseObjects
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: UseObjects
* Method: changeObject
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
* Signature: (LMyJavaClass;)V
*/
#ifdef __cplusplus
#endif
#endif
#include <jni.h>
env->CallVoidMethod(obj, mid);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 14.15 de tanýmlanan MyJavaClass sýnýfý bir int deðiºken, aValue, ve bir metod,
divByTwo , içermektedir. Metod int de verilen deðeri 2 ye bölmekte ve sonucu aktarmaktadýr.
Bu programda int sýnýf alt deðiºkenini tanýmlamak için
deyimiyle tanýmlandý. Ve
GetFieldID
GetStaticFieldID
GetBooleanField
GetByteField
GetCharField
GetDoubleField
GetFloatField
GetIntField
GetLongField
GetObjectField
GetShortField
Metodlarý mevcuttur.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªimdi de Çok boyutlu deðiºkenleri nasýl kullanabildiðimizi inceleyelim :
class IntArray {
arr[i] = i;
static {
[Link]("MyImpOfIntArray");
#include <jni.h>
#include "IntArray.h"
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Java_IntArray_sumArray(JNIEnv *env, jobject obj, jintArray arr)
int i, sum = 0;
sum += body[i];
return sum;
deyimiyle aktarýlmýºtýr.
arr deðiºkeninin deðeri jint tipi body boyutlu deðiºkene, indeksi 0dan baºlamak üzere
metoduyla aktarýlýr.
arr boyutlu deðiºkeninin deðeri (deðerler deðiºmiºte olabilir) tekrar kullanýlabilmek üzere
sum = 45
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
GetArrayLength
GetBooleanArrayElements
GetByteArrayElements
GetCharArrayElements
GetDoubleArrayElements
GetFloatArrayElements
GetIntArrayElements
GetLongArrayElements
GetShortArrayElements
GetObjectArrayElement
SetObjectArrayElement
Java dilinde tanýmlanmýº, fakat c dilinde direk tanýmlanmamýº iºlemlerden birisi de hata
analiz iºlemidir (Catch-throw exception). Ana dil programlamasý kullanýrken, bu iºlemi de
yapmak mümkündür. Aºaðýdaki CatchThrow program setinde hata sisteminin kullanýlmasýný
görüyoruz.
class CatchThrow {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
try {
[Link]();
} catch (Exception e) {
static {
[Link]("MyImpOfCatchThrow");
#include <jni.h>
#include "CatchThrow.h"
jthrowable exc;
if (mid == 0) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
return;
exc = (*env)->ExceptionOccurred(env);
if (exc) {
/*
jclass newExcCls;
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return;
bu programý çalýºtýrdýðýmýzda :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sonucunu alýrýz. Buradaki
In Java:
ExceptionClear
ExceptionDescribe
ExceptionOccurred
Burada iki dilli programlama kavramýna bir giriº yaptýk. Buradaki kavramlar size biraz zor
geldiyse lütfen umutsuzluða kapýlmayýn, java ve C dillerini çok iyi öðrendikten sonra geri
dönün. Ýki dilli programlama her zaman programlama dünyasýnýn en zor iºlerindendir, ayrýca
jbuilder, Microsoft j++ gibi paketler java anadil (native) programlamasýnda iºleri kolaylaºtýran
otomatik kod oluºturma sisyemleri sunarlar, bu tür programlama araçlarýyla iºinizi daha kolay
hale getirebilirsiniz.
Java beans tekrar kullanýlabilir paketler halinde java programlamasý geliºtiren, ayný zamanda
hýzlý yeni geliºtirmelere de ön ayak olan bir programlama sistemidir. Daha önceden
programlanmýº hazýr program paketçiklerinin ve apletlerinin bilgisayarlar arasýnda hýzlý bir
ºekilde alýºveriºine yardýmcý olan bir sistemdir. "Java beans" kavramý yeni bir programlama
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ºeklini getirebilir. Bu kod yazma yerine program parçacýklarýný birleºtirerek programlama
yapan bir programcý olabilir.
Java beans sistemini kullanmak için "JavaBeans development kit" Java bean kullanma
seti'ne ihtiyacýnýz vardýr. Bu seti [Link] adresinden
kopyalayabilirsiniz. Java bean kullanma setinin Java 1.1 versiyonu da olmakla birlikte biz
burada 1.2 versiyonunun kullanýldýðýný varsayacaðýz.. Java Bean geliºtirme setini kullanmak
için önce programý kurmamýz gerekir. Paketi java dosyalarýnýzýn olduðu ana dosyanýn bir alt
dosyasý veya baðýmsýz bir dosya sisteminde tanýmlayabilirsiniz. Bu dosyanýn alt dosyasý
olarak beanbox alt dosyasý mevcuttur. Bu dosyanýn altýnda window sisteminde [Link],
unix sisteminde [Link] dosyasýný bulacaksýnýz. bu dosyayý açtýðýnýzda beanbox açýlacaktýr.
Beanbox programýný açtýðýmýzda, yanýnda Toolbox(aletkutusu), Properties (özellikler) ve
Method tracer( metot izleyici) adý verilen programlarý da göreceðiz. ToolVox kutusunda jars
alt dosyasýnda yer aln bean program paketlerinin listesini göreceðiz bunlarýn birini secip
BeanBox kutusuna getirince bu program çalýºmaya baºlýyacaktýr. Örneðin ªekil 15.1 de
Bean Box ve içinde çalýºan Jogler programýný görmekteyiz.
[Link]
ªimdi kendi bean programýmýzý nasýl yazabileceðimize bir göz atalým. Daha önceki
bölümlerde [Link] programýný geliºtirmiº ve bu programdan yola çýkarak analog saat ve
çeºitli çizim programlarý yazmýºtýk. Önce [Link] programýnýn swing ve Graph2D olarak
deðiºtirlmiº ºekline bir göz atalým
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 15.1 [Link] programý, yildiz sýnýfý
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import polar;
public static void drawYildiz1(Graphics g2,int xi,int yi, int n,int yildizboyu,double aci )
Graphics2D g=(Graphics2D)g2;
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
for(int i=0;i<n;i++)
double teta1=teta*i+[Link]/2.0+aci;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double teta2=teta/2+teta1;
[Link](R,teta1);
[Link](r,teta2);
[Link]((xi+(int)[Link]()),(yi-(int)[Link]()),
(xi+(int)[Link]()),(yi-(int)[Link]()));
double teta3=teta*(i+1)+[Link]/2.0+aci;
[Link](R,teta3);
[Link]((xi+(int)[Link]()),(yi-(int)[Link]()),
(xi+(int)[Link]()),(yi-(int)[Link]()));
[Link](xi,yi,
(xi+(int)[Link]()),(yi-(int)[Link]()));
[Link](xi,yi,
(xi+(int)[Link]()),(yi-(int)[Link]()));
public static void drawYildiz1(Graphics g2,int xi,int yi, int n,int yildizboyu )
drawYildiz1(g2,xi,yi,n,yildizboyu,0);
public static void drawYildiz(Graphics g2,int xi,int yi, int n,int yildizboyu,double aci )
Graphics2D g=(Graphics2D)g2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
[Link]);
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2.0+teta1;
[Link](R,teta1);
[Link](r,teta2);
x[2*i]=xi+(int)[Link]();
y[2*i]=yi-(int)[Link]();
x[2*i+1]=xi+(int)[Link]();
y[2*i+1]=yi-(int)[Link]();
if(i==n)
x[2*i]=x[0];
y[2*i]=y[0];
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
for(int i=0;i<=2*n;i++)
if(i==0)
[Link](x[0],y[0]);
else
[Link](x[i],y[i]);
[Link](polygon);
public static void fillYildiz(Graphics g2,int xi,int yi, int n,int yildizboyu,double aci )
Graphics2D g=(Graphics2D)g2;
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
polar P3=new polar();
[Link]);
for(int i=0;i<=n;i++)
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta/2.0+teta1;
[Link](R,teta1);
[Link](r,teta2);
x[2*i]=xi+(int)[Link]();
y[2*i]=yi-(int)[Link]();
x[2*i+1]=xi+(int)[Link]();
y[2*i+1]=yi-(int)[Link]();
if(i==n)
x[2*i]=x[0];
y[2*i]=y[0];
for(int i=0;i<=2*n;i++)
if(i==0)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](x[0],y[0]);
else
[Link](x[i],y[i]);
[Link](polygon);
public static void fillAkrep(Graphics g2,int xi,int yi, int n,int yildizboyu,double aci,int i )
Graphics2D g=(Graphics2D)g2;
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]);
x[0]=xi;
y[0]=yi;
x[4]=xi;
y[4]=yi;
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta1+teta/2.0;
double teta3=teta1-teta/2+[Link]*2;
[Link](R,teta1);
[Link](r,teta2);
[Link](r,teta3);
x[1]=xi+(int)[Link]();
y[1]=yi-(int)[Link]();
x[2]=xi+(int)[Link]();
y[2]=yi-(int)[Link]();
x[3]=xi+(int)[Link]();
y[3]=yi-(int)[Link]();
for(i=0;i<5;i++)
if(i==0)
[Link](x[0],y[0]);
else
[Link](x[i],y[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link](polygon);
public static void drawAkrep(Graphics g2,int xi,int yi, int n,int yildizboyu,double aci,int i )
Graphics2D g=(Graphics2D)g2;
double teta=2.0*[Link]/n;
double R=yildizboyu;
double r=yildizboyu*0.25;
[Link]);
x[0]=xi;
y[0]=yi;
x[4]=xi;
y[4]=yi;
double teta1=teta*i+[Link]/2.0+aci;
double teta2=teta1+teta/2.0;
double teta3=teta1-teta/2+[Link]*2;
[Link](R,teta1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](r,teta2);
[Link](r,teta3);
x[1]=xi+(int)[Link]();
y[1]=yi-(int)[Link]();
x[2]=xi+(int)[Link]();
y[2]=yi-(int)[Link]();
x[3]=xi+(int)[Link]();
y[3]=yi-(int)[Link]();
for(i=0;i<5;i++)
if(i==0)
[Link](x[0],y[0]);
else
[Link](x[i],y[i]);
[Link](polygon);
Graphics2D g=(Graphics2D)g2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](new [Link]((int)(xi-R),(int)(yi-R),2*R,2*R));
Graphics2D g=(Graphics2D)g2;
[Link](new [Link]((int)(xi-R),(int)(yi-R),2*R,2*R));
ªimdi ilk bean programýmýzý hazýrlýyalým. Önce programýmýzý yazalým. program 15.2 de
[Link] programý görülmektedir. Bu programda Serializable sýnýfý implement
edilmiºtir. bunun dýºýnda normal bir java programýdýr. Programýn Jpanel olarak yazýlmýº
olduðuna dikkat edelim. Bu yüzden
java yildizciz2Dbean
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class yildizciz2Dbean extends JPanel implements ActionListener,Serializable
public yildizciz2Dbean()
setSize(getPrefferedSize());
setBackground(bg);
setForeground(fg);
return getPrefferedSize();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](g2);
Dimension boyut=getSize();
int dx=[Link]/2;
int dy=[Link];
[Link](getBackground());
g.draw3DRect(0,0,[Link]-1,[Link]-1,true);
g.draw3DRect(3,3,[Link]-7,[Link]-7,false);
//cizgiciz
[Link](g,dx/2,dy/2, 3,dy/2-5,0 );
[Link]([Link]);
[Link](g,dx/2,dy/2, 3,dy/2-5,0 );
[Link]([Link]);
yildizSW.drawYildiz1(g,3*dx/2,dy/2, 3,dy/2-5,0 );
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]().add(yildiz,[Link]);
[Link](
new WindowAdapter()
[Link](0);
);
[Link]([Link]().width+10,
[Link]().height+30);
[Link]();
Bölüm 7.14 de bir tür program paketleme yolu olan jar deyimi ve kullanýlmasýndan kýsaca
bahsedilmiºti. Burada programýmýzý bir jar dosyasý haline getireceðiz. Fakat bunu yaparken
ayný zamanda hem jarýn içinde hangi dosyanýn ana programý içerdiðini, hemde Java-bean
olarak kullanýlma izni veren Java_Bean komutunu veren MANIFEST:MF dosyasýný
oluºturacaðýz. Bunu yapmak için [Link] isimli birdosya hazýrlayacaðýz. Bu dosyanýn
içeriði :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Main-Class: yildiz2Dbean
Name: [Link]
Java-Bean: True
komutunu kullanabiliriz. Burada yildizSW da kullanýlan polar, renk sýnýflarýnýn da jar gurubuna
ilave edildiðine dikkat edelim. Bu komut [Link] dosyasýný yaratacaktýr. ªimdi programýmýzý
komutuyla da çalýºtýrýlabilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
143 Sat Mar 04 11:18:32 GMT+02:00 2000 META-INF/[Link]
Ýkinci bir örnek olarak ayný yýldýz çizme prosesini amimasyon olarak yapacak
[Link] programýný veriyoruz. Bu programda kullanýlan stopAnimation() ve
startAnimation() metodlarý animasyonu baºlatma ve durdurma iºlevlerini görmektedirler.
Animasyon baºladýðýnda çizilen yýldýz dönmektedir. Program 15.3 de bu programýn listesi
verilmiºtir.
yildizAnimator programý bir önceki yildizciz2Dbean programýna göre biraz daha detaylýdýr.
örneðin yýldýzýn kanat sayýsýný deðiºtirebilen metodlara sahiptir. Burada da bir öceki
programla ayný yollarý izleyerek [Link] dosyasýný oluºrurduk ve jars alt
direktörüsüne yerleºtirdik.
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 15.3 [Link] programý
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public yildizAnimator()
setSize( getPreferredSize() );
startAnimation();
yildizkosesayisi=5;
aci=0;
setForeground([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void paintComponent( Graphics g2 )
[Link]( g2 );
Dimension boyut=getSize();
int dx=[Link];
int dy=[Link];
[Link](getBackground());
[Link](getForeground());
yildizSW.drawYildiz1(g,dx/2,dy/2, yildizkosesayisi,dy/2-5,aci);
aci+=piaci;
yildizkosesayisi=syks;
return yildizkosesayisi;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
aci=iaci;
return aci;
animationDelay=iad;
return animationDelay;
repaint();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if ( animationTimer == null )
[Link]();
else // continue
if ( ! [Link]() )
[Link]();
[Link]();
return getPreferredSize();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
[Link](
new WindowAdapter() {
[Link]( 0 );
);
[Link]().height + 30 );
[Link]();
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 15.3 [Link] programýnýn BeanBox'ta görünümü
ªu ana kadar yeni bir ortamda çalýºmakla birlikte bu bölümün baºýnda söylediðimiz gibi
programlama olmadan çalýºtýðýmýzý söylemek pek mümkün deðil. Fakat bundan sonraki
kýsýmlarda programý bilgisayar oluºturacaktýr. Örnegin yildiz döndüren yildizAnaimator
programýmýza animasyonu baºlatacak ve durduracak komutlar ilave etmek isteyelim. Bunun
için yeni bir program yazmak mümkündür. Fakat program yazmadan bu yeni düzenlemeyi
BeanBox üzerinden gerçekleºtirebiliriz. Bunu yapmak için önce beanBox'ta daha önce hazýr
olarak tanýmlanmýº bulunan ExplicitButton bean'ini seçelim ve bean box'a ilave edelim.
Daha sonra properties penceresindeki , "press" yazýsýný "animasyonu baslat" olarak
deðiºtirelim. Ayný iºlemi tektrarlayarak "animasyonu durdur düðmesi oluºturalým. Sonra
Animasyomu baºlat düðmesini seçelim. BeanBox da Edit, Events, button
push,actionPerformed dizisini seçtikten sonra faremizin ucunda bir doðru oluºacaktýr. bu
doðruyu yildizAnimasyon penceresinin içine çekerek sol mouse düðmesine basalým.
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
[Link]
Oluºan yeni programý kaydedebiliriz. Bilgisayarýn oluºturduðu java program kodu aºaðýdaki
gibidir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 15.4 [Link] programýna BeanBox'da animasyon baºlatma ve
durdurma düðmelerinin eklenmesinden sonra otomatik olarak oluºturulan
serizalizable [Link] program
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public MyApplet() {
InputStream is = [Link]().getResourceAsStream("MyAppletData");
if (is == null) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
throw new Error("Could not locate the Applet data at MyAppletData");
[Link](null);
try {
initContentsFromStream(ois);
// Preferred size
return getMinimumSize();
// Preferred size
throws [Link],
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
if (! [Link]("MyApplet")) {
initContents();
throws [Link],
[Link]
myLoader = [Link]().getClassLoader();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// Create nested beans
addConnections();
try {
//
[Link](yildizAnimator1);
[Link](hookup0);
//
[Link](yildizAnimator1);
[Link](hookup1);
//
// hookup0 = addPropertyTarget(
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
// ourButton1,
// "foreground",
// "background",
[Link]();
try {
//
//
//
// hookup0 = addPropertyTarget(
// ourButton1,
// "foreground",
// "background",
// [Link](hookup0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
throws [Link],
[Link]
myLoader = [Link]().getClassLoader();
if (! [Link]("MyApplet")) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
acquire(yildizAnimator1, null);
acquire(explicitButton1, null);
acquire(explicitButton2, null);
addReconnections();
throws [Link]
data[0] = "MyApplet";
data[1] = yildizAnimator1;
data[2] = explicitButton1;
data[3] = explicitButton2;
[Link](data);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private [Link] explicitButton2;
// The hookups
// ===========================================
// Support code
// ===========================================
// Acquire a bean
return;
[Link]((Applet) bean,
myLoader,
[Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
add((Component) bean);
if (boundsData != null) {
((Component) bean).setBounds(boundsData);
((Applet)bean).start();
String propertyName,
Object targetObject,
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if (hook == null) {
[Link](source, hook);
types[0] = pClass;
args[0] = hook;
[Link](source, args);
// get setter
getClassFromTypes(setterTypeNames));
return hook;
Class c = unwrapPrimitiveStringToClass(types[i]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
if (c == null)
back[i] = [Link](types[i]);
else
back[i] = c;
return back;
return null;
// ===========================================
// ===========================================
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªüphesiz bu program kodunu biz çok daha kýsa ve etkili ekilde yazabilirdik, ancak otomatik
kod oluºturmanýn zamansal olarak saðladýðý avantaj ile bizim harcayacaðýmýz zamanýn bize
ilave maliyeti hesaplanarak optimal çözümler oluºturulabilir.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
JTextField sonucgirdisi;
JTextField kutugirdisi;
JButton Gir,Arti,Eksi,Carpi,Bolu,M,MR,MArti,MEksi,Isaret,C;
JButton Pow,Cos,Sin,Tan,RtoD,DtoR,Acos,Asin,Atan,Exp,Kok,Kare,birBoluX;
JButton Ln,Log10,Oku,PI;
double sayi;
bilimselhesapmakinasi1 D;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public H4O1bSWbean()
D=new bilimselhesapmakinasi1();
Container c=getContentPane();
[Link](new BorderLayout());
sonucgirdisi=new JTextField();
[Link](false);
[Link]([Link]);
[Link](new Font("SansSerif",[Link],14));
[Link](new GridLayout(2,1));
kutugirdisi=new JTextField(40);
[Link](new Font("SansSerif",[Link],14));
[Link](sonucgirdisi);
[Link](kutugirdisi);
[Link](e,[Link]);
M=new JButton("M");
MR=new JButton("MR");
MArti=new JButton("M+");
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
MEksi=new JButton("M-");
Isaret=new JButton("+/-");
C=new JButton("C");
Pow=new JButton("x^y");
Cos=new JButton("cos");
Sin=new JButton("sin");
Tan=new JButton("tan");
RtoD=new JButton("R->D");
DtoR=new JButton("D->R");
Acos=new JButton("acos");
Asin=new JButton("asin");
Atan=new JButton("atan");
Exp=new JButton("exp");
Ln=new JButton("ln");
Log10=new JButton("log10");
Kok=new JButton("x^0.5");
Kare=new JButton("x^2");
PI=new JButton("pi");
[Link](new GridLayout(5,8));
[Link](Gir);
[Link](Oku);
[Link](Arti);
[Link](Eksi);
[Link](Carpi);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](Bolu);
[Link](M);
[Link](MR);
[Link](MArti);
[Link](MEksi);
[Link](Isaret);
[Link](C);
[Link](Pow);
[Link](Cos);
[Link](Sin);
[Link](Tan);
[Link](DtoR);
[Link](RtoD);
[Link](birBoluX);
[Link](Acos);
[Link](Asin);
[Link](Atan);
[Link](Kok);
[Link](Kare);
[Link](Exp);
[Link](Ln);
[Link](Log10);
[Link](PI);
[Link](m,[Link]);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
String ss=[Link]();
if([Link]("")) sayi=0.0;
else
sayi=[Link]();
if([Link]()==Gir) [Link](sayi);
if([Link]()==Oku) [Link]();
if([Link]()==PI) [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
else if([Link]()==Cos) [Link](sayi);
[Link]([Link]());
if([Link]()==MR || [Link]()==M ||
[Link]()==MArti||[Link]()==MEksi)
[Link]([Link]());
else if([Link]()==Cos ||
[Link]()==Sin||[Link]()==Tan||[Link]()==RtoD ||
[Link]()==Asin||[Link]()==Atan||[Link]()==Exp ||
[Link]()==Log10||[Link]()==Isaret ||[Link]()==Kok ||
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]()==PI)
[Link]([Link]());
else
[Link]("");
[Link](new WindowAdapter() {
});
[Link]().add("Center", applet);
[Link]();
[Link]();
[Link](new Dimension(450,220));
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
Java network protokolü olarak TCP/IP protokolünü kullanýr. TCP ingilizce Transmission
interface protokol (Veritransferi arayüz protokolü) IP ise Internet protokolü anlamýna gelir.
0-10 : baºlýk
10-12 : kontrol
20-24 : seçenekler
24....gönderilen bilgi
IP bilgi paketlerinin yerine ulaºma garantisiyoktur. TCP protokolü gitme garantili paketler
oluºturur. IP paketini telgrafa benzetebiliriz. TCP paketleri ise telefon servisi gibidir. Karºýlýklý
iki tarafý baðlar. TCP paketinde alt birimler ºunlardýr :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
4-8 paket numarasý
12-20 baºlýklar
20+ veri
TCP kanallarýndan bazýlarý özel görevler görürler. Örneðin kanal 7 gönderilen bilgiyi geriye
yansýtýr. Kanal 13 verinin gittiði makinanýn yerel zamanýný bildirir. Kanal 20-21 ftp protokolü,
kanal 23 telnet protokolü, kanal 80 http protokolü tarafýndan kullanýlýr. Javada internet
adreslerini proses aden sýnýfýmýz InetAdress sýnýfýdýr.
package [Link];
InetAddress() ;
Inet adres sýnýfýný kullanarak DSN server sitelerinin adresine ulaºabiliriz. Bunu yapan bir
program kodu aºaðýda verilmiºtir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Program 16.1 [Link] programý
import [Link].*;
InetAddress someHost;
byte bytes[];
if ([Link] == 0) {
someHost = [Link]();
} else {
bytes = [Link]();
fourBytes[1] + "." +
fourBytes[2] + "." +
fourBytes[3]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
program çalýºtýrýlýnca :
sonucunu verecektir.
DatagramPacket sýnýfý dört kurucu metod içermektedir. Bu metodlardan ikisi veri almak, ikisi
de veri göndermek amaçlýdýr. Hem gönderirkenhemde veri alýrken byte olarak veriyi ve veri
uzunluðunu bildirme zorunluðu mevcuttur. Bu sýnýf asýl gönderme iºlemlerini yapmaz, bu
parelel sýnýfý DatagramSocket tarafýndan gerçekleºtirilir.
package [Link];
byte[] buf;
int offset;
int length;
InetAddress address;
int port;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public DatagramPacket(byte buf[], int offset, int length,
package [Link];
DatagramSocketImpl impl;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public DatagramSocket(int port) throws SocketException
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main (String args[]) throws Exception {
DatagramSocket dgSocket;
DatagramPacket datagram;
InetAddress destination;
PORT_DAYTIME);
[Link](datagram);
[Link](datagram);
[Link]();
program çýktýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
16.3 TCP BÝLGÝ ÝLETÝMÝ, SOCKET SINIFI
Direk olarak TCP üzerinden bilgi aktarma UDP üzerinden bilgi aktarýmý gibidir. En önemli
fark, TCP kullanýrken veri miktarýnýn önemli olmamasýdýr. Istenilen miktarda veri TCP lanalý
üzerinden aktarýlabilir. TCP veri aktarýmý için socket sýnýfýný kullanýyoruz. Socket sýnýfýnýn
tanýmý :
package [Link];
protected Socket()
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public int getSoLinger() throws SocketException
throws SocketException
throws SocketException
throws SocketException
throws IOException
ºeklindedir.
import [Link].*;
import [Link].*;
import [Link];
String s;
String msgFile;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
String from, to, mailHost;
if ([Link] != 4) {
[Link] (10);
msgFile = args[0];
from = args[1];
to = args[2];
mailHost = args[3];
checkEmailAddress (from);
checkEmailAddress (to);
if (mail != null) {
[Link](null,"Mektup gönderildi");
} else {
[Link](0);
if ([Link]('@') == -1) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](null,"Geçersiz e-mail adresi '" + address + "'");
[Link] (10);
//-------------------------------------------------------------------
class SMTP {
InetAddress mailHost;
InetAddress ourselves;
BufferedReader in;
PrintWriter out;
mailHost = [Link](host);
ourselves= [Link]();
public boolean send (FileReader msgg, String from, String to) throws IOException {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Socket smtpPipe;
InputStream inn;
OutputStream outt;
BufferedReader msg;
if (smtpPipe == null) {
return false;
inn = [Link]();
outt = [Link]();
if (inn==null || outt==null) {
return false;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link] (initialID);
[Link] (welcome);
[Link] (senderOK);
[Link] (recipientOK);
[Link] ("DATA");
[Link] ("DATA");
String line;
[Link](line);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link] (".");
[Link] (".");
[Link] (acceptedOK);
[Link] ("QUIT");
[Link] ("QUIT");
return true;
komutunu kullanabiliriz.
Program çýktýsý :
mailhost = [Link]/[Link]
localhost= turhan-czcvoqtf/[Link]
HELO turhan-czcvoqtf
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
250 OK
MAIL From:<turhan@[Link]>
RCPT TO:<[Link]@[Link]>
DATA
QUIT
ªeklinde oluºur.
Java'nýn Internet ortamýnda programlama için oldukça iyi bir araç olduðundan kitabýn baºýnda
bahsetmiºtik. Bu konuda javanýn çok iyi bir araç olmasý nazýlarýnýn Java dilini sadece bir
internet aracý olduðunu sanmalarýna kadar gitmektedir. Java dilinde internet ve serverlerin
haberleºmeleri için bir çok araç bulunmaktadýr. Bu araçlarýn en önemlilerinden biri de
ºüphesiz URL sýnýfý dýr. bu sýnýf yardýmýyla bir internet adresiyle (html adresiyle) rahatlýkla
baðlantý kurulabilir. url sýnýfýnýn genel tanýmý ºöyledir :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private String ref;
public URL(String protocol, String host, int port, String file) throws
MalformedURLException
public URL(String protocol, String host, int port, String file,URLStreamHandler handler)
throws MalformedURLException
protected void set(String protocol, String host, int port, String file, String ref)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public URLConnection openConnection() throws [Link]
ClassNotFoundException
Ýnternetten URL sýnýfýný kullanarak veri aktarýmý konusunda iki örnek program verelim. Birinci
program seçilen sitelere ulaºým yapacak bir internet sitesi seçme programýdýr.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
implements ItemListener
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public void init()
site=new Hashtable();
siteChoice=new Choice();
String baslik,yer;
URL url;
int counter=0;
try
yer="[Link]
url=new URL(yer);
[Link](baslik,url);
[Link](baslik);
baslik="Turhan Coban";
yer="[Link]
url=new URL(yer);
[Link](baslik,url);
[Link](baslik);
yer="[Link]
url=new URL(yer);
[Link](baslik,url);
[Link](baslik);
baslik="Java sitesi";
yer="[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
url=new URL(yer);
[Link](baslik,url);
[Link](baslik);
catch(MalformedURLException e){[Link]();}
[Link](this);
add(siteChoice);
URL url=(URL)[Link]([Link]());
getAppletContext().showDocument(url);
[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link];
getinternetsitesiFromHTMLParameters();
Container c = getContentPane();
[Link] );
[Link](
new ListSelectionListener() {
Object o = [Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
AppletContext browser = getAppletContext();
[Link]( newDocument );
);
[Link] );
URL url;
int counter = 0;
while ( true ) {
if ( baslik != null ) {
try {
[Link]( baslik );
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
catch ( MalformedURLException e ) {
[Link]();
else
break;
++counter;
bu programýn çýktýsý da bir önceki programda olduðu gibidir. Bir sonraki programda internet
üzerinden verilen adrese giderek dosyayý okumaktayýz. Yani bir anlamda küçük bir browser
programý yarattýk.
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
public InternetDosyaOku()
Container c = getContentPane();
[Link](
new ActionListener() {
getThePage( [Link]() );
);
[Link]( false );
[Link](
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
new HyperlinkListener() {
if ( [Link]() ==
[Link] )
getThePage( [Link]().toString() );
);
[Link] );
show();
setCursor( [Link](
Cursor.WAIT_CURSOR ) );
try {
[Link]( adres );
[Link]( adres );
catch ( IOException io ) {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]( this,
JOptionPane.ERROR_MESSAGE );
setCursor( [Link](
Cursor.DEFAULT_CURSOR ) );
[Link](
new WindowAdapter() {
[Link]( 0 );
);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªekil 16.4 internetdosyaoku programýný kullanarak seçilen internet sitesinin
gösterilmesi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
17. GÜVENLÝK
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
PrintWriter dos;
try {
[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("Yazým iºlemi baºarý ile gerçekleºti : " + myFile + " -- dosyasýný açýp
bakabilirsiniz ", 10, 10);
catch (SecurityException e) {
[Link]
Mesajý verilmiºtir. [Link] dosyasý incelendiðinde de hiç bir ºey yazýlmadýðý görülür. Bu
applet programýný kullanarak nasýl dosyaya yazý yazdýrabiliriz. Bunun için önce policytool
isimli programý çalýºtýralým. Ekrana
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
bir java programý gelecektir. Programdaki Add Policy Entry (güvenlik kuralý ekle) düðmesine
basalým. Yeni bir ekran açýlacaktýr. Bu ekranda güvenlik programýmýzý içerecek dosya url
adresini yazýp (örneðin file:/c:/co/java/prog veya html://[Link]/~turhan) Add
Permission tuºuna basalým.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
File permission (dosya güvenlik izni) penceresinden file permission (dosya izni) seçtikten
sonra Target Name alanýna yazma izni istediðimiz [Link] dosyasýnýn ismini yazalým. Ve
son alanda da yazma izni (“write”) seçelim ve ok düðmesine basalým.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
son pencere kapanacak ve bir önceki pencere gelecektir. Burada da Done düðmesine
basalým.
ilk pencerede file, save as seçeneklerini seçtikten sonra c:\co\java\prog (veya sizin
çalýºtýðýnýz dosyaya) [Link] adýyla kaydedelim. Program policy succesfully written to
c:\co\java\prog\[Link] mesajýný verecektir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ºimdi policy tool programýný exit deyimiyle kapatabiliriz. Policytool programý bize otomatik
olarak [Link] dosyasýný yarattý. Bu dosyanýn kapsamýna bakacak olursak :
/* DO NOT EDIT */
};
komutuyla çalýºtýrdýðýmýzda :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
çýktýsýný alacaðýz. Yazý[Link] dosyasýný açtýðýmýzda
------------
# the Java Security API. A provider may, for example, implement one or
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
#
# [Link].<n>=<className>
# by 2, and so on.
# [Link].1=[Link]
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
# registered instead by calls to either the addProvider or
[Link].1=[Link]
[Link].2=[Link]
# Class to instantiate as the system Policy. This is the name of the class
[Link]=[Link]
[Link].1=file:${[Link]}/lib/security/[Link]
[Link].2=file:${[Link]}/.[Link]
# files.
[Link]=true
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
# with -[Link]=somefile. Comment out this line to disable
# this feature.
[Link]=true
[Link]=false
[Link]=jks
[Link]=[Link]
# been granted.
[Link]=sun.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
#
# been granted.
#[Link]=
[Link].1=file${[Link]}/lib/security/[Link]
[Link].2=file${[Link]}/.[Link]
[Link].3=file:/C:/co/java/prog/[Link]
------------
[Link].3=file:/C:/co/java/prog/[Link]
komutunu kullanarak ekledik. 3 rakamýnýn anlamý daha önce yazýlan iki güvenlik kodunun
olmasýdýr. ªimdi sadece appletviewer [Link] komutu kulanarak programýmýzý
çalýºtýrýp yazma iºlemini baºarabiliriz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
17.2 KONSOL PROGRAMLARINDA GÜVENLÝK
Applet dýºý programlarda (konsol programlarýnda) java direk olarak güvenlik kontrolu istemez.
Yukardaki programýn bir Jframe eºdeðerini oluºturalým
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
PrintWriter dos;
public yazitestiSWF()
Graphics2D g2 = (Graphics2D)g;
try {
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]();
[Link]("Yazým iºlemi baºarý ile gerçekleºti : " + myFile + " -- dosyasýný açýp
bakabilirsiniz ", 10, 50);
catch (SecurityException e) {
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
programýn direk olarak hiçbir güvenlik iºlemine gereksinim duymadan çalýºtýðýný görürüz.
Eðer bu güvenlik kontrolunu özel olarak arzularsak, programýmýzý
Örneðin [Link] dosyasýnýn [Link] dosyasý içinde yazma izni almýº hali:
/* DO NOT EDIT */
};
ºeklinde olacaktýr.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ªimdi size sistem özelliklerini veren bir program verelim.
import [Link].*;
import [Link].*;
import [Link];
class ozellikler {
String s,s1;
try {
[Link](null,s1);
[Link](0);
bu programý çalýºtýrdýðýmýzda :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
çýktýsýný verecektir. ªimdi programý güvenli modda çalýºtýralým, çýktý :
olacaktýr. Burada temel olarak sistem özelliklerini okuma izni vermemiz gerekiyordu. Bu
yüzden [Link] (java özellikleri izni) read (oku) komutuyla verildi
/* DO NOT EDIT */
};
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
17.3 GÜVENLÝK SERTÝFÝKALARI
Bilgisayarlardaki genel güvenlik sistemi genelde iki anahtarlý bir sistemdir. Bu anahtarlardan
birincisi, özel anahtar, sadece sizin bildiðiniz bir anahtardýr. Ikinci anahtar güvenli olarak
iletiºim kurmak istediðiniz her yere gönderilebilir. Sertifika almanýn ilk aºamasýný javada
verilen keytool adlý programý kullanarak yapabiliriz. Bunun için
keytool –genkey
What is the name of your City or Locality? (ºehrinizin veya bulunduðunuz yerin adý nedir?)
[unknown]: Gebze
What is the name of your State or Province? (eyaletinizin veya bölgenizin adý nedir?)
[unknown]: Kocaeli
What is the two-letter country code for this unit? (iki harfli ülke kodunuz nedir?)
[unknown]: TR
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Enter key password for <mykey>
(mykey anahtarý için ºifreyi giriniz daha önce girdiðiniz ºifreyle aynýysa sadece gir tuºuna
basýnýz)
sorusunu soracak ve ºifre isteyecektir. Burada sizin ºifreniz mykey ismini almýºtýr.
MIICcjCCAi8CAQAwbDELMAkGA1UEBhMCVFIxEDAOBgNVBAgTB0tvY2FlbGkxDjAMBgN
VBAcTBUdl
YnplMRQwEgYDVQQKEwtNUkNfVFVCSVRBSzEOMAwGA1UECxMFRVNFUkkxFTATBgN
VBAMTDFR1cmhh
biBDb2JhbjCCAbgwggEsBgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3
UjzvRADD
Hj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7q
df+
t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI
8VIwvM
spK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrUW
U/m
cQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEkO8
yk
8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQBTDv+z0kqA4GFAAKBgQCGLh1t/Vo3fMkMFLXNu9d
hueKG
dac3vGCUmd1FzqBALncr+YEQw2DZqtxiwqIeivbXOoean2516S0cDBi333ArOGtK0pm/pHQ
3Yyeh
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
W/ePbV6ljh/KbmuHaa3ZSfAHKseuHBcMkS4SNC5DeTVifzT1QLRwGeAkP5xdL72EX/dt8KA
AMAsG
ByqGSM44BAMFAAMwADAtAhUAlm7LpK8FaOco1hgARAkCX0ik9CECFDqrUbnw9Fyp5CR
UYs0+RCFy
L+U9
gibi bir çýktý oluºturacaktýr. Bu çýktý anahtar sertifika otoritelerine direk olarak email ile
gönderilebilir. Sertifikanýn gayesi sizi tanýmýyan kiºilerce bile programlarýnýzýn güvenliðinin
onaylanmasýdýr. Genellikle sertifika kuruluºlarý bunu bir ücret karºýlýðý yapar. Örneðin
[Link] asdresinde böyle bir kuruluºla ilgili detaylý bilgi bulabilirsiniz. Sertifika
kuruluºundan onaylanmýº olarak gelen sertifikanýzý
Jar dosyalarýnýn hazýrlanmasýndan daha önce bahsetmiºtik. Java jar dosyalarý jarsigner
komutu kullanýlarak sertifikalandýrýlabilir. Komut
jarsigner [Link] mykey ºeklindedir. Buradaki mykey sizin anahtarýnýzýn adý, [Link] ise
kullandýðýmýz jar dosyasýdýr. Dosyayý kullanmadan önce –verify ve –verbose terimleriyle
açmamýz gerekir.
Browserlerin güvenlik sistemi burada anlattýklarýmýzla benzer olmakla beraber aynýsý deðildir.
Microsoft ve netscape birbirinden ayrý güvenlik sistemlerine sahiptirler. Bunlarla ilgili bilgi
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Microsoft için : [Link]
adreslerinden edinilebilir.
EK A TEXT SINIFI
[Link]
//============================================
// Numerical Analysis Package in Java
// Class Text to read data from screen or file
// Dr. Turhan Coban
//============================================
import [Link].*;
import [Link].*;
class Text
{
BufferedReader in;
/*
---------------------------------------------------
Static routines provided are:
---------------------------------------------------
public static void prompt(String s);
public static int readInt(DataInputStream in);
public static int readInt(BufferedReader in);
public static double readDouble(DataInputStream in);
public static double readDouble(BufferedReader in);
public static String readString(DataInputStream in);
public static String readString(BufferedReader in);
public static char readChar(DataInputStream in);
public static char readChar(BufferedReader in);
----------------------------------------------------
Dynamic routines provided are :
----------------------------------------------------
public void Text()
public void Text(String s1)
public void Text(File f1)
public int readInt();
public double readDouble();
public String readString();
public char readChar();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Sample use :
--------- reading a double--------------
DataInputStream cin=new DataInputStream([Link]);
double number;
number=[Link](cin);
veya
BufferedReader cin=new BufferedReader(new InputStreamReader([Link]));
double number;
number=[Link](cin);
veya
double number;
Text cin=new Text();
number=[Link]();
------ reading data from a file "[Link]"------
DataInputStream fin=new DataInputStream
(new FileInputStream("[Link]"));
double number;
number=[Link](fin);
veya
double number;
BufferedReader fin=new BufferedReader(new FileReader("[Link]"));
double number;
number=[Link](fin);
veya
double number;
Text cin=new Text("[Link]");
number=[Link]();
------ printing data into a file "[Link]"----
PrintStream fout=new PrintStream
(new FileOutputStream("[Link]"));
String a="turhan";
[Link](a);
veya
BufferedWriter fout=new BufferedWriter(new FileWriter("[Link]"));
String a="Turhan");
[Link](a);
----------------------------------------------------
*/
public Text()
{
in=new BufferedReader(new InputStreamReader([Link]));
}
public Text(String s1) throws IOException
{
in=new BufferedReader(new FileReader(s1));
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](s + " ");
[Link]();
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static int readInt (BufferedReader in) throws IOException
{
if (T==null) refresh(in);
while (true)
{
try {
String item = [Link]();
return [Link]([Link]()).intValue();
}
catch (NoSuchElementException e1) { refresh (in);
} catch(NumberFormatException e2)
{ //[Link]("Error in number, try again.");
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
refresh (in);
} catch(NumberFormatException e2)
{
//[Link]("Error in number, try again.");
}
}
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static String readStringLine(DataInputStream in) throws IOException
{
//reads a line of strings from DataInputStream in
int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = [Link]();
if (ch < 0 || (char)ch == '\n' || (char)ch == '\0')
done = true;
else
r = r + (char) ch;
}
catch([Link] e)
{ done = true;
}
}
return [Link](0,([Link]()-1));
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
private static void refresh (BufferedReader in) throws IOException
{
String s = [Link]();
if (s==null) throw new EOFException();
T = new StringTokenizer(s);
}
}
Ýsim – soyisim
Öðrenci numarasý
Master/doktora
Email
Telefon
Not
AÇIKLAMALAR
SORU 1
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
ºeklindedir. Program çýktýsýný yazýnýz.
import [Link].*;
import Text;
import [Link];
class SORU1_2000{
double sayi1,sayi2;
double toplam;
sayi1=[Link]();
sayi2=[Link]();
toplam=sayi1+sayi2;
[Link](0);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 2
Aºaðýda verilen kutuya girdi olarak 2 girildiðinde oluºacak program çýktýsýný yazýnýz
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](s1);
[Link](t1);
[Link](s2);
[Link](ciktiAlani);
[Link](this);
SS
SORU 3
metodunu yazýnýz. Bu metod kendi kendini çaðýran bir program kodu veya bir döngü yapýsý
kullanan bir ºekilde oluºturulabilir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Import [Link];
double taban,kuvvet;
taban=[Link]([Link]
kuvvet=[Link]([Link]
+pow(taban,kuvvet),"H3OD3_2000.java
programý",JOptionPane.PLAIN_MESSAGE);
[Link](0);
Cevap :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 4
Aºaðýda verilen kompleks2 programýnýn içerisinde yer almasý gereken ve bir kompleks
sayýnýn karesini hesaplayan kare metodunu yazýnýz. kompleks2 sýnýfýný kullanarak (1+2i)
kompleks sayýsýnýn karesini alan ve sonuçlarýný konsol ortamýnda yazdýran bir küçük bir çýktý
programý yazýnýz
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class kompleks2
ger=nger;
imaj=nimaj;
double Rad,th;
Rad=[Link](sol.R(),sag);
th=sag*[Link]();
kompleks2 sonuc;
(Rad*[Link](th) ) );
return sonuc;
Kare metodu :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 5
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{ {
{ length=[Link];
for(int i=0;i<length;i++) {
a[i]=x[i]; a[i]=x[i];
} }
public doubleBoyut(int n) }
a=new double[n]; {
} }
{ {
{ for(int i=0;i<length;i++)
int z=[Link]+n; {
********************************* s+="\n";
a=b; return s;
length=[Link]; }
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
} }
{ int z=[Link]-n;
boyutEkle(1); if(z>1)
} {
{ for(int i=0;i<z;i++)
boyutAzalt(1); b[i]=a[i];
} a=b;
{ else
return a[i]; {
{ a=b;
return a; }
} length=[Link];
if(n>0)
int z=[Link]+n;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
a=b;
length=[Link];}}
SORU 6
OvalPanelSWP panel programý verilmiºtir. Biz bu programý kullanarak bir elips çizdirmek
istiyoruz. Bunun için yazýlan JFrame programý SORU6_2000 nýn kurucu metodu
SORU6_2000 metodunu tamamlayýnýz.
import [Link].*;
import [Link].*;
import yildizSW;
import [Link].*;
import renk;
int xi,yi,yaricap;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
xi=xi1;
yi=yi1;
xi=xi1;
yi=yi1;
repaint();
[Link](g);
[Link]([Link]);
Graphics2D g2=(Graphics2D)g;
[Link](RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Link](elips1);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
================================================================
import BasicWindowMonitor;
import ovalPanelSWP;
import [Link].*;
private ovalPanelSWP p;
Color r=[Link];
Container c;
public SORU6_2000()
super("JSlider Testi");
c=getContentPane();
[Link](new Flowlayout());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
****** tamamlayýnýz ********
*************************
//============================
[Link](new BasicWindowMonitor());
[Link](350,200);
[Link](true);
}}
public ovalTestSWF_2000()
super("JSlider Testi");
c=getContentPane();
[Link]();new Flowlayout());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 7
import [Link].*;
import [Link].*;
import Text;
String driverName;
Connection con;
String createString;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
"TOPLAM int)";
Statement stmt;
try {
[Link]("[Link]");
} catch([Link] e)
[Link]("ClassNotFoundException: ");
[Link]([Link]());
try {
stmt =
[Link]();
[Link](createString);
[Link]();
[Link]();
} catch(SQLException ex)
Program çýktýsý :
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 8
[Link] dosyasý incelendiðinde
12
23
34
45
56
import [Link].*;
import Text;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
double x[],y[];
DataInputStream input;
x= new double[200];
y=new double[200];
String s1="[Link]";
boolean EOF=false;
int j=0;
while (!EOF)
try
x[j]= [Link](b);
y[j]= [Link](b);
++j;
catch (EOFException e)
[Link]();
EOF=true;
} //while
String s2="[Link]";
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
PrintWriter cfout=new PrintWriter(new BufferedWriter(new FileWriter(fcik)));
for(int i=0;i<j;i++)
{[Link](""+x[i]+" "+(y[i]*y[i]));}
[Link]();
} //main
} //class
SORU 9
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
class SetA
String s1,s2;
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
s1=(String)[Link]();
[Link](s1);
while([Link]())
s2=(String)[Link]();
if()
[Link](s2);
return bilesimVectoru;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
JTextField T1,T2;
JTextArea cikti;
Vector ansUn;
Container c;
public SetTestSWF_2000()
c=getContentPane();
[Link](new FlowLayout());
T1 = new JTextField(30);
[Link](false);
[Link]("");
[Link]([Link]());
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link](P1);
[Link](T1);
[Link](this);
[Link](P2);
[Link](T2);
[Link](this);
[Link](new Dimension(320,200));
[Link](jp);
while([Link]()) {
[Link](test);
while([Link]())
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
[Link]("\n");
if([Link]()==T1)
girdiA(stringToTokenize,list1);
else if([Link]()==T2)
girdiA(stringToTokenize,list2);
ansUn = [Link](list1,list2);
[Link]("");
ciktiA(ansUn);
[Link](new BasicWindowMonitor());
[Link](400,350);
[Link](true);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 10
Birden yüze kadar sayýlarýn ortalamasýný bulan bir java bilgisayar programý yazýnýz.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
JAVA PROGRAMLAMA DÝLÝ GEBZE YÜKSEK TEKNOLOJÝ ENSTÝTÜSÜ
isim soyisim
ogrenci numarasý
email /telefon
not
AÇIKLAMALAR :
· Ýyi ºanslar
SORU 1
import [Link].*;
int sayi1=1;
int sayi2=2;
sayi1 += sayi2;
sayi1 -= sayi2;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
sayi1 *= sayi2;
sayi1 /= sayi2;
SORU 2
import [Link];
import [Link].*;
double not=60;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{ [Link]("A",25,35); }
{ [Link]("B",25,35); }
{ [Link]("C",25,35); }
{ [Link]("D",25,35); }
{ [Link]("E",25,35); }
else
{ [Link]("F",25,35); }
SORU 3
import [Link];
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public class soru3 extends Applet
for(int x=10;x<100;x+=20)
[Link](" "+x,x,25);
SORU 4
import [Link];
import [Link];
int x,y;
y=1;
while(y++<5)
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
{
x=1;
while(x++<6)
[Link] ("*",15*x,15*y);
SORU 5
aºaðýdaki program kodunda ******* ile verilen yerde kare metodunu kullanarak sonucu
yazdýracak [Link](...) komutunu yeniden yazýnýz
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static double kare(double x)
return x*x;
double sayi=2;
SORU6
soru6 metodunda, apletdeki sonucu alabilmek için gerekli olan kare metodunu yazýnýz.
class soru6
**************
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 7
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Verilen programýn çýktýsýný yazýnýz.
import [Link].*;
class soru7
return b1&&b2;
return b1||b2;
boolean b1=true;
boolean b2=false;
[Link](""+[Link](b1,b2));
[Link](""+[Link](b1,b2));
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 8
public double x, y;
public noktaX()
x=0;
y=0;
*************
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public noktaX(noktaX a)
x=a.x;
y=a.y;
return "["+x+","+y+"]";
SORU 9
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
import noktaX;
n1=new nokta(x1,y1);
n2=new nokta(x2,y2);
*****************
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 10
import [Link].*;
class boyut1
int ayin_gunleri[]={31,28,31,30,31,30,31,31,30,31,30,31};
SORU 10
drawLine metodu kullanarak aºaðýdaki çýktýyý alacak bir program yazýnýz. çizgi
koordinatlarýnýn ne olduðu önemli deðildir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 11
drawRect metodu kullanarak aºaðýdaki çýktýyý alacak bir program yazýnýz. dikdortgen
koordinatlarýnýn ne olduðu önemli deðildir.
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 12
import [Link];
import [Link].*;
L1=new Label();
[Link]("etiket 1");
add(L1);
add(L2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
[Link]("L1 : "+[Link](),25,80);
[Link]("L2 : "+[Link](),25,95);
SORU 13
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 14
import [Link];
import [Link].*;
setBackground([Link]);
T1=new TextArea(s,5,40);
add(T1);
SORU 15
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
Birden 10 a kadar sayýlarýn ortalamasýný hesaplayan bir application (konsol) programý
yazýnýz.
SORU 16
extends ArithmeticException
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public sifiraBolunmeException()
import [Link].*;
import sifiraBolunmeException;
int sayi1=0;
int sayi2=1;
try
[Link](bol(sayi2,sayi1));
catch(sifiraBolunmeException e) {[Link]([Link]());}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
SORU 17
import [Link].*;
class YazOku
[Link]("Merhaba");
[Link]("isminiz nedir");
[Link]();
s1=[Link]();
s2=[Link]();
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
s3=[Link]();
[Link]();
[Link]("s1 = "+s1);
[Link]("s2 = "+s2);
[Link]("s3 = "+s3);
a)
b)
SORU 18
import [Link].*;
import [Link].*;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public static void main(String arg[])
[Link]("cumle : "+s);
int i=0;
while([Link]())
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
SORU 19
import [Link].*;
import [Link].*;
import [Link];
import [Link].*;
class kume
String s1,s2;
Enumeration n1=[Link]();
Enumeration n2=[Link]();
while([Link]())
s1=(String)[Link]();
[Link](s1);
while([Link]())
s2=(String)[Link]();
if()
[Link](s2);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
}
return bilesimVectoru;
SORU 20
soldal_node_sagdal_sirala();
package bolum11;
class TreeNode
TreeNode sol;
int data;
TreeNode sag;
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public TreeNode(int d)
data=d;
sol=sag=null;
if(d<data)
else {[Link](d);}
else if(d>data)
else {[Link](d);}
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF
public synchronized void gir(int d)
else [Link](d);
if(node==null) return;
soldal_node_sagdal_siralayici([Link]);
[Link]([Link]+" ");
soldal_node_sagdal_siralayici([Link]);
Trial This PDF was created using the Free RoboPDF Trial (for evaluation purposes only!)
Version Get RoboPDF: An Easy, Affordable Alternative for Creating PDFs - [Link] Buy RoboPDF