相关疑难解决方法(0)

重写到MVC后GUI无法正常工作

我正在练习MVC风格的编程.我在一个文件中有一个Mastermind游戏,工作正常(可能除了"Check"按钮在开始时不可见).

http://paste.pocoo.org/show/226726/

但是当我把它重写为模型,视图,控制器文件时 - 当我点击空Pin(应该更新,并重新绘制新颜色)时 - 注意到了.谁能在这里看到任何问题?我尝试在不同的地方放置repaint(),但它根本不起作用:/

主要:

public class Main { 
    public static void main(String[] args){
        Model model = new Model();
        View view = new View("Mastermind", 400, 590, model);
        Controller controller = new Controller(model, view); 
        view.setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

型号:

import java.util.Random;

public class Model{
    static final int
    LINE = 5,
    SCORE = 10, OPTIONS = 20;
    Pin pins[][] = new Pin[21][LINE];
    int combination[] = new int[LINE];
    int curPin = 0;
    int turn = 1;
    Random generator = new Random(); …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller user-interface swing

121
推荐指数
2
解决办法
4万
查看次数

JAR Bundler使用OSXAdapter导致应用程序滞后或终止

我创建了一个简单的Java应用程序,每秒连续10秒为a添加一个新行JTable.它由三个类组成.

程序启动后调用的主类

public class JarBundlerProblem {
    public static void main(String[] args)
    {
        System.err.println("Initializing controller");
        new Controller();
    }
}
Run Code Online (Sandbox Code Playgroud)

一个控制器,用于创建GUI并对其进行更改 doWork()

public class Controller {
    public Controller()
    {
        doWork(null);
    }
    public static void doWork(String s)
    {
        GUI gui = new GUI();

        for (int i=0; i<10; i++)
        {
            gui.addRow("Line "+(i+1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,GUI

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class GUI {
    private JFrame frame = …
Run Code Online (Sandbox Code Playgroud)

java macos swing jarbundler

4
推荐指数
1
解决办法
6893
查看次数

摇摆动画运行速度极慢

我的当前动画有问题,我正在使用Java Swing运行.这是一个离散事件模拟,基于文本的模拟工作正常,我只是在连接模拟到GUI输出时遇到问题.

在这个例子中,我将有10辆车要模拟.JPanels我将在几分钟内详细说明这些汽车.

所以考虑一下,事件process_car_arrival.每次计划执行此事件时,我都会在我的类中Car向被ArrayList调用者添加一个对象.本类具有以下相关属性:carsModelCar

Point currentPos; // The current position, initialized in another method when knowing route.
double speed; // giving the speed any value still causes the same problem but I have 5 atm.
RouteType route; // for this example I only consider one simple route
Run Code Online (Sandbox Code Playgroud)

另外它有以下方法move():

switch (this.route) {
    case EAST:
        this.currentPos.x -= speed; 
        return this.currentPos;
.
.
.
//only above is relevant in this example
Run Code Online (Sandbox Code Playgroud)

这一切都很好.所以从理论上讲,汽车沿着一条直线道路从东向西穿过,因为我只是 …

java optimization performance swing multithreading

4
推荐指数
2
解决办法
4818
查看次数