Head the Java note (d) __java

Source: Internet
Author: User
Graphical User InterfaceJFrame: Creates gui:1 for objects that are windows on the screen. Create frame
JFrame frame = new JFrame ();
2. Create Widget
JButton button = new JButton ("click Me");
3. Add the widget to the frame
Frame.getcontentpane (). Add (button);
4. Show up
Frame.setsize (300,300);
Frame.setvisible (TRUE);

The "Look and feel" type of the core function library controls the appearance and operating feelings of the interface.

Listening interface: A bridge between the listener (you) and the event source. An event source is an object that converts user actions (click the mouse, press the key, close the window, and so on) to a time. An event source, such as a button, produces an event object when the user makes a related action (press the button). Each event type has a corresponding listener interface. If you want to receive mouseevent, you can implement MouseListener this interface.
Gets the ActionEvent of the button 1. Implement ActionListener this interface 2. Register to button
Button.addactionlistener (this);
3. Define event-handling methods (implement the methods on the interface)
public void actionperformed (ActionEvent event) {
    button.settest ("clicked!");
}


3 ways to add something to the GUI: 1. To prevent widget on frame
Frame.getcontentpane (). Add (button);
2. Draw a 2D graphic on the widget
Graphics.filloval (70,70,100,100);
3. Draw a JPEG image on the widget
Graphics.DrawImage (Mypic,10,10,this);

Create your own drawing components: Create JPanel subclasses and overwrite the Paintcomponent () method.

Note: The parameters of paintcomponent () are declared as graphics types
public void Paintcomponent (Graphics g) {}
The object referenced by G is actually a graphics2d instance. To invoke the Graphics2D method, you cannot use the G parameter directly, you can convert it to a graphics2d variable
Graphics2D g2d = (graphics2d) g;


Inner class: Using all external methods and variables (including private)
An inner class provides a different way to implement the same interface in a class. eg. make a different actionlistener in a single class
SwingComponent (component): something that a user can see, interact with the user, put on a GUI, and inherit from a javax.swing.JComponent component that can be nested: You can put anything on something else. Layout Manager (layout managers): Controls other components that are carried on the associated component
The three chief managers: BorderLayout: Split the background components into 5 areas, each region can only put one component, the component usually does not go to the default size. (frame default layout manager)
BorderLayout the north-South layout uses the ideal height of the component, regardless of width, the middle area can only use the remaining space. FlowLayout: Each component is rendered according to the desired size and is arranged in the order of entry from left to right (possibly wrapped). (Panel default layout manager)
BoxLayout: Use the default size of each component, in the order in which they are added, in a vertical direction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.