Question

Quand j'apporter mon application à un autre ordinateur les deux boutons qui devraient ouvrir soit un navigateur de fichiers, ou de prendre dans un chemin de fichier pour ouvrir un fichier à la fois ne fonctionnent pas. Je ne comprends pas pourquoi.

Il fonctionne parfaitement bien si je compile dans un délai Netbeans.

package maxsublistsum;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.lang.Exception;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import javafx.scene.control.TextBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollView;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.paint.Color;
import javafx.scene.effect.DropShadow;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import java.io.File;
import java.io.FileNotFoundException;
/**
 * @author
 */

public class Main{
    var originalList: Integer[];
    var maxSublistSum = subListCalculator{};


    public-read def Start_Index: Label = Label {
        width: 27.0
        height: 27.0
        text: "Start"
    }

    public-read def StartIndexText: TextBox = TextBox {
        text: bind maxSublistSum.maxStartIndex.toString()
        editable: false
    }

    public-read def StartIndexBox: HBox = HBox {
        layoutX: 251.0
        layoutY: 102.0
        width: 140.0
        height: 21.0
        content: [ Start_Index, StartIndexText, ]
        spacing: 4.0
    }

    public-read def End_Index: Label = Label {
        width: 30.0
        height: 27.0
        text: "End"
    }

    public-read def EndIndexText: TextBox = TextBox {
        text: bind maxSublistSum.maxEndIndex.toString()
        editable: false
    }

    public-read def EndIndexBox: HBox = HBox {
        layoutX: 252.0
        layoutY: 157.0
        width: 121.0
        height: 21.0
        content: [ End_Index, EndIndexText, ]
        spacing: 10.0
    }

    public-read def Sum: Label = Label {
        width: 27.0
        height: 27.0
        text: "Sum"
    }

    public-read def SumText: TextBox = TextBox {
        text: bind maxSublistSum.maxSum.toString()
        editable: false
    }

    public-read def SumBox: HBox = HBox {
        layoutX: 258.0
        layoutY: 45.0
        width: 172.0
        height: 21.0
        content: [ Sum, SumText, ]
        spacing: 6.0
    }

    public-read def results_box: VBox = VBox {
        layoutX: 185.0
        layoutY: 140.0
        width: 120.0
        height: 80.0
        content: [ StartIndexBox, EndIndexBox, SumBox, ]
        spacing: 6.0
    }

    public-read def sublist_view: ListView = ListView {
        width: 150.0
        height: 170.0
        items: bind maxSublistSum.maxSubList
    }

    public-read def sublist_scroll: ScrollView = ScrollView {
        layoutX: 320.0
        layoutY: 140.0
        width: 150.0
        height: 170.0
        node: sublist_view
        hbarPolicy: javafx.scene.control.ScrollBarPolicy.NEVER
        vbarPolicy: javafx.scene.control.ScrollBarPolicy.ALWAYS
    }

    public-read def file_textBox: TextBox = TextBox{
        layoutX: 100.0
        layoutY: 98.0
        width: 160.0
        editable: true
        text: "Enter path to file here:"
        onMouseClicked: function(e: MouseEvent): Void {
            file_textBox.text = "";
        }

    }

    public-read def calculate_Button: Button = Button {
        layoutX: 320.0
        layoutY: 98.0
        text: "Calculate Max Sub List Sum"
        onMouseClicked: function(e: MouseEvent): Void{
            try {readFile(new File(file_textBox.text))}
            catch (exception:FileNotFoundException) {
                Stage{
                title: "File Error!"
                scene: Scene {
                    width: 175.0
                    height: 40.0
                    content: Label {
                        text:"File Not Found Error!"
                        font: TitleFont
                        }
                    }
                }
            }
        }


    }

    public-read def select_file: Button = Button {
        layoutX: 10.0
        layoutY: 98.0
        text: "File Browser"
        onMouseClicked: function(e: MouseEvent): Void {
            select_fileAction();
    }

    }

    public-read def original_listView: ListView = ListView {
        width: 150.0
        height: 170.0
        items: bind listView2Items
    }

    public-read def original_scroll: ScrollView = ScrollView {
        layoutX: 10.0
        layoutY: 140.0
        width: 150.0
        height: 170.0
        node: original_listView
        hbarPolicy: javafx.scene.control.ScrollBarPolicy.NEVER
    }

    public-read def Original_List: Label = Label {
        layoutX: 50.0
        layoutY: 118.0
        width: 60.0
        text: "Original List"
    }

    public-read def Sub_List: Label = Label {
        layoutX: 370.0
        layoutY: 118.0
        width: 40.0
        text: "Sub-List"
    }

    public-read def Help_Text: Text = Text {
        layoutX: 90.0
        layoutY: 75.0
        wrappingWidth: 300.0
        x: 0.0
        content: "This program accepts files with .txt and .dat file extensions "
        "where the intergers of a list are provided on seperate lines."
    }

    public-read def TitleFont: Font = Font {
        size: 22.0
        embolden: true
    }

    public-read def blue: Color = Color {
        red: 0.4
        green: 0.6
        blue: 1.0
    }

    public-read def dropShadow: DropShadow = DropShadow {
        color: blue
        width: 10.0
        height: 10.0
    }

    public-read def Title: Label = Label {
        layoutX: 20.0
        layoutY: 20.0
        width: 440.0
        effect: dropShadow
        text: "Determine the Sub-List with the Maximum Sum!"
        font: TitleFont
    }

    public-read def My_Name: Label = Label {
        layoutX: 165.0
        layoutY: 261.0
        effect: dropShadow
        text: "Author"
        font: TitleFont
    }

    public-read def scene: Scene = Scene {
        width: 480.0
        height: 320.0
        content: getDesignRootNodes ()
    }

    public-read def currentState: org.netbeans.javafx.design.DesignState = 
        org.netbeans.javafx.design.DesignState {
    }

    public function getDesignRootNodes (): Node[] {
        [ calculate_Button, file_textBox, results_box, sublist_scroll, select_file, 
        original_scroll, Original_List, Sub_List, Help_Text, My_Name, Title, ]
    }

    public function getDesignScene (): Scene {
        scene
    }

    var listView2Items: Object[] = bind originalList;

    function select_fileAction(): Void {
        var extensions = [".txt", ".dat"];
        var fileChooser = new JFileChooser();
        fileChooser.addChoosableFileFilter(
            FileFilter{
                override function getDescription(){"Data {extensions.toString()}"}
                override function accept(file:File){
                    if (file.isDirectory()){return true}
                    var name = file.getName().toLowerCase();
                    for (extension in extensions){
                        if (name.endsWith(extension)){
                            return true;
                        }
                    }

                    return false
                }

            });
        originalList = [];
        var returnVal = fileChooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION){};
        readFile(fileChooser.getSelectedFile());
    }
    function readFile(file:File): Void {

        var reader = new BufferedReader(
                            new FileReader (
                                    file ) );
        while (true){
            var line = reader.readLine();
            if (line == null){break}
            try {
                var currentInteger: Integer = java.lang.Integer.parseInt(line);
                insert currentInteger into originalList;
            }
            catch (e:Exception){
                Stage{
                title: "File Error!"
                scene: Scene {
                    width: 150.0
                    height: 40.0
                    content: Label {
                        text:"File Input Error!"
                        font: TitleFont
                        }
                    }
                }
                originalList = [];
                break;
            }
        }
        maxSublistSum.updateList(originalList);
    }
}

function run (): Void {
    var design = Main {};

    javafx.stage.Stage {

        title: "Main"
        scene: design.getDesignScene ()
    }
}

Et l'algorithme:

public class subListCalculator {

public-read var maxStartIndex: Integer = -1;
public-read var maxEndIndex: Integer = -1;
public-read var maxSum: Integer = 0;
public-read var maxSubList: Integer[];
var currentSubList: Integer[];
var currentSum: Integer = 0;
var currentStartIndex: Integer = -1;
public var list: Integer[];


function resetValues(): Void{
    maxStartIndex = -1;
    maxEndIndex = -1;
    maxSum = 0;
    currentSubList = [];
    maxSubList = [];
    currentSum = 0;
    currentStartIndex = -1;
}

public function updateList (newList:Integer[]): Void{
    resetValues();
    list = newList;
    var lastIndex = list.size() - 1;

    for (i in [0..lastIndex]) {
        var currentValue = list[i];

        if (currentSum > 0) {
            currentSum = currentSum + currentValue;
            if (currentStartIndex == -1) { currentStartIndex = i }
            insert currentValue into currentSubList;
        }else {
            currentSum = currentValue;
            currentStartIndex = i;
            currentSubList = [currentValue];
        }
        if (currentSum > maxSum){
            maxSum = currentSum;
            maxEndIndex = i;
            maxStartIndex = currentStartIndex;
            maxSubList = currentSubList
        }
    }
}

}//End of class
Était-ce utile?

La solution

  

Il fonctionne parfaitement bien si je compile dans un délai Netbeans.

En règle générale, NetBeans met des copies des bibliothèques requises à côté de votre JAR dans un dossier nommé dist. Vous pouvez vérifier que vous y compris les autres fichiers JAR nécessaires lorsque vous copiez des choses ailleurs.

Addendum: Il peut y avoir quelque chose d'utile dans l'article Déploiement d'applications JavaFX . En outre, certains lanceurs JWS anciens ne fonctionnent pas correctement support wildcards-chemin de classe .

Autres conseils

Je faisais la même question et ne pouvait pas trouver un moyen de résoudre ce problème, jusqu'à ce que je pensais à ce qui a été dit dans la réponse précédente au sujet des bibliothèques ne sont pas inclus.

Je ne comptait que 5 bibliothèques pour commencer:

mysql-connector-java.5.1.34-bin.jar EclipseLink (3 stuff- Bibliothèques) 1.8 JDK (par défaut)

je suis entré dans Java 1.8 et une scie qui JavaFX est compris dans la bibliothèque, mais je décide d'ajouter JavaFX pour voir ce qui se passerait de toute façon.

  1. Cliquez droit sur le projet et cliquez sur Propriétés.
  2. Cliquez sur l'élément de menu Bibliothèques, sur le côté gauche.
  3. Cliquez sur Ajouter Jar / Dossier
  4. Dans le fichier chooser, je suis allé dans mon java actuel lieu JDK. Pour moi, il était, C: \ Program Files \ Java \ jdk1.8.0_40. Cliquez ensuite sur le javafx-src.zip comme la bibliothèque à ajouter. Cliquez sur Ouvrir, puis cliquez sur OK dans le menu propriétés.
  5. Après cela, Run 'Clean and Build' Projet.
  6. Puis emballé le programme Image uniquement. Où vous devez copier tout le répertoire de l'application ou vous devez faire votre propre programme d'installation pour déplacer le dossier, puis placer un raccourci vers l'application.

Après avoir été emballé est allé à l'autre ordinateur et essayé, travaillé comme un charme !!!

J'espère que cela aide quelqu'un.

Bonne programmation!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top