2017-01-12 5 views
0

のタイトルにそれを表示することができ、私は私のArrayListに私の最初のオブジェクトの名前を取りたいが、私は本当に私はこれを行う方法を知ってはいけません。私が取るこの名前は私のJFrameのタイトルでなければなりません。はどのように私は私のオブジェクトの名前を取り、JFrameの

これは私のJFrameです:

public class Bank { 

private String name; 
private String bic; 
private Adress adress; 
private ArrayList<Customer> customerList; 

public Bank() { 
    super(); 
    this. customerList = new ArrayList<Customer>(); 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public String getbIC() { 
    return bic; 
}// end of getbIC() 

public void setbIC(String bic) { 
    this.bic = bic; 
} 

public Adress getAdress() { 
    return adress; 
} 

public void setAdress(Adress adress) { 
    this.adress = adress; 
} 

public int sizeOfArraylist(){ 
    return customerList.size(); 
} 

public Customer get(int index){ 
    return customerList.get(index); 

} 

public ArrayList<Customer> getCustomerList() { 
    return customerList; 
}// end of getCustomerList() 

public void setCustomerList(ArrayList<Customer> customerList) { 
    this. customerList = customerList; 
} 

public boolean addAccount(Account account) { 
    for (Customer c : customerList) { 
     if (c.getCustomerNumber().equals(account.getCustomerNb())) { 
      boolean sucess = k.addAccount(account); 
      return sucess; 
     } 
    } 
    return false; 
} 

public void addCustomer(Customer customer) { 
    this.customerList.add(customer); 
} 

@Override 
public String toString() { 
    return "Bank [Name= " + name + ", BIC= " + bic + ", Adress= " + adress + ", Customer= " + customerList + " ]"; 
} 

} 

マイCustomerクラス:

public class TransactionFrame extends JFrame implements ActionListener { 
private Transaction trans; 
private Bank bank; 
private Customer customer; 
private Account acc; 
private Toolkit t; 
private int x=0, y=0, width=800, height = 600; 

public TransaktionFrame(Konto konto) throws HeadlessException { 
    super(); 
    this.konto = konto; 
    t = Toolkit.getDefaultToolkit(); 
    Dimension d = t.getScreenSize(); 
    x = (int)((d.getWidth() - width)/2); 
    y = (int)((d.getHeight()- height)/ 2); 

    setTitle("Application Java"); 

    setBounds(x, y, width, height); 
    setVisible(true); 
} 
} 

次はInitOfObjects

public class Menue { 

private Bank bank = new Bank(); 
private Account account = new Account(); 
private Customer customer= new Customer(); 

    public void initOfObjects(){ 
    Customer customer1 = new Privatecustomer("Ragnar", "Lothbrok", "017634456657", "[email protected]", "15.07.1979", 
    new Adress("Ragnarstraße", "22", "12159", "Berlin"), "2"); 
    bank.addCustomer(customer1); 

    Kunde customer2 = new Companycustomer("Varian", "Lothbrok", "017634456657", "[email protected]", "15.07.1979", 
    new Adress("Ragnarstraße", "22", "12159", "Berlin"), "2"); 
    bank.addCustomer(customer2); 

    Customer customer3 = new Privatecustomer("Rengar", "Lothbrok", "017634456657", "[email protected]", "15.07.1979", 
    new Adress("Ragnarstraße", "22", "12159", "Berlin"), "2"); 
    bank.addCustomer(customer3); 
} 
} 

私の銀行のクラスと呼ばれる方法で私のクラスMenueです。

public class Customer implements Comparator<Customer> { 

protected String customerNumber; 
private Adress adress; 
protected ArrayList<Account> account; 


public Customer(String cnb, Adress adress) { 
    super(); 
    this.customerNumber = cnb; 
    this.adress = adress; 
} 

public Customer(String customerNumber) { 
    this.customerNumber = customerNumber; 
} 

public Customer() { 

} 

public Adress getAdress() { 
    return adress; 
} 

public void setAdress(Adress adress) { 
    this.adress = adress; 
} 

public String getCustomerNumber() { 
    return customerNumber; 
} 

public Customer setCustomerNumber(String customerNumber) { 
    this.customerNumber = customerNumber; 
    return this; 
} 

public ArrayList<Account> getAccount() { 
    return account; 
} 


public boolean addAccount(Account acc) { 
    if (account == null) 
     account = new ArrayList<Account>(); 


    if (account.size() > 10) 
     return false; 


    account.add(k); 

    return true; 
} 


@Override 
public int compare(Customer o1, Customer o2) { 

    return o1.customerNumber.compareTo(o2.customerNumber); 
} 

} 

マイPrivatecustomerクラス(該当するショート):

public class Privatecustomer extends Customer { 

private String firstname; 
private String lastname; 
private Adresse adress; 
private String customerNumber; 

public Privatkunde(String firstname, String lastname, Adress adress, String kndnr) { 
    super(kndnr, adress); 
    this.firstname = firstname; 
    this.lastname = lastname; 
    this.adresse = adress; 
    this.customerNumber = cnb; 

} 
public String getFirstname() { 
    return firstname; 
} 

public void setFirstname(String firstname) { 
    this.firstname = firstname; 
} 

public String getLastname() { 
    return lastname; 
} 

public void setLastname (String lastname) { 
    this.lastname = lastname; 
} 

public Adress getAdress() { 
    return adress; 
} 

public void setAdress(Adress adress) { 
    this.adress = adress; 
} 

} 

マイCompanycustomerクラス(該当するショート):

public class Companycustomer extends Customer { 


private String companyName; 
private Adresse adr; 

public Companycustomer(String companyName, Adress adress, String customerNumber) { 
    super(customerNumber, adress); 
    this.companyName = firmenName; 
    this.adr = adress; 

} 

public String getCompanyName() { 
    return companyName; 
} 

public void setCompanyName(String companyName) { 
    this.companyName = companyName; 
} 

public Adresse getAdr() { 
    return adr; 
} 

public void setAdr(Adress adr) { 
    this.adr = adr; 
} 

PrivatecustomerとCompanycustomerは、お客様から延びています。 私はちょうどコードが実際に働くと言いたいと思います。 は、私はちょうど私が名前と顧客の姓と当社の顧客の名前を取り出すことができる方法を知りたいです。 なぜスイングを使うのですか?先生がそれを言ったからです。私は本当にjavafxを学びたいと思っていますが、先生はいいえと言いました。 もっとコードが必要な場合は、私にお書きください。私はJavaで本当に新しいです。

よろしく Maskulin

以下
+0

は、いくつかのJava FXを学ぶためにしようと、あなたの良い提案を、与えたい...スイングが – xFighter

+0

が同様にあなたの 'Bank'クラスコードを投稿とても悪いです。 –

+0

あなたのメニュークラスはあなたのフレームとやりとりする必要がありますが、フレームの参照を渡すことを示唆しているかもしれませんが、他のどのクラスが許可されているかを記述したインターフェイスを作成して実装します。 – MadProgrammer

答えて

0

私はあなたの完全な質問については非常にわからないんだけど、私は私はあなたが欲しいものを知っていると思うので、私'LL

Menue menu = new Menue(); 
menu.initOfObjects();//populate list of customers 

Bank bankObj=menu.getBank(); 
List<Customer> customers=bankObj.getCustomers();//get List of customers 

if(customers!=null && customers.size()>0) 
setTitle(customers.get(0).getCustomerName());//get First customer details 
+0

私はクラスの顧客の顧客の名前を避けているので私はちょうど私のポストを編集する。そのクラスのCompanycustomerとPrivatecustomer – MaskulinerJunge

0

、同じのための擬似コードでありますあなたに答えるためにいくつかの想像力を使ってください。

私はあなたが話しているのArrayListクラスの分野バンク銀行であり、あなたがMenueクラスを介してすべてのアカウントを格納しているので、最初のステップは、両方のクラスにゲッターを作成することであると仮定します:

public class Bank { 

    ... 

    ArrayListz<Customer> list; 

    public int size() 
    { 
     return list.size(); 
    } 

    // Notice that this WILL ASSUME that index is < than size 
    public Customer get(int index) 
    { 
     return list.get(index); 
    } 
} 

public class Menue { 

... 

    public Customer getCustomer(int index) 
    { 
     // If element exists at 'index', return it. If it doesn't, return null 
     return index >= bank.size() ? null : bank.get(index); 
    } 

} 

あなたはカスタマーフィールドの値を必要とするので、あなたは、上記のようなものの、右クラスで何かをする必要があります。

public class TransactionFrame extends JFrame implements ActionListener { 

    private Bank bank; 
    ... 

    public TransaktionFrame(Konto konto) throws HeadlessException { 
     super(); 
     ... 

     //this will return the name of the first customer  
     Customer customer = bank.getCustomer(0); 
     String name = customer == null ? "" : customer.getName(); 

     ... 

     setTitle(name); //this will use the name of your the first customer as the title of the JFrame 

    } 
} 

私はこれが解決した場合はわからない:さて、あなたはあなたが正しくあなたのJFrameクラスで初期化フィールド銀行を持っていると仮定すると、あなたはこのような何かを行うことができ、あなたが必要とするすべての情報にアクセスすることができますあなたの問題は、私はそれが役に立てば幸い:)

+0

私は自分のコースを編集するだけです。私はそれを修正する方法を理解していますが、顧客は名前を持っていません。名前はPrivatecustomerクラスとCompanycustomerクラスにあります。 – MaskulinerJunge

+0

また、Customer customer = bank.getCustomer(0);行のTransactionFrameクラスでNullpointerexceptionを取得します。 – MaskulinerJunge

関連する問題