P6-P15: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-06-05 03:15:38 +05:30
parent 539adc94da
commit 14898356a8
16 changed files with 675 additions and 0 deletions

43
P12.java Normal file
View File

@@ -0,0 +1,43 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public class P12 {
private String name;
private int age;
private PropertyChangeSupport propertyChangeSupport;
public P12() {
propertyChangeSupport = new PropertyChangeSupport(this);
}
public String getName() {
return name;
}
public void setName(String name) {
String oldName = this.name;
this.name = name;
propertyChangeSupport.firePropertyChange("name", oldName, name);
}
public int getAge() {
return age;
}
public void setAge(int age) {
if (age < 0) {
throw new IllegalArgumentException("Age cannot be negative");
}
int oldAge = this.age;
this.age = age;
propertyChangeSupport.firePropertyChange("age", oldAge, age);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
}