Java 基于基本MVC的Swing应用程序

Java 基于基本MVC的Swing应用程序,java,swing,model-view-controller,jgoodies,Java,Swing,Model View Controller,Jgoodies,因此,我遇到了以下问题:我想用我的App类中的一个控制器实例初始化Swing构造函数。这就是我初始化回购协议和控制器的地方。当我想传递给swingGui类时,我意识到控制器参数有自己的main方法 你能检查一下代码,告诉我这是不是正确的方法吗?”因为我不确定,我找不到从TUI应用到GUI应用的基本示例。谢谢大家! App.java View_gui.java 1) 你的代码有效吗?您能够看到GUI吗?2) 什么是TUI申请?3) 你的主要问题是什么?你在问我们什么?代码工作,我看到gui。。。T

因此,我遇到了以下问题:我想用我的
App
类中的一个控制器实例初始化Swing构造函数。这就是我初始化回购协议和控制器的地方。当我想传递给swing
Gui
类时,我意识到控制器参数有自己的main方法

你能检查一下代码,告诉我这是不是正确的方法吗?”因为我不确定,我找不到从TUI应用到GUI应用的基本示例。谢谢大家!

App.java

View_gui.java


1) 你的代码有效吗?您能够看到GUI吗?2) 什么是TUI申请?3) 你的主要问题是什么?你在问我们什么?代码工作,我看到gui。。。TUI是基于文本的界面,这是swing应用程序的正确接口吗?看起来不错,但我问问题的原因是1)当你从应用程序类开始时,我看不到在视图的顶层窗口中调用
setVisible(true)
。有`window.frame.setVisible(true)`这是View_gui的主方法,一个永远不应该被调用的方法。应改为调用App main方法。
package app;

import repository.*;
import view.View_gui;
import controller.*;

public class App{
    RepoInterface ri;
    ControllerInterface c;
    View_gui gui;

    public App() {
        ri = new Repo();
        c = new Controller(ri);
        gui = new View_gui(c);
    }

    public static void main(String[] args) {
        App app = new App();
    }
}
package view;

import controller.*;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.awt.BorderLayout;
import java.awt.Label;
import java.awt.Panel;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JSeparator;
import javax.swing.JPanel;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.GridLayout;

public class View_gui {

    private JFrame frame;
    private static ControllerInterface ci; //added the variable

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    View_gui window = new View_gui(ci); // parametrizied
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public View_gui(ControllerInterface c) {
        ci = c;                          // add + param by me
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame("Countries");
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel lblNewLabel = new JLabel("Country");

        JLabel lblCapital = new JLabel("Capital");

        JLabel lblArea = new JLabel("Area");


    }
}