Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将ActionListener添加到控制器(MVC)中的swixml不工作_Java_Swing_Model View Controller_Swixml - Fatal编程技术网

Java 将ActionListener添加到控制器(MVC)中的swixml不工作

Java 将ActionListener添加到控制器(MVC)中的swixml不工作,java,swing,model-view-controller,swixml,Java,Swing,Model View Controller,Swixml,您好,我对Java中的swixml有问题。我需要创建简单的应用程序,但在MVC中,应用程序几乎没有表单 不幸的是,试图将ActionListener添加到控制器中的view按钮最终导致缺少响应 在视图类中,我的JButton属性和XML中的id按钮同名 我添加了以下代码: actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent){ System.ex

您好,我对Java中的swixml有问题。我需要创建简单的应用程序,但在MVC中,应用程序几乎没有表单

不幸的是,试图将ActionListener添加到控制器中的view按钮最终导致缺少响应

在视图类中,我的JButton属性和XML中的id按钮同名

我添加了以下代码:

 actionListener = new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent){
     System.exit(0);
     // menuItemControl();                
    }
 };

    view.app_close.addActionListener(actionListener);
视图为:

当我点击app_close时,应用程序没有反应

有什么可以帮我的吗?谢谢

编辑

感谢您的回答,更多代码:

主类

    package pl.kramarczykrent;

import javax.swing.SwingUtilities;
import pl.kramarczykrent.controllers.Controller;
import pl.kramarczykrent.views.*;
public class Kramarczykrent {

       public static void main(String[] args) {           
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {                                           
                //Model model = new Model(0);
                try{
                    View view = new View();
                    view.se.getRootComponent().setVisible(true);
                     Controller controller = new Controller(view);
                controller.control();
                } catch(Exception e)
                {
                        }



            }
        });  
    }
}
模型 在这个空荡荡的时候

视图类

    package pl.kramarczykrent.views;
import org.swixml.SwingEngine;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.event.ActionEvent;

public class View extends WindowAdapter{
    public JMenuItem menuItem;
    public JMenuBar menuBar;
    public JMenu menu;
    public JPanel film_form;
    public JLabel label;
    public JTextField textField;
    public JTextArea textArea;
    public JButton app_close;
    public SwingEngine se;

    public View() throws Exception {
       se = new SwingEngine(this);
       se.render("xml/view.xml");


}

}
view.xml

 <?xml version="1.0" encoding="UTF-8"?>
<frame id="frame" title="Wypożyczalnia dzikiego złesiora" size="1000,720" defaultCloseOperation="JFrame.EXIT_ON_CLOSE">
    <menubar id="mb">
        <menu id="m_film" text="Filmy">
            <menuitem id="film_new" text="Nowy"></menuitem>
            <menuitem id="film_list" text="Lista"></menuitem>
            <menuitem id="film_rent" text="Wypożycz"></menuitem>
            <menuitem id="film_return" text="Zwrot"></menuitem>
            <menuitem id="film_type" text="Gatunki"></menuitem>
        </menu>
        <menu id="m_klient" text="Klienci">
            <menuitem id="klient_new" text="Nowy"></menuitem>
            <menuitem id="klient_list" text="Lista"></menuitem>
        </menu>
        <menu id="m_pracownik" text="Pracownicy">
            <menuitem id="pracownik_new" text="Nowy"></menuitem>
            <menuitem id="pracownik_list" text="Lista"></menuitem>
            <menuitem id="pracownik_type" text="Stanowiska"></menuitem>0
        </menu>
        <menu id="m_program" text="Program">
            <menuitem id="app_close" text="Zamknij"></menuitem>
        </menu>
    </menubar>
    <panel id="film_form" visible="false">
        <vbox>
            <label text="Tytuł filmu"></label>
            <label text="Język"></label>
            <label text="Reżyser"></label>
            <label text="Rok produkcji"></label>
            <label text="Opis"></label>
            <label text="Rodzaj nośnika"></label>
            <label text="Jakość"></label>
            <label text="Czas trwania w minutach"></label>
            <label text="Ilość płyt w zestawie"></label>
            <label text="Cena za wypożyczenie"></label>
            <label text="Wiek od"></label>
            <label text="ID"></label>
        </vbox>
        <vbox>
            <textfield columns="20" text="" id="film_tytul"></textfield>
            <textfield columns="20" text="" id="film_jezyk"></textfield>
            <textfield columns="20" text="" id="film_rezyser"></textfield>
            <textfield columns="20" text="" id="film_rok_produkcji"></textfield>

        </vbox>


    </panel>
</frame>
每个文件都在其他包中,但导入是可以的

以上是现在使用的所有类


Redgars

您能在将ActionListener添加到app_close按钮的位置显示更多代码吗?这是在另一个类或方法的看法?谢谢你的回答。我改变了我的第一篇文章后,编辑是所有的代码。
 <?xml version="1.0" encoding="UTF-8"?>
<frame id="frame" title="Wypożyczalnia dzikiego złesiora" size="1000,720" defaultCloseOperation="JFrame.EXIT_ON_CLOSE">
    <menubar id="mb">
        <menu id="m_film" text="Filmy">
            <menuitem id="film_new" text="Nowy"></menuitem>
            <menuitem id="film_list" text="Lista"></menuitem>
            <menuitem id="film_rent" text="Wypożycz"></menuitem>
            <menuitem id="film_return" text="Zwrot"></menuitem>
            <menuitem id="film_type" text="Gatunki"></menuitem>
        </menu>
        <menu id="m_klient" text="Klienci">
            <menuitem id="klient_new" text="Nowy"></menuitem>
            <menuitem id="klient_list" text="Lista"></menuitem>
        </menu>
        <menu id="m_pracownik" text="Pracownicy">
            <menuitem id="pracownik_new" text="Nowy"></menuitem>
            <menuitem id="pracownik_list" text="Lista"></menuitem>
            <menuitem id="pracownik_type" text="Stanowiska"></menuitem>0
        </menu>
        <menu id="m_program" text="Program">
            <menuitem id="app_close" text="Zamknij"></menuitem>
        </menu>
    </menubar>
    <panel id="film_form" visible="false">
        <vbox>
            <label text="Tytuł filmu"></label>
            <label text="Język"></label>
            <label text="Reżyser"></label>
            <label text="Rok produkcji"></label>
            <label text="Opis"></label>
            <label text="Rodzaj nośnika"></label>
            <label text="Jakość"></label>
            <label text="Czas trwania w minutach"></label>
            <label text="Ilość płyt w zestawie"></label>
            <label text="Cena za wypożyczenie"></label>
            <label text="Wiek od"></label>
            <label text="ID"></label>
        </vbox>
        <vbox>
            <textfield columns="20" text="" id="film_tytul"></textfield>
            <textfield columns="20" text="" id="film_jezyk"></textfield>
            <textfield columns="20" text="" id="film_rezyser"></textfield>
            <textfield columns="20" text="" id="film_rok_produkcji"></textfield>

        </vbox>


    </panel>
</frame>
    package pl.kramarczykrent.controllers;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.swixml.SwingEngine;
import pl.kramarczykrent.views.*;

public class Controller {
    private View view;
    private ActionListener actionListener;

    public Controller( View view)
    {
        this.view=view;

    }

    public void control(){

    actionListener = new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent){
     System.exit(0);
     // menuItemControl();

    }


        };

    view.app_close.addActionListener(actionListener);

    }

    private void menuItemControl(){
        System.exit(0);
    }
}