java中实现字体的放大缩小

来源:百度知道 编辑:UC知道 时间:2024/05/15 07:14:10
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ChangeFront extends Applet implements ActionListener
{ Button but1,but2;
Font f,f1,f2;

public void init()
{
setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
but1=new Button("放大");
but2=new Button("缩小");
add(but1);
add(but2);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{

if(e.getSource()==but1)
{
g.setFont(f1);
}
if(e.getSource()==but2)
{
g.setFont(f2);
}
}
public void paint(Graphics g)

{
Font f=new Font("宋体",Font.BOLD+Font.ITALIC,25);
Font f1=new Font("Arial",Font.BOLD,36);
Font f2=new Font("宋体",Font.ITALIC,18);
g.setFont(f);
g.drawString("你

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ChangeFront extends Applet implements ActionListener
{
Button but1,but2;
Font f,f1,f2;
Label lb1;

public void init()
{
setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
but1=new Button("放大");
but2=new Button("缩小");
lb1=new Label("你好JAVA!");
add(but1);
add(but2);
add(lb1);

f=new Font("宋体",Font.BOLD+Font.ITALIC,25);
f1=new Font("Arial",Font.BOLD,36);
f2=new Font("宋体",Font.ITALIC,18);
but1.addActionListener(this);
but2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{

if(e.getSource()==but1)
{
lb1.setFont(f1);
}
if(e.getSource()==but2)
{
lb1.setFont(f2);
}
}

}

用到了Button 为什么不用Label呢?
把你的
p