Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 2 odgovora
  • 2.428 pregleda

Najnovija ↓

Java beans na koji nacin 07.02.2009. u 14:49 · pre 215 meseci #1
Molim vas a mi neko kaze na koji nacin da sljedeci kod implementiam pomocu java beansa

Code:
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class radar extends javax.swing.JFrame {
private static int step = 50, count = 0;
public int precnik, plot, t1xsm = 1, t1ysm = 1, t2xsm = -1, t2ysm = 1, t3xsm = -1, t3ysm = -1;
public float fade = 1.0f, crt1 = 0.5f, crt2 = 0.5f, crt3 = 0.5f;
public double tx, ty, tugao, tug, ugao = 0, ut1, ut2, ut3;
Insets pomak;
Color xcolor, zcolor;
Point lt = new Point(0, 0);
Point t1 = new Point(50, 100);
Point t2 = new Point(400, 80);
Point t3 = new Point(500, 500);
Point rt1 = new Point(0, 0);
Point rt2 = new Point(0, 0);
Point rt3 = new Point(0, 0);
Point min = new Point(0, 0);
Point max = new Point(400, 400);
Point kcentar = new Point(0, 0);
Point centar = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
public radar() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setBounds(centar.x - 300, centar.y - 300, 600, 600);
this.setTitle("AWT demo: Radar");
TimerTask scan = new TimerTask() {
public void run() {
ugao = ugao + 1;
if (ugao == 360) { ugao = 0; }
count++;
if (count == 80) {
t1.x = t1.x + 4 * t1xsm;
t1.y = t1.y + 8 * t1ysm;
t2.x = t2.x + 6 * t2xsm;
t2.y = t2.y + 2 * t2ysm;
t3.x = t3.x + 3 * t3xsm;
t3.y = t3.y + 5 * t3ysm;
count = 0;
}
if (t1.x < min.x) {
t1.x = min.x + (min.x - t1.x);
t1xsm = 1;
}
if (t1.x > max.x) {
t1.x = max.x - (t1.x - max.x);
t1xsm = -1;
}
if (t1.y < min.y) {
t1.y = min.y + (min.y - t1.y);
t1ysm = 1;
}
if (t1.y > max.y) {
t1.y = max.y - (t1.y - max.y);
t1ysm = -1;
}
if (t2.x < min.x) {
t2.x = min.x + (min.x - t2.x);
t2xsm = 1;
}
if (t2.x > max.x) {
t2.x = max.x - (t2.x - max.x);
t2xsm = -1;
}
if (t2.y < min.y) {
t2.y = min.y + (min.y - t2.y);
t2ysm = 1;
}
if (t2.y > max.y) {
t2.y = max.y - (t2.y - max.y);
t2ysm = -1;
}
if (t3.x < min.x) {
t3.x = min.x + (min.x - t3.x);
t3xsm = 1;
}
if (t3.x > max.x) {
t3.x = max.x - (t3.x - max.x);
t3xsm = -1;
}
if (t3.y < min.y) {
t3.y = min.y + (min.y - t3.y);
t3ysm = 1;
}
if (t3.y > max.y) {
t3.y = max.y - (t3.y - max.y);
t3ysm = -1;
}
repaint();
}
};
Timer Xtimer = new Timer();
Xtimer.schedule(scan, 0, step);
}
public void paint(Graphics g) {
if (pomak == null) { pomak = getInsets(); }
precnik = getHeight() - pomak.top - pomak.bottom - 30;
kcentar.x = getWidth()/2;
kcentar.y = (getHeight() + pomak.top)/2;
min.x = kcentar.x - precnik/2 - 10;
min.y = kcentar.y - precnik/2 - 10;
max.x = kcentar.x + precnik/2 + 10;
max.y = kcentar.y + precnik/2 + 10;
g.setColor (Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
tug = (360 - ugao) / 180 * Math.PI;
tugao = (ugao - 90) / 180;
plot = 0;
while ( plot < 31) {
xcolor = Color.getHSBColor(0.41f, 0.9f, fade);
g.setColor (xcolor);
tx = Math.cos(tugao * Math.PI) * precnik/2 + kcentar.x;
ty = Math.sin(tugao * Math.PI) * precnik/2 + kcentar.y;
lt.x = (int) tx;
lt.y = (int) ty;
g.drawLine(lt.x, lt.y, kcentar.x, kcentar.y);
plot++;
tugao = tugao - 0.0015f;
fade = fade - 0.03f;
}
fade = 1.0f;
ut1 = Math.atan2(kcentar.x - t1.x, kcentar.y - t1.y);
if (ut1 < 0) { ut1 = 2 * Math.PI + ut1; }
if (ut1 > (tug - 0.02f)) {
if (ut1 < tug ) {
crt1 = 1.0f;
rt1.x = t1.x;
rt1.y = t1.y;
}
}
zcolor = Color.getHSBColor(0.41f, 0.9f, crt1);
g.setColor (zcolor);
if (precnik/2 > Math.sqrt(Math.pow(kcentar.x - rt1.x, 2) + Math.pow(kcentar.y - rt1.y, 2))) {
g.fillOval (rt1.x, rt1.y, 4, 4);
g.drawString("F18A", rt1.x + 4, rt1.y);
}
ut2 = Math.atan2(kcentar.x - t2.x, kcentar.y - t2.y);
if (ut2 < 0) { ut2 = 2 * Math.PI + ut2; }
if (ut2 > (tug - 0.02f)) {
if (ut2 < tug ) {
crt2 = 1.0f;
rt2.x = t2.x;
rt2.y = t2.y;
}
}
zcolor = Color.getHSBColor(0.41f, 0.9f, crt2);
g.setColor (zcolor);
if (precnik/2 > Math.sqrt(Math.pow(kcentar.x - rt2.x, 2) + Math.pow(kcentar.y - rt2.y, 2))) {
g.fillOval (rt2.x, rt2.y, 4, 4);
g.drawString("MIG29", rt2.x + 4, rt2.y);
}
ut3 = Math.atan2(kcentar.x - t3.x, kcentar.y - t3.y);
if (ut3 < 0) { ut3 = 2 * Math.PI + ut3; }
if (ut3 > (tug - 0.02f)) {
if (ut3 < tug ) {
crt3 = 1.0f;
rt3.x = t3.x;
rt3.y = t3.y;
}
}
zcolor = Color.getHSBColor(0.41f, 0.9f, crt3);
g.setColor (zcolor);
if (precnik/2 > Math.sqrt(Math.pow(kcentar.x - rt3.x, 2) + Math.pow(kcentar.y - rt3.y, 2))) {
g.fillOval (rt3.x, rt3.y, 4, 4);
g.drawString("B747", rt3.x + 4, rt3.y);
}
crt1 = crt1 - 0.002f;
if (crt1 <= 0) { crt1 = 0.002f; }
crt2 = crt2 - 0.002f;
if (crt2 <= 0) { crt2 = 0.002f; }
crt3 = crt3 - 0.002f;
if (crt3 <= 0) { crt3 = 0.002f; }
zcolor = Color.getHSBColor(0.41f, 0.9f, 1.0f);
g.setColor (zcolor);
g.drawOval(kcentar.x - precnik/2, kcentar.y - precnik/2, precnik, precnik);
g.drawOval(kcentar.x - 3*precnik/8, kcentar.y - 3*precnik/8, 3*precnik/4, 3*precnik/4);
g.drawOval(kcentar.x - precnik/4, kcentar.y - precnik/4, precnik/2, precnik/2);
g.drawOval(kcentar.x - precnik/8, kcentar.y - precnik/8, precnik/4, precnik/4);
g.drawLine(0, kcentar.y, getWidth(), kcentar.y);
g.drawLine(kcentar.x, 0, kcentar.x, getHeight());
}
public static void main(String args[]) {
try {
new radar().setVisible(true);
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}
Re: Java beans na koji nacin 18.02.2009. u 21:27 · pre 215 meseci #2
Pozdrav.

Napraviti JavaBean znaci prdzavati se specifikacije koju je SUN napisao, najvise radi pravljenja komponenti za razvojna okruzenja kao sto su NetBeans ili eclipse.
Medjutim praviti Bean znaci pridrzavati se dobre objektno orjentisane prakse, pa ako hoces da pravis klase koje je lako odrzavati najboljee ti je da naucis sta su JavaBeanovi.

A to ti je otprilike sledece:

svaka osobina u klasi pokusaj da bude private a ne public,protected i default (nije obavazno ali je preporuceno).
za svaku osobinu imas public metode koje vracaju vrijednost i postavljaju vrijednost, npr.

umjesto
public int precnik;

postavis npr.
Code:

      private int precnik;
      
      public int getPrecnik(){
          return precnik;
      }
      public void setPrecnik(int precnik){
         this.precnik = precnik;
      }


naziv metode pocinje sa get (geter), set(seter), is(geter za boolean).

Ovo ti je ukratko sta bi treba da radis.
Malo bi bilo previse da ti pisem bean za ovo to je po meni ipak stvar koju bi trebao ti da uradis, pa bi ti mnoge stvari bile jasnije i pokusaj da nadjes neko detaljnije upustvo.

Pozdrav,
nadam se da ce ti ovo pomoci.
Re: Java beans na koji nacin 09.03.2009. u 17:28 · pre 214 meseci #3
MOzda da kontaktiras Džanu..on to zna 100%....:::))))))
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme