Java Swing Project-Book Management System (SWING+MYSQL+JDBC) Summary

Source: Internet
Author: User

  

(i) Java Swing learning.

  (1) Learn how to install the Windowbuilder plug-in installation.

<1> Click Help in Eclipse

<2> in the Help dropdown select Install new software, add interface to pop-up plugin

<3> Click Add, and the following screen pops up:

      

 <4> Enter Windowbuider in the Name field

Enter the following address in location: http://download.eclipse.org/windowbuilder/WB/release/R201506241200-1/4.5/

After clicking OK, the following screen will appear:

      

<5> then select all the items, click Finish, and wait for the plugin to complete.

  (2) Learn to use Windowuilder to design the interface

<1> create an interface to take advantage of graphical design

<2> drag and Drop interface components (buttons, text boxes, labels)

<3> add icons and add events for interface components

  (3) To compensate for the lack of graphic design

<1> Change System font    

Change the system default fonts font font = new Font ("Dialog", Font.plain, 12);    java.util.Enumeration keys = Uimanager.getdefaults (). keys ();      while (Keys.hasmoreelements ()) {Object key = Keys.nextelement ();      Object value = Uimanager.get (key);      if (value instanceof Javax.swing.plaf.FontUIResource) {uimanager.put (key, font); }    }

  <2> Refine text field borders

Set Text field Border Booktypedesctext.setborder (New Lineborder (New Java.awt.Color (127,157,185), 1, false));

  (4) Special use of some components

<1> drop-down box use:

When a property is displayed for an entity class in the project, the ToString method of the entity class is typically overridden, and the entity class is added to the drop-down box instead of the property.

Use of <2>jdesktoppane

When this interface is a vector for other interfaces, use the JDesktopPane component in the form and then use the Internalframe design for the other interface.

Use of <3>jtabled

Design the structure of tables and add events through a graphical interface

Get the model of the table:

        DefaultTableModel dtm= (DefaultTableModel) Booktypetable.getmodel ();

To set the number of rows in a table:

Dtm.setrowcount (0);

To add a row of data to a table through the Vector collection class:

Create a new vector and initialize
Vector v=new vector ();
V.add (Rs.getint ("id")); Add an ID to the vector
V.add (rs.getstring ("Booktypename")); Add a booktypename to the vector
V.add (rs.getstring ("Booktypedesc")); Add a booktypedesc to the vector
Display the data in a vector in a table
Dtm.addrow (v);

After adding the Mousepressed event event to the table, get the line number selected by the mouse

int Row=booktable.getselectedrow ();

Gets the value of the specified column for the specified line number

String id=booktable.getvalueat (row,0) + "";

Two Learning from JDBC

(1) Dbutil Tool class

<1> database driver, the parameter value of the address only needs to be loaded once, so the reading of the parameter and the loading of the driver class are done in the static code block.

<2> use. Properties to store the various parameters of the database for later database switchover and maintenance.

<3> uses the properties class in Java.util to read. The value of the stored parameter in the peoperties.

Properties P=new properties (); Creates a Properties object.

P.load (DBUtil.class.getClassLoader (). getResourceAsStream ()); It is common to get static resources and configuration files through class loading.

P.getproperty ("xxx"); Read the parameter values for the file.

  (2) Create the corresponding entity based on the entity class DAO class

<1> implement additions and deletions of database entity records in DAO class.

<2> general Static SQL statements, using statement objects. Dynamic SQL statements use the PreparedStatement object instead.

<3>DDL uses the Execute method, DML uses the Executeupdate method, DQL uses the ExecuteQuery method.

  (3) Special use skills

<1>

* When querying a table with an indeterminate number of query conditions, It is a good idea to create a string buffer class to continually add conditions to the SQL statement.

* at the same time, it is not known which conditions are the first condition and cannot determine where the keyword is located, so the addition of conditions is used (and condition)

* When the last string is converted to a string, it is replaced by the first and the Where, and finally the complete SQL statement

(iii) Use of Eclipse shortcut keys in project design

Main shortcut key: main alt+/

alt+/: Auto Prompt

Ctrl+1: Prompt Error

Shortcut keys for Output statements: Syso alt+/

Popup Menu Shortcut: Ctrl+shift+s

Auto Introduction Package: Ctrl+shift+o

Enter the implementation: Hold down the CTRL mouse to move up and click.

Quick Delete line: ctrl+d

A line of code quickly moves up and down: ALT + UP ARROW and DOWN ARROW keys

Quick Fix Code: CTRL+SHIFT+F

( IV) use of debug

<1> break points on the code

<2> Enter debug mode

<3>f6 continue to the next step

<4>f8 executes to the next breakpoint, joins without, executes the program

<5>f5 Entering method interior

<6>f7 Bounce Method

<7> in debug, you can dynamically modify the value of a variable

<8>ctrl+shift+i can view the value of an expression

Java Swing Project-Book Management System (SWING+MYSQL+JDBC) Summary

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.