JAVA : alter a font variable AFTER the fact

I’m trying to subclass a Java FONT object so that I can alter specific properties without having to deal with everything each time I want to change one property…

None of this works
any ideas? or am I totally off base


class dsFONT extends Font {
	private Integer zSize = 24;
 
 public dsFONT() {
 	super("Verdana", Font.PLAIN, 48);
 }
	public dsFONT(String name,Integer style,Integer size) {
		super(name,style, size);
	}

	public void fontNAME(String name) {
		Integer size = this.getSize();
		 dsFONT temp =  new dsFONT(name, Font.BOLD, size);
		 this = temp;
	}
	
	public void fontSIZE(Integer newValue) { 
	//	 String name = this.getName();
	 	this.setSize(newValue);
	//	 dsFONT temp =  new dsFONT(name, Font.BOLD, newValue);
	//	 this = temp;
	}

Assuming you’re using java.awt.Font as the base class

Class1.java:18: error: cannot assign to 'this'
		this = temp;

you’re NOT allowed to replace the “self” reference
a different design might be in order
perhaps your subclass simply has a private “Font” object that you manipulate & recreate as needed ? (composition)

Class1.java:23: error: cannot find symbol
		this.setSize(newValue);

Fonts have no setSize method
https://docs.oracle.com/javase/7/docs/api/java/awt/Font.html

EDIT : it appears to me that a Font is a reference to a specific face and size
Not something you can alter (note they have no setters)
So in your class extending a font may not be useful in any way

However, a dsFont that wraps a font inside so you CAN make it appear like the Font is “mutable” might be

import java.awt.Font ;

class dsFONT {

  private Font reference ;
	private Integer zSize = 24;

	public dsFONT() {
		reference = new Font("Verdana", Font.PLAIN, 48);
	}

	public dsFONT(String name,Integer style,Integer size) {
		reference = new Font(name,style, size);
	}

	public void fontNAME(String name) {
		Integer size = reference.getSize();
		reference =  new Font(name, Font.BOLD, size);
	}

	public void fontSIZE(Integer newValue) { 
				reference =  new Font(reference.getFontName(), Font.BOLD, newValue);
	}
	
}	

a slightly different design than you had in mind

All this said I might suggest reconsidering this design
Suppose you set a text field to use a dsFont with face Courier 24 bold
And, you set some other field to use that same reference
Now if you alter that reference because one text field should display larger text BOTH will change to whatever

Even in Xojo, or SWift, the font object isnt the thing that determines what face & size is used
The consumer (the text field text area etc) is and holds properties that it can get a correct Font reference at the size IT wants to use independent of anyone else using it

Thanks… my idea was that each control would have an INSTANCE of dsFONT