JavaBean 101 12

zhaozj2021-02-11  219

Finishing Touches

Now, the button has been displayed in Beanbox, which looks like a bean. The property table lists the properties of colors and tags. By editing attributes, you can set these two properties at the design phase. Note: The color of the button has become cyan (CYAN). To do this, you need to change the contents of the beancolor instance variable.

PRIVATE color beancolor = color.cyan;

The new display effect produced is implemented in the PAINT method of the bean.

G.fillarc (5, 5, 30, 30, 0, 360); G. Fillarc (25, 5, 30, 30, 0, 360);

These calls make the shape of the arc in the left and right sides of the initial square frame of the bean. The remaining code in the Paint method ensures that the String tag is at the center of the button:

INT width = size (). width;

INT height = size (). HEIGHT;

FontMetrics FM = g.getfontmetrics ();

g.drawstring (label, (width - fm.stringwidth) / 2,

(HEIGHT FM.GETMAXASCENT () - fm.getmaxdescent ()) / 2);

转载请注明原文地址:https://www.9cbs.com/read-4755.html

New Post(0)