I've some code that launch an external program (VLC) do some stuff and close the external program (VLC).
The problem is that I'm unable to know if VLC has been opened or it's still loading, is there any way in Java to know if the window of VLC has been opened?
EDIT:
here is the code
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
public class myClass extends JDialog {
public Dimension dim;
public Process pr;
public myClass(final JFrame parent, String title, String message) {
super(parent, title, true);
try {
Runtime rt = Runtime.getRuntime();
pr = rt.exec("C:\\Programmi\\VideoLAN\\VLC\\vlc.exe dshow:// --dshow-vdev=\"TridVid Capture\" --dshow-video-input=1 -Ihttp");
Thread.sleep(500); //this is a workaround
}
catch (Exception e) {
System.out.println(e.toString());
}
if (parent != null) {
Toolkit toolkit = Toolkit.getDefaultToolkit ();
dim = toolkit.getScreenSize();
Dimension parentSize = parent.getSize();
Point p = parent.getLocation();
setBounds(p.x + parentSize.width / 4, p.y + parentSize.height / 4, dim.width, dim.height);
}
JPanel messagePane = new JPanel();
Image image = new ImageIcon("targa_prova.jpg").getImage();
ImagePanel panel = new ImagePanel(image.getScaledInstance(dim.width, dim.height, Image.SCALE_SMOOTH));
messagePane.add(new JLabel(message));
getContentPane().add(panel);
Timer timer = new Timer(5000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
pr.destroy();
parent.setVisible(false);
parent.dispose();
}
});
timer.setRepeats(false);
timer.start();
try {
Image backgroundImage = javax.imageio.ImageIO.read(new File("targa_prova.jpg"));
messagePane.paintComponents(backgroundImage.getGraphics());
}
catch (Exception e) {
System.out.println(e.toString());
}
setVisible(true);
}
public static void main(String[] a) {
new myClass(new JFrame(), "Configuring Cam", "Configurazione della telecamera in corso...\nAttendere.");
}
}
class ImagePanel extends JPanel {
private Image img;
public ImagePanel(String img) {
this(new ImageIcon(img).getImage());
}
public ImagePanel(Image img) {
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
The above code launch vlc, open a dialog that cover the vlc window, than close vlc and the dialog, now i get it with delays, but it's horrible and could not work on some slow computers.