📄 fonts.java
字号:
// Fig. 12.9: Fonts.java
// Using fonts.
import java.awt.*;
import javax.swing.*;
public class Fonts extends JFrame {
// set window's title bar and dimensions
public Fonts()
{
super( "Using fonts" );
setSize( 600, 400 );
setVisible( true );
}
// display Strings in different fonts and colors
public void paint( Graphics g )
{
// call superclass's paint method
super.paint( g );
// set font to Serif (Times), bold, 12pt and draw a string
g.setColor(Color.YELLOW);
g.setFont( new Font( "Serif", Font.BOLD, 24 ) );
g.drawString( "我是黑体", 20, 50 );
// set font to Monospaced (Courier), italic, 24pt and draw a string
g.setColor(new Color(0,255,0));
g.setFont( new Font( "Monospaced", Font.ITALIC, 48 ) );
g.drawString( "我是斜体", 20, 120 );
// set font to SansSerif (Helvetica), plain, 14pt and draw a string
g.setColor(Color.BLUE);
g.setFont( new Font( "SansSerif", Font.PLAIN, 28 ) );
g.drawString( "我是正常体", 20, 200 );
// set font to Serif (Times), bold/italic, 18pt and draw a string
g.setColor( Color.RED );
g.setFont( new Font( "Serif", Font.BOLD + Font.ITALIC, 18 ) );
g.drawString( g.getFont().getName() + " " + g.getFont().getSize() +
" 我是粗斜体", 20, 300 );
} // end method paint
// execute application
public static void main( String args[] )
{
Fonts application = new Fonts();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class Fonts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -