第五周作业
2014-04-15 16:43
344 查看
[java] view
plaincopy
<pre code_snippet_id="277015" snippet_file_name="blog_20140405_1_6365875" name="code" class="java">import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FontSet
{
public static void main(String args[])
{
FontFrame frame= new FontFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class FontFrame extends JFrame
{
public FontFrame()
{
setTitle("设置字体");
setSize(WIDTH,HEIGHT);
FontPanel panel = new FontPanel();
Container contentPane =getContentPane();
contentPane.add(panel);
}
public static final int WIDTH =300;
public static final int HEIGHT =140;
}
class FontPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
//设置字体
Font f =new Font("宋体",Font.BOLD+Font.ITALIC,20);
g.setFont(f);
//显示文本
g.drawString("java 欢迎您!",x,y);
}
public int x=55;
public int y=50;
}</pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
plaincopy
<pre code_snippet_id="277015" snippet_file_name="blog_20140405_1_6365875" name="code" class="java">import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FontSet
{
public static void main(String args[])
{
FontFrame frame= new FontFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class FontFrame extends JFrame
{
public FontFrame()
{
setTitle("设置字体");
setSize(WIDTH,HEIGHT);
FontPanel panel = new FontPanel();
Container contentPane =getContentPane();
contentPane.add(panel);
}
public static final int WIDTH =300;
public static final int HEIGHT =140;
}
class FontPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
//设置字体
Font f =new Font("宋体",Font.BOLD+Font.ITALIC,20);
g.setFont(f);
//显示文本
g.drawString("java 欢迎您!",x,y);
}
public int x=55;
public int y=50;
}</pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>
<pre></pre>