Jedno od mogućih rješenja, koje ti se možda i neće svidjeti, je da napraviš C# konzolnu aplikaciju.
Code:
using System;
using System.Text;
using System.Runtime.InteropServices;
class Program
{
[DllImport("winmm.dll")]
public static extern int mciSendStringA(string lpszCommand,
StringBuilder lpszReturnString, int cchReturn, IntPtr hwndCallback);
static void Main(string[] args)
{
if (args.Length == 1)
{
if (args[0] == "open")
mciSendStringA("set cdaudio door open", null, 0, IntPtr.Zero);
else if (args[0] == "close")
mciSendStringA("set cdaudio door closed wait", null, 0, IntPtr.Zero);
else
{
Console.WriteLine("Using:");
Console.WriteLine("jcd open");
Console.WriteLine("jcd close");
}
}
else
{
Console.WriteLine("Using:");
Console.WriteLine("jcd open");
Console.WriteLine("jcd close");
}
}
}
Snimiš kao jcd.cs
i kompajliraš sa csc jcd.cs
U istom folderu napraviš java aplikaciju. Recimo:
Code:
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class CD extends JFrame implements ActionListener
{
public CD()
{
JButton open = new JButton();
open.setText("Open");
open.addActionListener(this);
JButton close = new JButton();
close.setText("Close");
close.addActionListener(this);
this.setLayout(new FlowLayout());
this.getContentPane().add(open);
this.getContentPane().add(close);
this.setSize(300,70);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Open/Close CD/DVD devices.");
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getActionCommand() == "Open")
{
String s = "jcd open";
Runtime.getRuntime().exec(s);
}else if(ae.getActionCommand() == "Close")
{
String s = "jcd close";
Runtime.getRuntime().exec(s);
}
}
catch(java.io.IOException e)
{
}
}
public static void main(String[] args)
{
CD cd = new CD();
cd.setVisible(true);
}
}
i to je to.
Pozdrav,
Goran