📅  最后修改于: 2020-09-29 01:20:37             🧑  作者: Mango
Toolkit类是Abstract Window Toolkit中每个实现的抽象超类。 Toolkit的子类用于绑定各种组件。它继承了Object类。
public abstract class Toolkit extends Object
import java.awt.*;
public class ToolkitExample {
public static void main(String[] args) {
Toolkit t = Toolkit.getDefaultToolkit();
System.out.println("Screen resolution = " + t.getScreenResolution());
Dimension d = t.getScreenSize();
System.out.println("Screen width = " + d.width);
System.out.println("Screen height = " + d.height);
}
}
输出:
Screen resolution = 96
Screen width = 1366
Screen height = 768
import java.awt.event.*;
public class ToolkitExample {
public static void main(String[] args) {
Frame f=new Frame("ToolkitExample");
Button b=new Button("beep");
b.setBounds(50,100,60,30);
f.add(b);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
}
});
}
}
输出:
import java.awt.*;
class ToolkitExample {
ToolkitExample(){
Frame f=new Frame();
Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");
f.setIconImage(icon);
f.setLayout(null);
f.setSize(400,400);
f.setVisible(true);
}
public static void main(String args[]){
new ToolkitExample();
}
}
输出: