---
# System prepended metadata

title: Résumer ExamEN!!!!!!!!
tags: [Système acces / libraries]

---

###### tags: `Système acces / libraries`
# Résumer ExamEN!!!!!!!!

![](https://i.imgur.com/JysBG9K.png)

![](https://i.imgur.com/PrmE8RO.png)

# Théorie
![](https://i.imgur.com/MG7JSkY.png)

## DLL Dynamic/Static

**Dynamic:**
avantage:x1mémoire
désavanatage:on ne peut pas copier un fichier parce qu'il peut avoir bcp de dépendances 


**static:**
avantage:on peut copier le fichier car toutes les librairies sont attaché
désavanatage: utilise plus de mémoire

![](https://i.imgur.com/UdaQxds.png)

## JNA
**JNA provides Java programs easy access to native shared libraries. Just 
writing Java-Code. (JNI is more complex and you have to write C-Code)**


## exemple dans cmd
chercher variables dans le système de l'ordinateur 

*Exemple :*
```
String sleep = System.getenv("sleep");
```

C:\windows\notepad.exe chemin du programme notepad est le chemin complet pour le notepad mais avec notepad il trouve car ça se trouve dans le PATH


## beep fonction


![](https://i.imgur.com/wJUQCyD.png)

`rundll32.exe Kernel32.dll Beep 50 `



## JNA avec la carte velleman

1. Ouvrir le logiciel dll export viewer
2. regarder les méthodes possible 
3. voir les signatures de ces méthodes dans le manuel
4. tester en JAVA dans netbeans


Tips: 
- Enregistrer le fichier dll dans windows-system32 ou a l'emplacement du projet netbeans à côté du fichier pom.xml
- ne pas oublier de **build with dependencies**

## C++
![](https://i.imgur.com/FZmLSnQ.png)




# programs
## DLL 
Si besoin de dll. Mettre le fichier à côté du pom.xml dans le projet netbeans
![](https://i.imgur.com/1CbxAFk.png)

## depedencies
ne pas oublier de **build with dependecies**
![](https://i.imgur.com/G8OPVt7.png)

### JNA
```
 <dependency> 
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna-platform</artifactId>
            <version>5.11.0</version>
        </dependency>
 ```
 ### OpenCV Computer Vision Librairy
 ```  
        <dependency>
            <groupId>org.openpnp</groupId>
            <artifactId>opencv</artifactId>
            <version>4.5.1-2</version>
        </dependency>
```


## ROBOT

Utiliser les touches du clavier et les commande windows
```

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import static java.awt.event.InputEvent.BUTTON1_DOWN_MASK;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author manuel.gerber
 */
public class RobotDemo {

    public static void wait(int ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

    }

    public static void main(String[] args) throws AWTException {

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot r = new Robot();
        Color c = r.getPixelColor(2, 0);
        System.out.println(c.toString());

        r.mouseMove(100, 200);
        r.keyPress(KeyEvent.VK_WINDOWS);
        r.keyPress('R');
        r.keyRelease('R');
        r.keyRelease(KeyEvent.VK_WINDOWS);
        wait(200);
        r.keyPress('C');
        r.keyPress('M');
        r.keyPress('D');
        r.keyPress(KeyEvent.VK_ENTER);
        wait(1000);
        r.keyPress('I');
        r.keyPress('P');
        r.keyPress('C');
        r.keyPress('O');
        r.keyPress('N');
        r.keyPress('F');
        r.keyPress('I');
        r.keyPress('G');
        r.keyPress(KeyEvent.VK_ENTER);
        

        /*
        r.mouseMove(200, 500);
         wait(1000);
        r.mousePress(BUTTON1_DOWN_MASK);
         wait(1000);
        r.mouseMove(800, 500);
         wait(1000);
        r.mouseRelease(BUTTON1_DOWN_MASK);
        
       for (int i=0; i<2; i++){
            r.mouseMove(100, 100);
             wait(1000);
            r.mouseMove(100, 200);
             wait(1000);
            r.mouseMove(200, 200);
             wait(1000);
             r.mouseMove(200, 100);
              wait(1000);
        }*/
        BufferedImage image = r.createScreenCapture(screenRectangle);
        

    }
}

```

## Color Picker and Grapic
montre la couleur de ou est le curseur de la sourie
### ColorPicker
```
import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import timeChrono.Chrono;

/**
 *
 * @author manuel.gerber
 */
public class ColorPicker implements Runnable, Observable {

    List<InvalidationListener> list = new ArrayList<>();
    Color color;
    Chrono chrono = new Chrono();

    public ColorPicker() {
        chrono.start();
        ScheduledExecutorService s = Executors.newScheduledThreadPool(1);
        s.scheduleAtFixedRate((Runnable) this, 0, 200, TimeUnit.MILLISECONDS);
        

    }

    public void askColor() throws AWTException {
        
        Robot r = new Robot();
        Point p = MouseInfo.getPointerInfo().getLocation();
        int x = p.x;
        int y = p.y;
        Color c = r.getPixelColor(p.x, p.y);
        color =c;
        System.out.println(c.toString());
        inform();
       
    }
    
    public Color getColor(){
        return color;
    }

    @Override
    public void run() {
        try {
            askColor();
        } catch (AWTException ex) {
            Logger.getLogger(ColorPicker.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    public void addListener(InvalidationListener listener) {
        list.add(listener);
    }

    @Override
    public void removeListener(InvalidationListener listener) {
        list.remove(listener);
    }

    public void inform() {
        {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    for (InvalidationListener listener : list) {
                        listener.invalidated(ColorPicker.this);
                         chrono.lap();

                    }
                }
            });
        }
    }
}

```

### ColorGraphic
```
import java.awt.AWTException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

/**
 *
 * @author manuel.gerber
 */
public class ColorGraphic extends Application implements InvalidationListener {

    private TextField textField = new TextField();
    private Circle circle = new Circle();
    Scene scene;

    public ColorGraphic() {
        circle.setCenterX(10);
        circle.setCenterY(30);
        circle.setRadius(10);
    }

   

    @Override
    public void start(Stage stage) throws Exception {
        ColorPicker cp = new ColorPicker();
        cp.addListener(this);

        VBox pane = new VBox();
        scene = new Scene(pane);
        stage.setScene(scene);
        pane.getChildren().addAll(textField, circle);
        stage.show();
    }

    @Override
    public void invalidated(Observable observable) {

        java.awt.Color color = ((ColorPicker) observable).getColor();
        textField.appendText(color + "|"); //add actual to history

        //changement de couleur
        java.awt.Color awtColor = ((ColorPicker) observable).getColor(); 
        int r = awtColor.getRed();
        int g = awtColor.getGreen();
        int b = awtColor.getBlue();
        int a = awtColor.getAlpha();
        double opacity = a / 255.0;
        javafx.scene.paint.Color fxColor = javafx.scene.paint.Color.rgb(r, g, b, opacity);

        circle.setFill(fxColor);
        scene.setFill(fxColor);
    }

    public static void main(String[] args) throws AWTException {
        launch(args);

    }
}

```

## Process
![](https://i.imgur.com/Tv766gs.png)

```
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author manuel.gerber
 */
public class ProcessB {

    public static void main(String[] args) throws IOException, InterruptedException {
        ProcessBuilder pBuilder;
        pBuilder = new ProcessBuilder();
       //pBuilder.command("cmd","/C","net view");
       pBuilder.command("cmd","/C","dir");
       //pBuilder.command("cmd","/C","ver");

        Process process = pBuilder.start();
        Scanner s = new Scanner(process.getInputStream());
        while (s.hasNextLine()){
            System.out.println(s.nextLine());
        }
      
    }

}

```
## afficher "IPConfig"
![](https://i.imgur.com/DMMf60d.png)

```

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Ayoubbbb {
	public static void main(String[] args) throws IOException {
		Process p = Runtime.getRuntime().exec("ipconfig");

		// read the standard output of the command
		BufferedReader stdInput = new BufferedReader(new InputStreamReader(p
				.getInputStream()));

		System.out.println("Here is the standard output of the command:\n");

		int count = 0;
		String s;
		String result = "";
		while (!procDone(p)) {
			while ((s = stdInput.readLine()) != null) {
				count++;
				result = result + s + "\n";
			}
		}
		
		System.out.println("result:" + count + ": " + result);
		stdInput.close();
	}

	private static boolean procDone(Process p) {
		try {
			int v = p.exitValue();
			return true;
		} catch (IllegalThreadStateException e) {
			return false;
		}
	}
}
```
## Kernel BEEP

### class Kernel
```


import com.sun.jna.Native;


/**
 *
 * @author manuel.gerber
 */
public class Kernel32 {

    static {
        Native.register("kernel32.dll");
    }

    public static native boolean Beep(int freq, int dur);
}

```
### class main
```
public class Main {
    public static void main(String[] args) {
       
        Kernel32.Beep(500,3000);
       
    }
    
```

## Chrono

```
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package TimeProperties;


import static java.lang.Thread.sleep;


/**
 *
 * @author james.gremaud
 */
public class Chrono {
    private long t1, t2;
    private long LapTime;
    
    public long Start(){
        t1 = System.currentTimeMillis();
        System.out.println("time of t1 : " + t1);
        return t1;
    }
    
    public long Lap(){
        t2 = System.currentTimeMillis();
        System.out.println("time of t2 : " + t2);
        return t2;
    }
    
    public void reset(){
        t1 = 0;
        t2 = 0;
        
    }
    
    public long TimeLap(){
       LapTime = t2-t1;
       System.out.println("time of lap : " + LapTime);
       return LapTime;
    }
    
    public static void main(String[] args) throws InterruptedException  {
        Chrono c = new Chrono();
        c.Start();
       sleep(10000);
       c.Lap();
       c.TimeLap();
    }
}

```
Résultat: ![](https://i.imgur.com/zqhgICm.png)

## SystemDemo (current time in ms)

```
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package TimeProperties;

import java.lang.*;
/**
 *
 * @author james.gremaud
 */
public class SystemDemo {
    public static void main(String[] args) {

      // returns the current time in milliseconds
      System.out.print("Current Time in milliseconds = ");
      System.out.println(System.currentTimeMillis());
   }
}
```
Résultat : ![](https://i.imgur.com/ib1njkH.png)

## ImageDemo (camera ordi avec cercle dessiné)
```
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package hftm;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.videoio.VideoCapture;

/**
 *
 * @author james.gremaud
 */
public class ImageDemo {

 
    public static void main(String[] args) {
           System.loadLibrary (Core.NATIVE_LIBRARY_NAME); // Load native OpenCV lib
    //Mat img = Imgcodecs.imread("./hftm.jpg"); // Load an image

    //Imgproc.cvtColor (img, img, Imgproc.COLOR_BGR2GRAY); // Convert an image (filter)

    //Imgcodecs.imwrite ("./hftm2.jpg", img); // Save an image
VideoCapture capture = new VideoCapture(0); // open Video Capturing
    Mat mat = new Mat();

    while (capture.read (mat) 
        ) { // read the frames
Mat mat2 = new Mat();
        Imgproc.cvtColor(mat, mat2, Imgproc.COLORMAP_BONE); // filter
        Imgproc.circle(mat2, new Point(200, 200), 100, new Scalar(255, 200, 100), 4);
        HighGui.imshow("Capture", mat2); // Show result
        if (HighGui.waitKey(10) == 27) { // wait for escape-key
            System.exit(0);
        }
    }
    }
}

```
## Face Detection (celui du prof)
```
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package hftm;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;

/**
 *
 * @author james.gremaud
 */
class FaceDetectImg
{
    public static void main(String[] args)
    {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        CascadeClassifier faceDetector = new CascadeClassifier("./data/lbpcascade_frontalface.xml");
        //Mat image = Imgcodecs.imread("./data/lena.png");
        Mat image = Imgcodecs.imread("C:\\Users\\james.gremaud.MIC19-GREMAUDJ\\Pictures\\Nicoud_Maxime.jpg");
        MatOfRect faceDetections = new MatOfRect();        // MatOfRect is a special container class for Rect.

        faceDetector.detectMultiScale(image, faceDetections);
        
        System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
        for (Rect rect : faceDetections.toArray())
        {       // Draw a bounding box around each face.
            Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
        }

        String filename = "faceDetection.png";             // Save the visualized detection.
        System.out.println(String.format("Writing %s", filename));
        Imgcodecs.imwrite(filename, image);
    }
}

```

## USB Board 
 ```
public class K8055D {
    
    static
    {
    Native.register("K8055D.dll");
    }
    public static native int OpenDevice(int cardAddress);
    public static native void WriteAllDigital(int data);
    }
```

Main : 
```
public class Main {
    public static void main(String[] args) {
        K8055D.OpenDevice(0);
        K8055D.WriteAllDigital(80);
    }
}
```
# C++ Program
https://www.onlinegdb.com/ 
## hello word
```
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
}
```

## Swapp
```
#include <iostream>


using namespace std;


void swap(int &v1, int &v2)
{
int temp = v1;
v1 = v2;
v2 = temp;
};

int main(){

    int a=3;
    int b=4;

    cout <<"a:"<<a<<"/b:"<<b<<"\n";
    swap(a,b);
    cout <<"a:"<<a<<"/b:"<<b<<"\n";
    }
```

## valeur sensor
```
#include <iostream>
using namespace std;
class Sensor
{
public:
    int value;
    string unit;
    Sensor()
    {
        unit = "mm";
    }
    int getValue()
    {
        return value;
    }

};

int main()
{

    Sensor sensor;
    sensor.value = 34;
    cout << sensor.value << sensor.unit;

}
```