Graphical user interface written in Java knowledge

Graphical user interface written in Java knowledge

1, concepts: the Abstract Window Toolkit AWT (the Abstract Window Toolkit) is to establish Java provides a graphical user interface, the GUI (Graphics the User Interface) development package, AWT can be used in the java Applet and Application.

2, the Component class some important members of the approach include:

  1. getComponentAt component object (int x, int y) obtained coordinates (x, y) on
  2. getFont () font obtain components
  3. getForeground () foreground component obtained
  4. getName () to get the name of the component
  5. getSize () Gets the size of the component
  6. paint (Graphics g) drawing assembly
  7. repaint () to redraw assembly
  8. update () Flash Components
  9. setVisible (Boolean b) provided the component is visible
  10. setSize (Dimension d) set the size of the component
  11. setName (String name) Set the name of the component

3, the container java.awt.Container is a subclass of Component.
Common container: Window, Panel, ScrollPane, commonly used Panel (panel) , Frame (window) , the Applet.

4, if the user to personally set the size or position of the component, it should be canceled layout manager container , method: setLayout (null); then call setLocation (), setSize (), setBounds ().

5, LayoutManager (layout manager) related classes include: the FlowLayout, the BorderLayout, GridLayout, A CardLayout, the GridBagLayout .

6, the BorderLayout layout manager is Windows, Frame and Dialog's default manager .

7. Close the window function to achieve

public void windowClosing(WindowEvent e){System.exit(1);}

8, java.awt.event package defined event adapter classes include the following:

  1. ComponentAdapter (component adapter)
  2. ContainerAdapter (container adapter)
  3. FocusAdapter An (focus adapter)
  4. KeyAdapter (keyboard adapter)
  5. MouseAdapter (mouse adapter)
  6. MouseMotionAdapter (mouse movements adapter)
  7. WindowAdapter (window adapter)

9, Choice (drop) with ItemListener interface to listen

10, an application must inherit the Canvas class in order to obtain useful features. If you want to perform some graphics on canvas, the Canvas class paint () method must be rewritten. When you enter characters in the Canvas component, you must first call
requestFocus () method.

11, single-line text input area ( the TextField ) only one line is when the Enter key is pressed, the ActionEvent event occurs, by the ActionListener actionPerfomed () method of the event accordingly. May be used setEditable (boolean) method is set to read-only property.

12, the event adapter provides a simple means to achieve the listener. When you need multiple monitors or such parent can not adopt an existing event adapter.

  1. Event adapter -EventAdapter
  2. Achieve internal event processing class
  3. Anonymous class (Anonymous Class)

13, AWT component library

  1. Button the Button , will have an ActionEvent need ActionListener interface to listen and handle events. ActionEvent object calls getActionCommand () method can be distinguished name of the button.
  2. Checkbox Checkbox with ItemListener to listen ItemEvent event, with a check box when the state changes getStateChange () Gets the current status.
  3. Checkbox Group ( CheckboxGroup )
  4. Drop-down menu ( Choice ) with ItemListener interface to listen
  5. Canvas component monitors various mouse and keyboard events.
  6. Single-line text input area ( the TextField )
  7. Text input area ( the TextArea )
  8. List ( List )
  9. Framework ( Frame )
  10. Dialog ( Dialog )
  11. File dialog ( FileDialog )
  12. Menu ( Menu )
  13. MenuBar only be added to Frame object, as the foundation of the entire menu tree.
  14. Menu item ( MenuItem ) is a menu tree "leaf node", add ActionListener

14, set the component font with setFont () method, can also call the Toolkit objects of getFontList () for a complete list of fonts method, you can also use the default Toolkit , such as the use Toolkit.getDefaultToolkit () to get the default character set.

15, Jcomponent kind of special functional classification:

  1. Setting the border with setBorder ()
  2. Dual Buffer: for closing setDoubleBuffered (false) method.
  3. Message: setToolTipText () method
  4. Keyboard navigation
  5. L & F can be inserted: with the UIManager.setLookAndFeel () method sets the desired L & F
  6. Layouts

16, two ways to add components JFrame

  • Obtained by the getContentPane () method JFrame content panel assembly again added: . Frame.getConlentPane () the Add (childComponent)
  • The JPanel establish a (panel) or the intermediate container JdesktopPane like, by adding components to the container, and then setConentPane () method of the container is set to the contents of the panel JFrame:
Jpanel contentPane=new Jpanel();
//......把其他组件添加到Jpanel中
frame.setContentPane(contentPane);//把contentPane对象设置成为frame的内容面板
Released eight original articles · won praise 2 · Views 439

Guess you like

Origin blog.csdn.net/weixin_45704114/article/details/104263860