ch7_e7_5.java

来自「各种关于JAVA的初级编程」· Java 代码 · 共 44 行

JAVA
44
字号
import java.applet.*; 
import java.awt.*;
import java.awt.event.*;

public class ch7_e7_5 extends Applet implements ActionListener
{
    String msgString = "SEE ME? AM I CLEAR ENOUGH?";
    Button enlargeBtn = new Button("放大");
    Button dwindleBtn = new Button("缩小");
    int currentFontSize = 12;
    
    public void init()
    {
        add(enlargeBtn);
        add(dwindleBtn);
        
        currentFontSize = 12;
        enlargeBtn.addActionListener(this);
        dwindleBtn.addActionListener(this);
    }
    
    public void paint(Graphics g)
    {
        Font newFont,oldFont;
        
        oldFont = g.getFont();
        
        newFont = new Font(oldFont.getFontName(),
            oldFont.getStyle(), currentFontSize);
        g.setFont(newFont);
        g.drawString(msgString,10,100);
    }
    
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource() == enlargeBtn)
            currentFontSize++;
        else if(ae.getSource() == dwindleBtn)
            currentFontSize--;
        System.out.println(currentFontSize);
        repaint();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?