📄 threelisteninner.java~20~
字号:
// P136 例 5-30 包含三个内部类的使用。package ThreeListenInner;import java.awt.*;import java.awt.event.*;public class ThreeListenInner { private Frame f; private TextField tf; private Button bt; public static void main(String s[]){ ThreeListenInner th=new ThreeListenInner(); th.go(); } public void go(){ f=new Frame("Three listers example"); //f.add() f.add("North",new Label("click and drag the mouse")); tf=new TextField(30); bt=new Button("close"); bt.setSize(10,5); bt.setBounds(10,0,10,40); f.add("South",tf); f.add("West",bt); f.addMouseMotionListener(new MouseMotionHandler()); f.addMouseListener(new MouseEventHandler()); f.addWindowListener(new WindowEventHandler()); f.setSize(300,300); f.setBackground(Color.white); f.setVisible(true); } // 内 部 类 public class MouseMotionHandler extends MouseMotionAdapter{ public void mouseDragged(MouseEvent e){ String s="Mouse dragging: x= "+e.getX()+"y= "+e.getY(); tf.setText(s); } } // 内 部 类 public class MouseEventHandler extends MouseAdapter{ public void mouseEntered(MouseEvent e){ String s="the mouse entered" ; tf.setText(s); } public void mouseExited(MouseEvent e){ String s="the mouse has left the building"; tf.setText(s); } public void mouseClicked(MouseEvent e){ String s="the mouse has click the building"; tf.setText(s); } } // 内 部 类 public class WindowEventHandler extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -