Ja e tere klasa.
Nuk po di cka te bej me mbetjen.
Veshtire te ndahet pa perdorur float. Por si te vizatoj float kur penda vizaton ne pixela te plote. Kam pare se ka dicka nga Graphics2D paketat mirepo nuk du ti perdor ato!
Kodi PHP:
/*
* @(#)Pie.java 1.0 23/08/06
* Pie vizaton një "tortë" të cilën e preni ju duke caktuar numrin e copëve
* Autor: Isa Bllaca, gjimnazi "Zenel-Hajdini", Gjilan.
*/
import java.awt.*;
import java.awt.event.*;
public class Pie extends Frame implements ActionListener{
public int ndarja; // numri i ndarjeve
private int ngjyre_ndrruesi; // selektuesi i ngjyrave ne vargun ngjyrat
private int ndrruesi; // ndrruesi i vleres se ngjyre_ndrruesi
private TextField txt; // per vleren e ndarjes.
private Button butoni; // butoni
public Color[] ngjyrat = {Color.blue, Color.green, Color.pink, Color.cyan,
Color.red, Color.yellow, Color.magenta, Color.lightGray}; // 8 ngjyrat me te cilat do te ngjyrosen pjeset e Pie-s
private int x1; // x1 e Pie
private int y1; // y1 e Pie
private int x2; // x2 e Pie
private int y2; // y2 e Pie
/** konstruktori */
public Pie() {
ndarja = 1; // inicimi i variablave...
ngjyre_ndrruesi = 0;
ndrruesi = 1;
x1 = 100;
y1 = 100;
x2 = 450;
y2 = 450;
txt = new TextField();
this.setLayout(new FlowLayout());
butoni = new Button("Vizato");
this.add(txt);
this.add(butoni);
butoni.addActionListener(this);
addWindowListener(new WindowAdapter() { // per nje mbyllje te rregullt te dritares
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
/** @paint per te vizatuar */
public void paint(Graphics g)
{
for (int i = 0; i < ndarja; i++)
{ int mbetja = 360 % ndarja; // mbetja
int shkallet = (360 - mbetja) / ndarja; // vlera e shkalleve
int kendi_fillues_i_ardhshem = i * shkallet; // pika ne te cilen do te filloj pjesa e ardhshme
ngjyre_ndrruesi = ngjyre_ndrruesi + ndrruesi; // percaktuesi i ngjyres ne varg
if (ngjyre_ndrruesi >= 7 || ngjyre_ndrruesi <= 0) // nese percaktuesi i ngj. del jashte numrit te elementeve te vargut
{ ndrruesi = -ndrruesi; } // ndrro drejtimin
g.setColor(ngjyrat[ngjyre_ndrruesi]); // ngjyra e percaktuar ne varg
g.fillArc(x1, y1, x2, y2, kendi_fillues_i_ardhshem, shkallet); // vizatimi i harkut
}
}
/** actionPerformed ne rast te klikimit te butonit */
public void actionPerformed(ActionEvent evt)
{ String ndarjett = txt.getText();
ndarja = new Integer(ndarjett).intValue();
this.repaint();
}
/** main per testim */
public static void main(String args[]) {
System.out.println("Ne startim e siper Pie...");
Pie dritarja = new Pie();
dritarja.setSize(700, 700);
dritarja.setTitle("Pie");
dritarja.setVisible(true);
}
}
Krijoni Kontakt