JButtonが、配列を使って8つのJTextFieldを変更する必要があります。ボタンやテキストを聴きますか?

StackOverflow https://stackoverflow.com/questions/1386888

質問

これは宿題であり、この質問はこの1

だからFirstPrevNextためのボタンがあり、かつLast

それぞれが変更する必要があります。

Item ID, Name, Rating, Price, Units, Value, Fee, ValueW/Fee, Total Inventory Value 

最後のものは、全てのユニットの静的合計である。

私は確信して私は各ボタンを作る必要がある場合はないのです。このような複数の呼び出しを行います。

productName.setText( product.getProductName() );
itemNumber.setText( String.valueOf( product.getItemNumber() ) );

またはメイク各JTextAreaには、そのフィールドを変更するには、ボタンを聞きます。それでも仕事をしていますか?

役に立ちましたか?

解決

登録各ボタンのActionListener。するActionListenerのactionPerformedメソッドの本体では、ディスプレイにアイテムを取得し、テキストフィールドに値を設定するための責任を負うことになりますメソッドに渡します。

のような何かます:

JButton button = new JButton("Next");
button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        DVDObject obj = getNextDVD();
        populateFields(obj);
    }
});

...

private DVDObject getNextDVD() {
    // gets the next object to display
    // you could call this method for each of the buttons, 
    // passing in an argument that determines which Object
    // to return (first, last, next, previous, whatever)
}

private void populateFields(DVDObject dvd) {
    // write out the values from the object passed in to the
    // fields
}

私はあなたがDVDに関するすべての情報が含まれているオブジェクトのコレクションのいくつかの種類を持って推測している、私は暗闇の中で刺しを取り、ここでは「DVDObject」と呼んできます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top