samedi 9 janvier 2016

Java Programming : Problems with starting .exe Files

I want to programm an Installer, in this Installer you can choose between 10 Files or Programms you want to install by JCheckBoxes and the paths to these files have to readout of a Textfile. So in the Textfile there are 10 paths every line a new Path for a new Programm or Installationfile / .exe. When I try to run the Origin and Opera exe it works but not on the other 8 files :(( I get everytime an Exception when I try to start a Steam.exe or something like that. When I try to change the Path for the Opera-Checkbox from the Opera-Path to the Steam-Path it doesn´t work too. But all .exe Files are in the same Folder all! What can I check or change in my code to make them working? Don´t be surprised that there are only the if-statement for the Opera and Origin-Checkboxes, I even tried to make the code for the other CheckBoxes but it even doesn´t work :(

The Installer GUI

The Folder including the exe Files, the Textfile

Here my Sourcecode:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import javax.swing.JCheckBox;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
import javax.swing.JOptionPane;
import javax.swing.DefaultListModel;
import javax.swing.UIManager;
import java.awt.Color;
public class Installer extends JFrame {
private JPanel contentPane;
String path1;
String path2;
String path3;
String path4;
String path5;
String path6;
String path7;
String path8;
String path9;
String path10;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (Throwable e) {
        e.printStackTrace();
    }

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Installer frame = new Installer();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Installer() {
    setBackground(Color.CYAN);

    try
    {
    FileReader fr = new FileReader("C:/Users/The5thBluesky/Desktop/Path.txt");
    BufferedReader br = new BufferedReader(fr);

    path1 = br.readLine();
    System.out.println(path1);
    path2 = br.readLine();
    System.out.println(path2);
    path3 = br.readLine();
    System.out.println(path3);
    path4 = br.readLine();
    System.out.println(path4);
    path5 = br.readLine();
    System.out.println(path5);
    path6 = br.readLine();
    System.out.println(path6);
    path7 = br.readLine();
    System.out.println(path7);
    path8 = br.readLine();
    System.out.println(path8);
    path9 = br.readLine();
    System.out.println(path9);
    path10 = br.readLine();
    System.out.println(path10);
    br.close();
    }
    catch (IOException ex)
    {
        JOptionPane.showMessageDialog(null, "Das ging wohl schief");
    }









    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 600, 564);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(245, 255, 250));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JTextPane txtpnDiesesProgrammWird = new JTextPane();
    txtpnDiesesProgrammWird.setEditable(false);
    txtpnDiesesProgrammWird.setText("Dieses Programm wird dazu verwendet, um nach einer Auswahl an Programmen, diese zu installieren. W\u00E4hlen sie dazu unten einfach die Programme aus die sie installieren m\u00F6chten und klicken sie dann auf INSTALL.");
    txtpnDiesesProgrammWird.setBounds(37, 12, 460, 58);
    contentPane.add(txtpnDiesesProgrammWird);

    JLabel lblOperaInstall = new JLabel("Opera wird jetzt installiert");
    lblOperaInstall.setBounds(236, 302, 199, 14);
    contentPane.add(lblOperaInstall);

    JLabel lblOriginInstall = new JLabel("Origin wird jetzt installiert");
    lblOriginInstall.setBounds(236, 337, 147, 14);
    contentPane.add(lblOriginInstall);

    JCheckBox checkbxOrigin = new JCheckBox("Origin\r\n");
    checkbxOrigin.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (checkbxOrigin.isSelected()){
                lblOriginInstall.setVisible(true);
                }
                else
                {
                lblOriginInstall.setVisible(false);
                }
        }
    });
    checkbxOrigin.setBounds(37, 333, 97, 23);
    contentPane.add(checkbxOrigin);

    JCheckBox checkbxOpera = new JCheckBox("Opera");
    checkbxOpera.setForeground(new Color(0, 0, 0));
    checkbxOpera.setBackground(new Color(0, 0, 0));
    checkbxOpera.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (checkbxOpera.isSelected()){
            lblOperaInstall.setVisible(true);
            }
            else
            {
            lblOperaInstall.setVisible(false);
            }
        }
    });
    checkbxOpera.setBounds(37, 298, 97, 23);
    contentPane.add(checkbxOpera);

    JCheckBox checkbxArduino = new JCheckBox("Arduino IDE");
    checkbxArduino.setBounds(37, 268, 104, 18);
    contentPane.add(checkbxArduino);

    JCheckBox checkbxCCleaner = new JCheckBox("CCleaner");
    checkbxCCleaner.setBounds(37, 238, 104, 18);
    contentPane.add(checkbxCCleaner);

    JCheckBox checkbxDevC = new JCheckBox("Dev- C++\r\n");
    checkbxDevC.setBounds(37, 208, 104, 18);
    contentPane.add(checkbxDevC);

    JCheckBox checkbxGeogebra = new JCheckBox("GeoGebra");
    checkbxGeogebra.setBounds(37, 178, 104, 18);
    contentPane.add(checkbxGeogebra);

    JCheckBox checkbxMicrosoft = new JCheckBox("Microsoft Office 365");
    checkbxMicrosoft.setBounds(37, 148, 136, 18);
    contentPane.add(checkbxMicrosoft);

    JCheckBox checkbxSteam = new JCheckBox("Steam");
    checkbxSteam.setBounds(37, 118, 104, 18);
    contentPane.add(checkbxSteam);

    JCheckBox checkbxTeamspeak = new JCheckBox("Teamspeak");
    checkbxTeamspeak.setBounds(37, 368, 104, 18);
    contentPane.add(checkbxTeamspeak);

    JCheckBox checkbxWinRAR = new JCheckBox("WinRAR");
    checkbxWinRAR.setBounds(37, 398, 104, 18);
    contentPane.add(checkbxWinRAR);

    JLabel lblTeamspeakWirdJetzt = new JLabel("TeamSpeak wird jetzt installiert");
    lblTeamspeakWirdJetzt.setBounds(236, 369, 199, 16);
    contentPane.add(lblTeamspeakWirdJetzt);

    JLabel lblWinrarWirdJetzt = new JLabel("WinRAR wird jetzt installiert");
    lblWinrarWirdJetzt.setBounds(236, 399, 181, 16);
    contentPane.add(lblWinrarWirdJetzt);

    JLabel lblArduinoIdeWird = new JLabel("Arduino IDE wird jetzt installiert");
    lblArduinoIdeWird.setBounds(236, 268, 168, 16);
    contentPane.add(lblArduinoIdeWird);

    JLabel lblCcleanerWirdJetzt = new JLabel("CCleaner wird jetzt installiert");
    lblCcleanerWirdJetzt.setBounds(236, 239, 199, 16);
    contentPane.add(lblCcleanerWirdJetzt);

    JLabel lblDevcWirdJetzt = new JLabel("Dev-C++ wird jetzt installiert");
    lblDevcWirdJetzt.setBounds(236, 209, 219, 16);
    contentPane.add(lblDevcWirdJetzt);

    JLabel lblGeogebraWirdJetzt = new JLabel("GeoGebra wird jetzt installiert");
    lblGeogebraWirdJetzt.setBounds(236, 179, 219, 16);
    contentPane.add(lblGeogebraWirdJetzt);

    JLabel lblMicrosoftOffice = new JLabel("Microsoft Office 365 wird jetzt installiert");
    lblMicrosoftOffice.setBounds(236, 149, 273, 16);
    contentPane.add(lblMicrosoftOffice);

    JLabel lblSteamWirdJetzt = new JLabel("Steam wird jetzt installiert");
    lblSteamWirdJetzt.setBounds(236, 119, 168, 16);
    contentPane.add(lblSteamWirdJetzt);

    JButton btnNewButton = new JButton("INSTALL");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            if (checkbxOpera.isSelected() && checkbxOrigin.isSelected())
            {
                try 
                {
                    Runtime rOp = Runtime.getRuntime();
                    Process rt = rOp.exec(path5);
                    rt.waitFor();
                    JOptionPane.showMessageDialog(null, "Opera wurde erfolgreich installiert");
                    Runtime rOr = Runtime.getRuntime();
                    Process rp = rOr.exec(path6);
                    rp.waitFor();
                    JOptionPane.showMessageDialog(null, "OK");
                } 
                catch( IOException | InterruptedException ex) 
                {
                    JOptionPane.showMessageDialog(null, "Ein Fehler ist aufgetreten! Möglicherweise " + 
                    "existiert die Datei nicht, oder der Pfad ist falsch!");
                }
            }
            else if (checkbxOrigin.isSelected())
            {
                try 
                {
                    Runtime rOr = Runtime.getRuntime();
                    Process rp = rOr.exec(path6);
                    rp.waitFor();
                    JOptionPane.showMessageDialog(null, "OK");
                } 
                catch( IOException | InterruptedException ex) 
                {
                    JOptionPane.showMessageDialog(null, "Ein Fehler ist aufgetreten! Möglicherweise " + 
                    "existiert die Datei nicht, oder der Pfad ist falsch!");
                }
            }
            else if (checkbxOpera.isSelected())
            {
                try 
                {
                    Runtime rOp = Runtime.getRuntime();
                    Process rt = rOp.exec(path5);
                    rt.waitFor();
                    JOptionPane.showMessageDialog(null, "Opera wurde erfolgreich installiert");
                } 
                catch( IOException | InterruptedException ex) 
                {
                    JOptionPane.showMessageDialog(null, "Ein Fehler ist aufgetreten! Möglicherweise " + 
                    "existiert die Datei nicht, oder der Pfad ist falsch!");
                }
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Kein Programm wurde ausgewählt");
            }

        }

    });
    btnNewButton.setBounds(414, 465, 147, 39);
    contentPane.add(btnNewButton);



}

}

Aucun commentaire:

Enregistrer un commentaire