An example of Reflection laptop USB Interface Example

Source: Internet
Author: User

Notebook class:
Package Cn.fanse;public class Notebook {public void run () {System.out.println (' book Run ');} public void Useusb (USB usb) {Usb.open (); Usb.close ();}  }


USB Interface:

Package Cn.fanse;public interface USB {public void open ();     public void close ();


USB Interface for Mouse:

Package Cn.fanse;public class Mousebyusb implements usb{@Overridepublic Void Open () {System.out.println ("mouse Run");} @Overridepublic void Close () {System.out.println ("mouse Close");}   }

Keyboard for USB:

Package Cn.fanse;public class Keybyusb implements usb{@Overridepublic Void Open () {System.out.println ("key Run");} @Overridepublic void Close () {System.out.println ("key Close");}             }

Main function class:


Package Cn.fanse;import Java.io.file;import Java.io.fileinputstream;import java.io.ioexception;import Java.util.properties;public class Notbookdemmo {/** * @param args * @throws Exception  */public static void Main (String [] args) throws Exception {  Notebook book = new Notebook ();  Book.run ();  File config = new file ("Usb.properties");  if (!config.exists ())  {  config.createnewfile ();  }  FileInputStream fis = new FileInputStream (config);    Properties Prop =new Properties ();  Prop.load (FIS);    for (int x =1;x<=prop.size (); x + +)  {String className = prop.getproperty ("USB" +x); Class Clazz=class.forname (className); USB USB = (USB) clazz.newinstance (); BOOK.USEUSB (USB);}}}  


Configuration file:

Write the following in the configuration file usb.properties:

Usb1=cn.fanse.mousebyusb
Usb2=cn.fanse.keybyusb

Results:

Book Run
Mouse Run
Mouse Close
Key Run
Key Close



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

An example of Reflection laptop USB Interface Example

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.