小弟刚学JAVA,今天遇到一个问题:用paint() 方法显示一行字符串,Applet包含两个按纽,“放大”和“缩小”,当按放大时字符串放大一倍,缩小是缩小一倍,我写了这程序,但有错误,还望大家帮我解决 import java.awt.*; import java.applet.*; import java.awt.event.*;
public class Ok extends Applet implements ActionListener { int size=28; String s="字体"; public void init() { Button btn1=new Button("放大"); btn1.setActionCommand("num1"); Button btn2=new Button("缩小"); btn2.setActionCommand("num2"); add(btn1); add(btn2); btn1.addActionListener(this); btn2.addActionListener(this); } public void actionPerformed(ActionEvent e) { Font mine =new Font(s,Font.PLAIN,size); if(e.getActionCommand()=="放大") { size=size*2; setFont(mine); } else if(e.getActionCommand()=="缩小") { size=size/2; setFont(mine); } }
public void paint(Graphics g) { g.drawString(s,100, 100); } }