Apllet İle Çizim
ÖRNEK 1
// Üçgen çizdirme programı
import java.awt.*;
import java.applet.Applet;
public class ucgenCiz extends Applet {
public void paint(Graphics g) {
int tabanX = 80;
int tabanY = 200;
int taban = 100;
int height = 110;
int i = 80, j = 200;
int a = 80, b = 200;
int c = 150, d = 200;
int e = 115, f = 260;
g.drawLine(tabanX, tabanY, tabanX + taban, tabanY);
g.drawLine(tabanX + taban, tabanY, tabanX + taban / 2, tabanY - height);
g.drawLine(tabanX + taban / 2, tabanY - height, tabanX, tabanY);
g.setColor(Color.yellow);
g.fillRect(i, j, 100, 100);
g.setColor(Color.black);
g.drawRect(i - 1, j - 1, 100, 100);
g.setColor(Color.blue);
g.fillRect(a, b, 30, 30);
g.setColor(Color.black);
g.drawRect(a - 1, b - 1, 30, 30);
g.setColor(Color.blue);
g.fillRect(c, d, 30, 30);
g.setColor(Color.black);
g.drawRect(c - 1, d - 1, 30, 30);
g.setColor(Color.RED);
g.fillRect(e, f, 30, 40);
g.setColor(Color.black);
g.drawRect(e - 1, f - 1, 30, 40);
}
}
import java.awt.*;
import java.applet.Applet;
public class ucgenCiz extends Applet {
public void paint(Graphics g) {
int tabanX = 80;
int tabanY = 200;
int taban = 100;
int height = 110;
int i = 80, j = 200;
int a = 80, b = 200;
int c = 150, d = 200;
int e = 115, f = 260;
g.drawLine(tabanX, tabanY, tabanX + taban, tabanY);
g.drawLine(tabanX + taban, tabanY, tabanX + taban / 2, tabanY - height);
g.drawLine(tabanX + taban / 2, tabanY - height, tabanX, tabanY);
g.setColor(Color.yellow);
g.fillRect(i, j, 100, 100);
g.setColor(Color.black);
g.drawRect(i - 1, j - 1, 100, 100);
g.setColor(Color.blue);
g.fillRect(a, b, 30, 30);
g.setColor(Color.black);
g.drawRect(a - 1, b - 1, 30, 30);
g.setColor(Color.blue);
g.fillRect(c, d, 30, 30);
g.setColor(Color.black);
g.drawRect(c - 1, d - 1, 30, 30);
g.setColor(Color.RED);
g.fillRect(e, f, 30, 40);
g.setColor(Color.black);
g.drawRect(e - 1, f - 1, 30, 40);
}
}
Kodun Çıktısı;
ÖRNEK 2
// Bu program gelisiguzel kutuları applet icine yerlestirir...
import java.awt.*;
import java.applet.*;
public class birsurukutu extends Applet {
public void paint(Graphics temp) {
int kirmiziorani, yesilorani, maviorani;
int i, j;
i = 5;
j = 10;
while (j < 130) {
while (i < 450) {
kirmiziorani = (int) Math.floor(Math.random() * 256);
yesilorani = (int) Math.floor(Math.random() * 256);
maviorani = (int) Math.floor(Math.random() * 256);
temp.setColor(new Color(kirmiziorani, yesilorani, maviorani));
temp.fillRect(i, j, 25, 25);
temp.setColor(Color.black);
temp.drawRect(i - 1, j - 1, 25, 25);
i = i + 30;
}//i<450 dongusunun sonu
i = 5;
j = j + 30;
}//j<130 dongusunun sonu
}//paint(Graphics temp) sonu
}//birsurukutu appletinin sonu
import java.awt.*;
import java.applet.*;
public class birsurukutu extends Applet {
public void paint(Graphics temp) {
int kirmiziorani, yesilorani, maviorani;
int i, j;
i = 5;
j = 10;
while (j < 130) {
while (i < 450) {
kirmiziorani = (int) Math.floor(Math.random() * 256);
yesilorani = (int) Math.floor(Math.random() * 256);
maviorani = (int) Math.floor(Math.random() * 256);
temp.setColor(new Color(kirmiziorani, yesilorani, maviorani));
temp.fillRect(i, j, 25, 25);
temp.setColor(Color.black);
temp.drawRect(i - 1, j - 1, 25, 25);
i = i + 30;
}//i<450 dongusunun sonu
i = 5;
j = j + 30;
}//j<130 dongusunun sonu
}//paint(Graphics temp) sonu
}//birsurukutu appletinin sonu
Kodun Çıktısı;
ÖRNEK 3
// Üçgen çizdirme metodu
import java.awt.*;
import java.applet.Applet;
public class x extends Applet {
public void paint(Graphics g) {
drawTriangle(g, 20, 180, 100, 110);
drawTriangle(g, 125, 180, 60, 70);
}
private void drawTriangle(Graphics g, int tabanX, int tabanY,
int taban, int yukseklik) {
int sagX = tabanX + taban;
int ustX = tabanX + taban / 2;
int ustY = tabanY - yukseklik;
g.drawLine(tabanX, tabanY, sagX, tabanY);
g.drawLine(sagX, tabanY, ustX, ustY);
g.drawLine(ustX, ustY, tabanX, tabanY);
}
}
import java.awt.*;
import java.applet.Applet;
public class x extends Applet {
public void paint(Graphics g) {
drawTriangle(g, 20, 180, 100, 110);
drawTriangle(g, 125, 180, 60, 70);
}
private void drawTriangle(Graphics g, int tabanX, int tabanY,
int taban, int yukseklik) {
int sagX = tabanX + taban;
int ustX = tabanX + taban / 2;
int ustY = tabanY - yukseklik;
g.drawLine(tabanX, tabanY, sagX, tabanY);
g.drawLine(sagX, tabanY, ustX, ustY);
g.drawLine(ustX, ustY, tabanX, tabanY);
}
}
Kodun Çıktısı;
Not :Aşağıdaki linke tıklayarak önceki örneklerimize de göz atabilirisiniz.
www.dijitalders.com/icerik-58-3831-japplet-setcolor-ve-setfont-kullanimi.html
Ömer Faruk KARAMAN
Yorumunuzu Ekleyin