import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;
public class SekilPanel extends JPanel {
public static final int Dogru = 1;
public static final int Dikdortgen = 2;
public static final int Oval_Dikdortgen = 3;
public static final int Oval = 4;
public static final int Kare = 5;
private int tip = 1;
private boolean doldur;
public boolean isDoldur() {
return doldur;
}
public void setDoldur(boolean doldur) {
this.doldur = doldur;
repaint();
}
public int getTip() {
return tip;
}
public void setTip(int tip) {
this.tip = tip;
}
public Dimension getPreferredSize() {
return new Dimension(80, 80);
}
public SekilPanel() {
}
public SekilPanel(int tip) {
this.tip = tip;
}
public SekilPanel(int tip, boolean doldur) {
this.tip = tip;
this.doldur = doldur;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
int width = getSize().width;
int height = getSize().height;
switch (tip) {
case Dogru:
g.setColor(Color.ORANGE);
g.drawLine(10, 20, width – 10, height – 20);
g.drawLine(width – 10, 20, 10, height – 20);
break;
case Dikdortgen:
g.setColor(Color.BLACK);
if (doldur) {
g.fillRect((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height));
} else
g.drawRect((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height));
break;
case Oval_Dikdortgen:
g.setColor(Color.RED);
if (doldur) {
g.fillRoundRect((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height), 20, 20);
} else
g.drawRoundRect((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height), 20, 20);
break;
case Oval:
g.setColor(Color.BLUE);
if (doldur) {
g.fillOval((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height));
} else
g.drawOval((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * height));
break;
case Kare:
g.setColor(Color.MAGENTA);
if (doldur) {
g.fillRect((int) (0.8 * width), (int) (0.8 * height),
(int) (width), (int) (width));
} else
g.drawRect((int) (0.1 * width), (int) (0.1 * height),
(int) (0.8 * width), (int) (0.8 * width));
break;
}
}
}
import java.awt.GridLayout;
import javax.swing.JFrame;
public class Sekil extends JFrame {
public Sekil() {
setLayout(new GridLayout(3, 1));
setSize(400, 400);
setTitle("E-Hero Şekil Çizdirme");
add(new SekilPanel(SekilPanel.Dogru));
add(new SekilPanel(SekilPanel.Dikdortgen));
add(new SekilPanel(SekilPanel.Oval_Dikdortgen));
add(new SekilPanel(SekilPanel.Oval));
add(new SekilPanel(SekilPanel.Kare));
add(new SekilPanel(SekilPanel.Dikdortgen), true);
add(new SekilPanel(SekilPanel.Oval_Dikdortgen), true);
}
public static void main(String[] args) {
Sekil f = new Sekil();
f.setVisible(true);
}
}
serhat
03/04/2013 — 01:15
bir JTextField içine kirmizi,kesikcizgili,kare yazıp bunu seçerek labelin içine bıraktığımızda label da kırmızı kesik çizgili bir kare nasıl çizdirebiliriz bu konuda sizden yardım alabilirmiyim?
gerekli olanlar:sekil class ı
kare class ı
daire class ı
üçgen class ı ve bu kare daire ve üçgen class larının şekil class ından extends olmaları.