Komponent jeszcze raz

0

Mój temat przeniesiono do kosza a ja zapytam jeszcze raz bo wtedy nie dostalem odpowiedzi.

Czy ta klasa jest komponentem I chodzi mi o sposob programowania !!! (czytaj programowanie struktualne, obiektowe i komponentowe) np java beans. Jesli nie to co musi zawierac zeby byc komponentem.
Jeszcze raz powtarzam nie chodzi mi o Component (jakim jest jLabel itp) Wiem co to Component!

package pl.toXML.app;
import nu.xom.*;
import java.io.*;
import java.util.*;
 
 
public class Zgloszenia {
        public String nr, data, imie, nazwisko, sprzet, opis, status;
        public Zgloszenia(String nr, String data, String imie, String nazwisko, String sprzet, String opis, String status){
                this.nr = nr;
                this.data = data;
                this.imie = imie;
                this.nazwisko = nazwisko;
                this.sprzet = sprzet;
                this.opis = opis;
                this.status = status;
        }
        //Tworzy element (Element) XML na bazie obiektu Zgloszenie (this):
        public Element getXML(){
                Element zgloszenie = new Element("zgloszenie");
                Element nrid = new Element("nr");
                nrid.appendChild(nr);
                Element dataid = new Element("data");
                dataid.appendChild(data);
                Element imieid = new Element("imie");
                imieid.appendChild(imie);
                Element nazwiskoid = new Element("nazwisko");
                nazwiskoid.appendChild(nazwisko);
                Element sprzetid = new Element("sprzet");
                sprzetid.appendChild(sprzet);
                Element opisid = new Element("opis");
                opisid.appendChild(opis);        
                Element statusid = new Element("status");
                statusid.appendChild(status);
 
                zgloszenie.appendChild(nrid);
                zgloszenie.appendChild(dataid);
                zgloszenie.appendChild(imieid);
                zgloszenie.appendChild(nazwiskoid);
                zgloszenie.appendChild(sprzetid);
                zgloszenie.appendChild(opisid);
                zgloszenie.appendChild(statusid);
 
                return zgloszenie;
        }
        //Konstruktor przywracający obiekt Zgloszenie z elementu XML:
        public Zgloszenia(Element zgloszenie){
                nr = zgloszenie.getFirstChildElement("nr").getValue();
                data = zgloszenie.getFirstChildElement("data").getValue();
                imie = zgloszenie.getFirstChildElement("imie").getValue();
                nazwisko = zgloszenie.getFirstChildElement("nazwisko").getValue();
                sprzet = zgloszenie.getFirstChildElement("sprzet").getValue();
                opis = zgloszenie.getFirstChildElement("opis").getValue();
                status = zgloszenie.getFirstChildElement("status").getValue();
        }
        public String toString(){return nr + " " + data;}
        //Dla czytelności:
        public static void format(OutputStream os, Document doc) throws Exception{
                Serializer serializer = new Serializer(os,"Windows-1250");
                serializer.setIndent(4);
                serializer.setMaxLength(60);
                serializer.write(doc);
                serializer.flush();
        }
        public static void glowny() throws Exception{
                 List<Zgloszenia> people = Arrays.asList(
                                new Zgloszenia("aaaaaa", "Kleks","a","fsfd","fsdfsd","fsdff","sdff"));
                                 //new Zgloszenia(app.Zgloszenie.jPanel1.jTextField1.getText(""), "Kleks","a","","","",""));
                System.out.println(people);
                Element root = new Element("zgloszenie");
                for(Zgloszenia p: people)
                        root.appendChild(p.getXML());
                Document doc = new Document(root);
                format(System.out, doc);
                format(new BufferedOutputStream(new FileOutputStream(
                                "zgloszenie.xml")), doc);
        }
}
1

Java bean musi mieć konstruktor bezargumentowy, gettery i settery (public). Musi też implementować interfejs Serializable.

0

A moglbys mi mniej wiecej powiedziec gdzie je wstawic i czy w ogóle z tej klasy idzie na java beean przerobic ??

1

Spróbuj tak (jak korzystasz z dobrego IDE, to IDE samo wygeneruje wszystkie settert i gettery):

public class Zgloszenia implements interface Serializable{
        private String nr, data, imie, nazwisko, sprzet, opis, status;
        public Zgloszenia(){
                this("","","","","","","");
        }
        public Zgloszenia(String nr, String data, String imie, String nazwisko, String sprzet, String opis, String status){
                this.nr = nr;
                this.data = data;
                this.imie = imie;
                this.nazwisko = nazwisko;
                this.sprzet = sprzet;
                this.opis = opis;
                this.status = status;
        }
        public void setNr(String nr){
                this.nr = nr;
        }
        public String getNr(){
                return this.nr;
        }
        ...
0

Dzieki ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1