Java notes in the graphic class of the detailed

Source: Internet
Author: User

How the software interacts:
1. How the console interacts,
2. Interactive mode of graphical interface.

The graphics classes used in Java are mainly in java.awt and javax.swing packages.

The difference between java.awt and javax.swing package:
The graphics classes used in java.awt are all dependent on the system's graphics library.
The graphics classes used by the Javax.swing package are implemented by sun itself and do not require a system-dependent graphics library.
Question: Since the graphics class in the swing package has replaced the AWT package graphics class, why not delete AWT?

1, swing than the AWT package appears late, so there will be some interface is using the AWT package related classes and methods, delete will bring impact.
2, the AWT package contains not only the image class, there are other classes and methods. The two are only very high similarity on the graph class, while others are not.

All of the graphics classes in Java are called component classes.

Categories of components:
----------| Container components
----------| Non-container components

 Public classDemo1 { Public Static voidMain (string[] args) {JFrame frame=NewJFrame ("This is my first example of a graphical interface."); //set the size of a form//frame.setsize (300,400); //set the position where the form (upper-left corner) appears//frame.setbounds ((1366-300)/2, (768-400)/2, 300,400);//The first parameter is the x-coordinate of the upper-left corner, and the second parameter is the coordinate of the upper-left corner y. The third form is wide, and the fourth form is high. Initframe (Frame, -, -); Frame.setvisible (true);//setvisible Set the visibility of the form. //set up a form Close eventframe.setdefaultcloseoperation (jframe.exit_on_close); }            //Gets the screen's resolution setting form centered on the screen.      Public Static voidInitframe (JFrame frame,intwidth,intheight) {Toolkit Toolkit= Toolkit.getdefaulttoolkit ();//gets a system-related tool class object//get the screen resolutionDimension d =toolkit.getscreensize (); intx = (int) d.getwidth (); inty = (int) d.getheight (); Frame.setbounds ((x-width)/2, (Y-height)/2, width, height); }            }

Java notes in the graphic class of the detailed

Related Article

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.