📄 ch7_e7_5.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -