For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > February 2005 > bean property problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author bean property problem
suresh

2005-02-04, 3:57 am

Aim:
Create an invisible Java bean that multiplies the values of two of its
properties

and places the product in a third as a read only property.
To acheive above requirement i write source code in java.
but can't satisfy on result.
i can't fulfil one condition i.e third property is read only. it give
permission

write also.
i tried so many different ways to acheive above requirement.
for example i change modifer of set() of read property. it can't
display that

property.

i want solution on this requirement.
i send two different java source files.

// source code no:1 "TestReadProp.java"

import java.beans.*;
import java.io.*;
public class TestReadProp implements Serializable {
private double A,B,C;

synchronized public void setA(double val) {
A=val;
multiply();
}
synchronized public void setB(double val) {
B=val;
multiply();
}

synchronized public void setC(double val)
{ C=val; }

synchronized public double getA() {
return A;
}
synchronized public double getB() {
return B;
}

synchronized public double getC( ) {
return C;
}

private void multiply() {
double oldC=C;
C=A*B;
change.firePropertyChange("",new Double(oldC),new

Double(C));
}

public PropertyChangeSupport change = new

PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChange
Listener

listener) {
change.addPropertyChangeListener(listener);
}
public void

removePropertyChangeListener(PropertyCha
ngeListener listener) {
change.removePropertyChangeListener(listener);
}
}

// source code no:2 "multiplier.java"

import java.beans.*;
import java.io.*;
public class multiplier implements Serializable {
private double a,b,Answer;

synchronized public void setA(double val) {
a=val;
multiply();
}
synchronized public void setB(double val) {
b=val;
multiply();
}

/*synchronized public void setAnswer(double val)
{ Answer=val; }
*/

synchronized public double getA() {
return a;
}
synchronized public double getB() {
return b;
}

synchronized public double getAnswer() {
return Answer;
}

private void multiply() {
double oldC=Answer;
Answer=a*b;
change.firePropertyChange("",new Double(oldC),new

Double(Answer));
}

public PropertyChangeSupport change = new

PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChange
Listener

listener) {
change.addPropertyChangeListener(listener);
}
public void

removePropertyChangeListener(PropertyCha
ngeListener listener) {
change.removePropertyChangeListener(listener);
}
}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com