📄 myexample.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Myexample extends WindowAdapter
implements ActionListener{
Frame f;
Panel p;
Label l;
Button b1,b2;
int i=20;
public static void main(String args[]){
Myexample me=new Myexample();
me.go();
}
public void go()
{
f=new Frame("Myexample");
p=new Panel();
b1=new Button("放大");
b2=new Button("缩小");
l=new Label("Hello");
f.add("Center",p);
f.add("East",b1);
f.add("West",b2);
p.add(l);
b1.addActionListener(this);
b2.addActionListener(this);
f.addWindowListener(this);
f.setSize(300,200);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="放大"){
i++;
l.setFont(new Font("TimesRoman",Font.PLAIN,i));
}
if(e.getActionCommand()=="缩小"){
i--;
l.setFont(new Font("TimesRoman",Font.PLAIN,i));
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -