Bonjour tout le monde
Je n'arrive pas à ouvrire et femer le lecteur cd, j'ai deja utiliser ce genre de code sans eclipse et il fonctionne.
J'ai bien importer les fichier .bat necessaire et le fichier dll dans le package du projet.
Voici les class
class Device
Controle menu
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 package Composant; import javax.swing.JOptionPane; public class Device { private final static int DRIVE_UNKNOWN = 0; private final static int DRIVE_NO_ROOT_DIR = 1; private final static int DRIVE_REMOVABLE = 2; private final static int DRIVE_FIXED = 3; private final static int DRIVE_REMOTE = 4; private final static int DRIVE_CDROM = 5; private final static int DRIVE_RAMDISK = 6; private native static int getDriveType (String drive); private native static int getLogicalDrives (); private native static void sendCommand (String drive, boolean bOpen); public static String [] getCRDOMDVDROMDrivesNames () { String [] result = new String [2]; result [0] = null; result [1] = null; int mask = getLogicalDrives (); int index = 0; for (int i=0; i<32; i++) { if ((mask & (1 << i)) != 0) { char c = (char)('A' + i); String drive = "" + c + ":"; if (getDriveType (drive) == DRIVE_CDROM) { result [index++] = drive; if (index == 2) break; } } } return result; } public static void open (String drive) { sendCommand (drive, true); return; } public static void close (String drive) { sendCommand (drive, false); return; } static { String os = System.getProperty("os.name").toLowerCase (); if (os.startsWith ("windows")) { System.loadLibrary ("Device"); } else { JOptionPane.showMessageDialog(null, "Erreur", "Ce programme ne peut fonctionner que sur Windows(R)", JOptionPane.ERROR_MESSAGE); System.exit (1); } } }
Voici les erreur dans eclipse.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 cdr = new JMenu("Disque"); openCD = new JMenuItem("Ouvrir lecteur CD/DVD"); openCD.setMnemonic('o'); openCD.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String drive=""; Device.open (drive); } }); cdr.add(openCD); closCD = new JMenuItem("Fermer lecteur CD/DVD"); closCD.setMnemonic('f'); closCD.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String drive= ""; Device.close (drive); } });
Je ne vois pas pourquoi qu'eclipse lance les erreur là, j'ai déja utiliser ce code quand je programmer en java en bloc note.in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no Device in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Composant.Device.<clinit>(Device.java:60)
at Composant.Menu$3.actionPerformed(Menu.java:103)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Je crois que je n'ais pas encore bien compris l'utilisation de eclipse!!
A+
Partager