The previous article mainly focused on basic syntax, while this one focuses on GUI-related topics.
GUI is very old, and I wouldn't learn it if it weren't for exams.
1. What models are used to detect and respond to events in the java.awt.event package?
Answer: Source object (Source), Monitor object (EventListener), Event object (EventObject)
Monitor object -> Register to monitor an action -> Source object triggers an event -> Generates information (event object) -> Transmits
The model does not include event methods.
2. In Java, JPanel is a generic container, and its default layout is FlowLayout
In GUI, the default layout for windows and containers is FlowLayout.
3. In the Java language, the JTextField class is used to create text boxes, and the interface related to text boxes is
A. ActionListener
B. MouseListener
C. WindowListener
D. ItemListener
The answer is: A
The JTextField text box has two methods to set up listeners,
addActionListener(ActionListener)
removeActionListener(ActionListener)
The parameters are of ActionListener type, which requires the relevant object to implement the ActionListener interface.
4. In JAVA, there are three elements of font style, which are font, style, size
Style refers to the style, such as bold, italic, underline, etc.
5. In JAVA, the drawing object Graphics g has multiple drawing methods. Methods starting with draw create outlines, while fill creates solid shapes.
drawOval(int x, int y, int width, int height) draws an oval or circle.
drawRect(int x, int y, int width, int height) draws a rectangle.
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) draws a sector.
6. In JAVA, image processing functionalities are encapsulated in Image.
7. The class that supports audio formats for playback in Java applets is AudioClip
8. Layouts in GUI
In AWT, there are mainly six layout types.
FlowLayout - Flow layout
Default layout, controls are arranged from top to bottom and left to right.
BorderLayout - Border layout
Automatically docks to the edges of the window, and its dimensions change with the window.
GridLayout - Grid layout
Divides the container into several rows and columns.
CardLayout - Card layout
Like playing cards, each card is a control, and multiple controls overlap, showing only one at a time.
GridBagLayout - GridBag layout
null - Uses coordinate-based layout
9. Create a menu bar
JMenuBar menuobj = new JMenuBar();
10. There are two mouse events: MouseListener and MouseMotionListener.
11. The methods implemented by the KeyListener interface are:
keyPressed(KeyEvent e)
keyReleased(KeyEvent e)
keyTyped(KeyEvent e)
12. In JAVA, the three methods for controlling sound playback are: play(), stop(), loop()
13. In JAVA, the text selection dialog object is FileFilter, implementing accept(File f) and getDescription methods.
14. Two main plans for writing event handlers in Java language are:
① One is to reset the method handleEvent(Event), which requires slightly more work.
② The other is for the program to implement some system-defined interfaces.
15. Briefly describe the JDialog constructor:
1) JDialog() constructs an initially invisible non-modal dialog box.
2) JDialog(JFrame f, String s) constructs an initially invisible non-modal dialog box where parameter f sets the window the dialog depends on, and parameter s sets the title.
3) JDialog(JFrame f, String s, boolean b) constructs a non-modal dialog box initially invisible with title s, where parameter f sets the window the dialog depends on, and parameter b determines whether the dialog is modal or non-modal.
文章评论