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