50 likes | 61 Views
Miscellaneous Topics #4 Fonts and Custom Colors. Inputting Numeric Types. JOptionPane.showInputDialog() can be used to input any of the numeric types when you use the following conversion methods:. Working with Fonts. To Create a font object with the font name, style, and point size, use:
E N D
Inputting Numeric Types JOptionPane.showInputDialog()can be used to input any of the numeric types when you use the following conversion methods:
Working with Fonts To Create a font object with the font name, style, and point size, use: Font labelFont = new Font("TimesRoman",Font.BOLD,24); Font normalFont = new Font("Helvetica",Font.PLAIN,12); To set the current font: gObj.setFont(labelFont);
Drawing Strings • To draw a string gObj.drawString("test string", leftX, baselineY); ascent leading leftX test string height baselineY descent
Custom Colors You can define Custom Colors by declaring your own Color object with different RGB values as follows, where r,g,b are 3 values from 0 to 255: Color theColor = new Color(r,g,b); The above statement declares “theColor” to be a variable object (instead of a primitive) with Color as its type. The term “new” means that a new instance of the object will be created with the specified values. This is called “instantiation” and is done for many other types of objects as well.