May 24, 2016 Java Basics Small Summary

Source: Internet
Author: User

1, exception (risk control)--catch the exception and let the program run properly

(1) Form: try{Listen for possible exception code}catch (exception name) {processing};

(2) The exception exception class inherits the Throwable, but it is the parent class of all exceptions;

(3) Common: runtimeexception (abnormal operation)-nullpointerexception;indexoutofboundeexception-arrayindexoutofexception;

(4) Print out the exception catch (Exception e) {e.printstacktrace ();}, this exception catch block is usually placed in the last, waiting for all exceptions to be judged and then executed;

(5) finally{}, the contents of the block, whether or not an exception will be executed, placed in the last catch, can be used for database shutdown operations;

2, graphical interface--java.swing:

(1) Form JFrame: The main creation step is

<1> Create a new JFrame first

<2> It takes two steps if you want to be visible: the first step SetSize (); second step: setvisible (True);

<3> Close: F.setdefaultcloseoperation (Jframe.exit_on_close), the process automatically exits after closing the window;

(2) Jpanel,jbutton, the creation steps and JFrame are basically consistent, but JPanel to be placed above the jframe, and JButton need to be placed above the JPanel;

(3) JTextField text box, created in two ways, one is extends JFrame, one is jframe.add; you can use SetFont;

(4) Font fonts--java.awt:font f = new Font ("Microsoft Jas Black", font.bold,15);

3, User events

(1) Mainly include: Event source, event, event processing program;

(2) Registered Monitor: B1.addactionlistener (this);-the class name needs to add implements ActionListener;

Event handling: Some event @override will be reconstructed according to IMPLEMEMT;

(3) Event type--jave.awt.event,javax.swing.event

ActionEvent (ActionListener)/focusevent (Focuslistener)/keyevent (KeyListener)/mouseevent/windowevent/textevent/

   

May 24, 2016 Java Basics Small Summary

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.