主题:[求助]帮忙楸错!
大家帮忙看下以下代码
单击按钮后,字符能放大或缩小,
为什么就是画布不能刷新...?
----------------------------------------------------------------------------
/*
*编写一个Applet程序显示一行字符串,Applet包含两个按钮“放大”和“缩小”
*当用户单击放大时,显示的字符串字体放大一号,单击缩小时,显示的字符串字体缩小一号
*/
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
public class Bian extends JApplet
{
int zihao = 10;
public void init()
{
setLayout(new BorderLayout()); //设置布局
JButton b1 = new JButton("增大字体"); //声明组件
JButton b2 = new JButton("减小字体");
JPanel p =new JPanel(); //声明面板
p.setLayout(new FlowLayout());
p.add(b1); //添加组件
p.add(b2);
add(p,BorderLayout.SOUTH);
setBounds(300,300,800,200);
setVisible(true);
b1.addActionListener(new ActionListener() //b1事件处理
{
public void actionPerformed(ActionEvent e)
{
zihao = zihao + 2;
repaint();
}
}
);
b2.addActionListener(new ActionListener() //b2事件处理
{
public void actionPerformed(ActionEvent e)
{
zihao = zihao - 2;
repaint();
}
}
);
}
public void paint(Graphics g)
{
Font f = new Font("DialogInput",Font.BOLD,zihao);
g.setFont(f);
g.drawString("点击按钮改变大小",175,150);
}
}
单击按钮后,字符能放大或缩小,
为什么就是画布不能刷新...?
----------------------------------------------------------------------------
/*
*编写一个Applet程序显示一行字符串,Applet包含两个按钮“放大”和“缩小”
*当用户单击放大时,显示的字符串字体放大一号,单击缩小时,显示的字符串字体缩小一号
*/
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
public class Bian extends JApplet
{
int zihao = 10;
public void init()
{
setLayout(new BorderLayout()); //设置布局
JButton b1 = new JButton("增大字体"); //声明组件
JButton b2 = new JButton("减小字体");
JPanel p =new JPanel(); //声明面板
p.setLayout(new FlowLayout());
p.add(b1); //添加组件
p.add(b2);
add(p,BorderLayout.SOUTH);
setBounds(300,300,800,200);
setVisible(true);
b1.addActionListener(new ActionListener() //b1事件处理
{
public void actionPerformed(ActionEvent e)
{
zihao = zihao + 2;
repaint();
}
}
);
b2.addActionListener(new ActionListener() //b2事件处理
{
public void actionPerformed(ActionEvent e)
{
zihao = zihao - 2;
repaint();
}
}
);
}
public void paint(Graphics g)
{
Font f = new Font("DialogInput",Font.BOLD,zihao);
g.setFont(f);
g.drawString("点击按钮改变大小",175,150);
}
}