// Display font info.
import java.applet.*;
import java.awt.*;
/*
<applet code="FontInfo" width=350 height=60>
</applet>
*/
public class FontInfo extends Applet {
public void paint(Graphics g) {
Font f = g.getFont();
String fontName = f.getName();
String fontFamily = f.getFamily();
int fontSize = f.getSize();
int fontStyle = f.getStyle();
String msg = "Family: " + fontName;
msg += ", Font: " + fontFamily;
msg += ", Size: " + fontSize + ", Style: ";
if((fontStyle & Font.BOLD) == Font.BOLD)
msg += "Bold ";
if((fontStyle & Font.ITALIC) == Font.ITALIC)
msg += "Italic ";
if((fontStyle & Font.PLAIN) == Font.PLAIN)
msg += "Plain ";
g.drawString(msg, 4, 16);
}
}
i got confused on the use of bitwise and operator,program is correct but i don't understand its working like
if((fontStyle & Font.ITALIC) == Font.ITALIC)
what this mean, fontsyle contain information about style of text and font.italic is also a style of text but what Bitwise And operator doing in between,i know working of it like for eg: 1&4=0,but what is (font.italic & font.italic),Suppose if my text style is italic

New Topic/Question
Reply



MultiQuote




|