Clojure + Seesaw: Почему не работает этот графический интерфейс? - PullRequest
0 голосов
/ 30 июня 2018

Я пытаюсь создать проект, как в примере с качелями Window-Builder , я создал проект с именем my-gui-project, скопировал код из src/window_builder/core.clj и src/window_builder/MyForm.java в мой проект и изменил строку 31, где говорится:

(let [form (identify (window_builder.MyForm.))]

в

(let [form (identify (my_gui_project.MyForm.))].

Затем я выполнил следующие команды: lein deps, lein compile и lein run -m my-gui-project.core, и он возвращает следующую ошибку:

Exception in thread "main" java.lang.ClassNotFoundException: my_gui_project.MyForm, compiling:(my_gui_project/core.clj:31:24)

Почему это происходит? Код точно такой же, я только что изменил имя папки.

Это полный код:

core.clj

(ns my-gui-project.core
  (:gen-class)
  (:use [seesaw.core])
  (:require [seesaw.selector :as selector]))

; This is the interesting part. Note that in MyPanel.java, the widgets we're
; interested in have their name set with setName().
(defn identify
  "Given a root widget, find all the named widgets and set their Seesaw :id
   so they can play nicely with select and everything."
  [root]
  (doseq [w (select root [:*])]
    (if-let [n (.getName w)]
      (selector/id-of! w (keyword n))))
  root)

(def states ["CA", "GA", "WA"])

(def defaults
  { :first-name "Laura"
    :last-name "Palmer"
    :street "123 Main St."
    :city "Twin Peaks"
    :zip "12345"
    :state "WA" })

; A helper to create an instance of the form, annotate it for Seesaw and do
; some other initialization.
(defn my-form
  []
  (let [form (identify (my_gui_project.MyForm.))]
    ; initialize the state combobox
    (config! (select form [:#state]) :model states)
    form))

; Now we just create the panel, initialize it to the defaults above with
; seesaw.core/value! and show it in a dialog. Note how, besides setting the
; names of the widgets, the code in MyForm.java is strictly for layout. All
; behavior, etc is done in Clojure.
(defn -main [& args]
  (invoke-later
    (let [form  (value! (my-form) defaults)
          result (-> (dialog :content form :option-type :ok-cancel) pack! show!)]
      (if (= :success result)
        (println "User entered: " (value form))
        (println "User canceled")))))

project.clj

(defproject my-gui-project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [seesaw "LATEST"]]
  :main ^:skip-aot my-gui-project.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

Ответы [ 2 ]

0 голосов
/ 01 июля 2018

В ходе тестирования я обнаружил, что внутри MyForm.java также была ссылка на название проекта. После изменения названия внутри MyForm.java все работает.

Редактировать : На что ссылается @Carcigenicate в сообщении (теперь удаленном), также необходимо добавить :java-source-paths ["src"] в project.clj

Оригинал MyForm.java:

package window_builder;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JComboBox;

public class MyForm extends JPanel {
  private JTextField firstName;
  private JTextField lastName;
  private JLabel lblStreet;
  private JTextField textField;
  private JLabel lblCity;
  private JTextField textField_1;
  private JLabel lblState;
  private JComboBox comboBox;
  private JLabel lblState_1;
  private JTextField textField_2;

  /**
   * Create the panel.
   */
  public MyForm() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[]{72, 134, 0, 0, 0, 0, 0};
    gridBagLayout.rowHeights = new int[]{28, 28, 0, 0};
    gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
    gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
    setLayout(gridBagLayout);

    JLabel lblFirstName = new JLabel("First Name:");
    GridBagConstraints gbc_lblFirstName = new GridBagConstraints();
    gbc_lblFirstName.anchor = GridBagConstraints.WEST;
    gbc_lblFirstName.insets = new Insets(0, 0, 5, 5);
    gbc_lblFirstName.gridx = 0;
    gbc_lblFirstName.gridy = 0;
    add(lblFirstName, gbc_lblFirstName);

    firstName = new JTextField();
    firstName.setName("first-name");
    firstName.setColumns(10);
    GridBagConstraints gbc_firstName = new GridBagConstraints();
    gbc_firstName.gridwidth = 2;
    gbc_firstName.anchor = GridBagConstraints.NORTH;
    gbc_firstName.fill = GridBagConstraints.HORIZONTAL;
    gbc_firstName.insets = new Insets(0, 0, 5, 5);
    gbc_firstName.gridx = 1;
    gbc_firstName.gridy = 0;
    add(firstName, gbc_firstName);

    JLabel lblLastName = new JLabel("Last Name:");
    GridBagConstraints gbc_lblLastName = new GridBagConstraints();
    gbc_lblLastName.anchor = GridBagConstraints.WEST;
    gbc_lblLastName.insets = new Insets(0, 0, 5, 5);
    gbc_lblLastName.gridx = 3;
    gbc_lblLastName.gridy = 0;
    add(lblLastName, gbc_lblLastName);

    lastName = new JTextField();
    lastName.setName("last-name");
    lastName.setColumns(10);
    GridBagConstraints gbc_lastName = new GridBagConstraints();
    gbc_lastName.gridwidth = 2;
    gbc_lastName.fill = GridBagConstraints.HORIZONTAL;
    gbc_lastName.insets = new Insets(0, 0, 5, 0);
    gbc_lastName.anchor = GridBagConstraints.NORTH;
    gbc_lastName.gridx = 4;
    gbc_lastName.gridy = 0;
    add(lastName, gbc_lastName);

    lblStreet = new JLabel("Street:");
    GridBagConstraints gbc_lblStreet = new GridBagConstraints();
    gbc_lblStreet.anchor = GridBagConstraints.EAST;
    gbc_lblStreet.insets = new Insets(0, 0, 5, 5);
    gbc_lblStreet.gridx = 0;
    gbc_lblStreet.gridy = 1;
    add(lblStreet, gbc_lblStreet);

    textField = new JTextField();
    textField.setName("street");
    GridBagConstraints gbc_textField = new GridBagConstraints();
    gbc_textField.gridwidth = 5;
    gbc_textField.insets = new Insets(0, 0, 5, 0);
    gbc_textField.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField.gridx = 1;
    gbc_textField.gridy = 1;
    add(textField, gbc_textField);
    textField.setColumns(10);

    lblCity = new JLabel("City:");
    GridBagConstraints gbc_lblCity = new GridBagConstraints();
    gbc_lblCity.anchor = GridBagConstraints.EAST;
    gbc_lblCity.insets = new Insets(0, 0, 0, 5);
    gbc_lblCity.gridx = 0;
    gbc_lblCity.gridy = 2;
    add(lblCity, gbc_lblCity);

    textField_1 = new JTextField();
    textField_1.setName("city");
    GridBagConstraints gbc_textField_1 = new GridBagConstraints();
    gbc_textField_1.insets = new Insets(0, 0, 0, 5);
    gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_1.gridx = 1;
    gbc_textField_1.gridy = 2;
    add(textField_1, gbc_textField_1);
    textField_1.setColumns(10);

    lblState_1 = new JLabel("State:");
    GridBagConstraints gbc_lblState_1 = new GridBagConstraints();
    gbc_lblState_1.insets = new Insets(0, 0, 0, 5);
    gbc_lblState_1.gridx = 2;
    gbc_lblState_1.gridy = 2;
    add(lblState_1, gbc_lblState_1);

    comboBox = new JComboBox();
    comboBox.setName("state");
    GridBagConstraints gbc_comboBox = new GridBagConstraints();
    gbc_comboBox.insets = new Insets(0, 0, 0, 5);
    gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox.gridx = 3;
    gbc_comboBox.gridy = 2;
    add(comboBox, gbc_comboBox);

    lblState = new JLabel("Zip:");
    GridBagConstraints gbc_lblState = new GridBagConstraints();
    gbc_lblState.anchor = GridBagConstraints.EAST;
    gbc_lblState.insets = new Insets(0, 0, 0, 5);
    gbc_lblState.gridx = 4;
    gbc_lblState.gridy = 2;
    add(lblState, gbc_lblState);

    textField_2 = new JTextField();
    textField_2.setName("zip");
    GridBagConstraints gbc_textField_2 = new GridBagConstraints();
    gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_2.gridx = 5;
    gbc_textField_2.gridy = 2;
    add(textField_2, gbc_textField_2);
    textField_2.setColumns(10);

  }
}

Исправлено MyForm.java:

package gui_example_application;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JComboBox;

public class MyForm extends JPanel {
  private JTextField firstName;
  private JTextField lastName;
  private JLabel lblStreet;
  private JTextField textField;
  private JLabel lblCity;
  private JTextField textField_1;
  private JLabel lblState;
  private JComboBox comboBox;
  private JLabel lblState_1;
  private JTextField textField_2;

  /**
   * Create the panel.
   */
  public MyForm() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[]{72, 134, 0, 0, 0, 0, 0};
    gridBagLayout.rowHeights = new int[]{28, 28, 0, 0};
    gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
    gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
    setLayout(gridBagLayout);

    JLabel lblFirstName = new JLabel("First Name:");
    GridBagConstraints gbc_lblFirstName = new GridBagConstraints();
    gbc_lblFirstName.anchor = GridBagConstraints.WEST;
    gbc_lblFirstName.insets = new Insets(0, 0, 5, 5);
    gbc_lblFirstName.gridx = 0;
    gbc_lblFirstName.gridy = 0;
    add(lblFirstName, gbc_lblFirstName);

    firstName = new JTextField();
    firstName.setName("first-name");
    firstName.setColumns(10);
    GridBagConstraints gbc_firstName = new GridBagConstraints();
    gbc_firstName.gridwidth = 2;
    gbc_firstName.anchor = GridBagConstraints.NORTH;
    gbc_firstName.fill = GridBagConstraints.HORIZONTAL;
    gbc_firstName.insets = new Insets(0, 0, 5, 5);
    gbc_firstName.gridx = 1;
    gbc_firstName.gridy = 0;
    add(firstName, gbc_firstName);

    JLabel lblLastName = new JLabel("Last Name:");
    GridBagConstraints gbc_lblLastName = new GridBagConstraints();
    gbc_lblLastName.anchor = GridBagConstraints.WEST;
    gbc_lblLastName.insets = new Insets(0, 0, 5, 5);
    gbc_lblLastName.gridx = 3;
    gbc_lblLastName.gridy = 0;
    add(lblLastName, gbc_lblLastName);

    lastName = new JTextField();
    lastName.setName("last-name");
    lastName.setColumns(10);
    GridBagConstraints gbc_lastName = new GridBagConstraints();
    gbc_lastName.gridwidth = 2;
    gbc_lastName.fill = GridBagConstraints.HORIZONTAL;
    gbc_lastName.insets = new Insets(0, 0, 5, 0);
    gbc_lastName.anchor = GridBagConstraints.NORTH;
    gbc_lastName.gridx = 4;
    gbc_lastName.gridy = 0;
    add(lastName, gbc_lastName);

    lblStreet = new JLabel("Street:");
    GridBagConstraints gbc_lblStreet = new GridBagConstraints();
    gbc_lblStreet.anchor = GridBagConstraints.EAST;
    gbc_lblStreet.insets = new Insets(0, 0, 5, 5);
    gbc_lblStreet.gridx = 0;
    gbc_lblStreet.gridy = 1;
    add(lblStreet, gbc_lblStreet);

    textField = new JTextField();
    textField.setName("street");
    GridBagConstraints gbc_textField = new GridBagConstraints();
    gbc_textField.gridwidth = 5;
    gbc_textField.insets = new Insets(0, 0, 5, 0);
    gbc_textField.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField.gridx = 1;
    gbc_textField.gridy = 1;
    add(textField, gbc_textField);
    textField.setColumns(10);

    lblCity = new JLabel("City:");
    GridBagConstraints gbc_lblCity = new GridBagConstraints();
    gbc_lblCity.anchor = GridBagConstraints.EAST;
    gbc_lblCity.insets = new Insets(0, 0, 0, 5);
    gbc_lblCity.gridx = 0;
    gbc_lblCity.gridy = 2;
    add(lblCity, gbc_lblCity);

    textField_1 = new JTextField();
    textField_1.setName("city");
    GridBagConstraints gbc_textField_1 = new GridBagConstraints();
    gbc_textField_1.insets = new Insets(0, 0, 0, 5);
    gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_1.gridx = 1;
    gbc_textField_1.gridy = 2;
    add(textField_1, gbc_textField_1);
    textField_1.setColumns(10);

    lblState_1 = new JLabel("State:");
    GridBagConstraints gbc_lblState_1 = new GridBagConstraints();
    gbc_lblState_1.insets = new Insets(0, 0, 0, 5);
    gbc_lblState_1.gridx = 2;
    gbc_lblState_1.gridy = 2;
    add(lblState_1, gbc_lblState_1);

    comboBox = new JComboBox();
    comboBox.setName("state");
    GridBagConstraints gbc_comboBox = new GridBagConstraints();
    gbc_comboBox.insets = new Insets(0, 0, 0, 5);
    gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox.gridx = 3;
    gbc_comboBox.gridy = 2;
    add(comboBox, gbc_comboBox);

    lblState = new JLabel("Zip:");
    GridBagConstraints gbc_lblState = new GridBagConstraints();
    gbc_lblState.anchor = GridBagConstraints.EAST;
    gbc_lblState.insets = new Insets(0, 0, 0, 5);
    gbc_lblState.gridx = 4;
    gbc_lblState.gridy = 2;
    add(lblState, gbc_lblState);

    textField_2 = new JTextField();
    textField_2.setName("zip");
    GridBagConstraints gbc_textField_2 = new GridBagConstraints();
    gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_2.gridx = 5;
    gbc_textField_2.gridy = 2;
    add(textField_2, gbc_textField_2);
    textField_2.setColumns(10);

  }
}
0 голосов
/ 01 июля 2018

вам, вероятно, также необходимо переименовать каталог window_builder, чтобы соответствовать изменению имени. и измените имена пакетов в любых файлах Java.

это соответствует шаблону именования проекта в Clojure для directory_name / namespace.clj с переключателем -s на _'s

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...