Java import confusion

前端 未结 4 664
半阙折子戏
半阙折子戏 2020-12-18 23:08

What is the difference between:

java.awt.*;

and:

java.awt.event.*;

I find both in many programs.

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 23:42

    Like many have said before.

    import java.awt.* won't import any classes in java.awt.event...

    And the difference between those two package is that java.awt.* include classes like a Frame, Button, etc and the java.awt.event.* package include all event / listener that can happen.

    Example, to create a Button you need the class java.awt.Button but if you want that any action happen when you click the Button, you need a java.awt.event.ActionListener that will "wait" for the click, then produce a java.awt.event.ActionEvent.

提交回复
热议问题