小编Hat*_*end的帖子

JavaFX TilePane setPrefColumn / Row方法不起作用?

我正在尝试用JavaFX制作Suduko板。我听说TilePane对此特别有用,因为TilePane背后的整个想法是每个“平铺”的大小均一。太好了,这就是Suduko棋盘,国际象棋棋盘,跳棋,井字游戏,战舰等的声音。听起来像TilePane是任何类型的棋盘游戏应用程序必不可少的窗格。

还是?

import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.TextFormatter.Change;
import javafx.scene.image.Image;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class SudukoSolver extends Application
{
    Stage window;
    Scene scene;
    private final int TEXTFIELD_WIDTH = 32;
    private final int TEXTFIELD_HEIGHT = 32;

    @Override public void start(Stage window) throws Exception
    {       
        this.window = window;
        window.setTitle("Suduko Solver");
        window.setOnCloseRequest(e -> closeProgram());

        // Does setting this to false defeat the purpose of TilePane?
        window.setResizable(false); 

        VBox root = new VBox(); 
        //root.setAlignment(Pos.CENTER); …
Run Code Online (Sandbox Code Playgroud)

java user-interface javafx

2
推荐指数
1
解决办法
1869
查看次数

在结构构造函数中使用"this"关键字编译错误? - C++

我有以下内容:

int main()
{
    struct A
    {
        unsigned char x, y;

        A(unsigned char x, unsigned char y)
        {
            this.x = x; // Error: expression must have class type.
            thix.y = y; // Error: expression must have class type.
        }
    };

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如何正确指的是xy的变量struct A,而不是xy的构造函数的参数变量A

谢谢.

c++ constructor struct

2
推荐指数
1
解决办法
3214
查看次数

C - Struct构造函数和解构函数

如果我有一个像这样的结构:

struct Cell
{
    unsigned int *x, *y;
    char flag;
};
Run Code Online (Sandbox Code Playgroud)

下面的构造函数和解构器是否足以安全地分配和取消分配内存?

// Constructor function.
struct Cell *Cell_new()
{
    struct Cell *born = malloc(sizeof(struct Cell));
    if (born == NULL)
        return NULL;
    born->x = NULL;
    born->y = NULL;
    born->flag = false;
    return born;
}

// Deconstructor function.
// When called, use Cell_destroy(&cell);
char Cell_destroy(struct Cell **cell)
{
    free(cell);
    cell = NULL;
}
Run Code Online (Sandbox Code Playgroud)

它是否正确?

我不明白的一件事是,如果我这样做:

struct Cell *myCell = Cell_new();
Cell_destroy(&myCell);
Run Code Online (Sandbox Code Playgroud)

当我正在调用时destroy,它期望一个指针(指向指针的指针)的地址,但我正在为结构提供一个地址.

我的意思是

我的功能期望:

Pointer -> Pointer -> Tangible Object …

c pointers

2
推荐指数
1
解决办法
294
查看次数

C - 非突兀的图形库?

我已经在其他语言中使用了GUI,但从来没有像C这样的低语言.我在线看过,发现SDL是理想的选择但不幸的是我不喜欢它在自己的窗口内运行的事实.有没有办法直接绘制到没有任何其他功能的屏幕?

例如,如果我想绘制保持ontop的其他窗口的形状,但只是有其属性设置为一个阶段,透明.

如果那是不可能的,那么我正在寻找尽可能简单和轻松的东西.我的目标是创造这样的东西

c graphics

2
推荐指数
1
解决办法
57
查看次数

Java - 'finally'相当于if语句

编辑:我只希望在finally其中一个if或多个else if语句为真的情况下执行代码.

很多次,我遇到以下情况:

if (condition1)
    do stuff
    do something
else if (conditon2)
    do other stuff
    do something
else if (condition3)
    algorithm here
    do something
Run Code Online (Sandbox Code Playgroud)

如果finallyif语句有一个条款,我可以将其减少为:

if (condition1)
    do stuff
else if (conditon2)
    do other stuff
else if (condition3)
    algorithm here
finally
    do something
Run Code Online (Sandbox Code Playgroud)

我试图找到一些解决方案,do something只需要调用一次,而不需要另外的方法,做一些奇怪的地方if语句,或制作一个标志,如:

boolean special = false;

if (condition1)
        do stuff
        special = true;
else if (conditon2)
        do other stuff
        special = true;
else if (condition3)
        algorithm here …
Run Code Online (Sandbox Code Playgroud)

java if-statement

2
推荐指数
3
解决办法
2553
查看次数

数组允许在 C 中越界访问?

Java / C++ 开发人员在这里。试图学习 C,但我对数组的内存分配感到困惑。

这里发生了什么?

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

int main()
{
    int az[3];
    az[2] = 66;
    az[8] = 5214;

    printf("%d\n", az[8]);

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出

5214
Run Code Online (Sandbox Code Playgroud)

怎么可能 ?为什么我没有得到越界异常或程序崩溃?我可以无限地这样做吗?在这种情况下,我的数组长度是多少?malloc如果我的数组允许我已经将值超出范围,那么分配内存有什么意义?这对我来说是零意义的。

在此处输入图片说明

c arrays

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

赋值运算符左侧的三元条件运算符

我有一个condition和三个变量.

// Assume these variables are all initialized.
int *a;
int *b;
const int c;
const bool condition;

if (condition)
    *a = c;
else
    *b = c;
Run Code Online (Sandbox Code Playgroud)

我希望if块通过三元条件运算符在一行上.

(condition ? *a : *b) = c;
Run Code Online (Sandbox Code Playgroud)

我不明白为什么不允许这样做,因为我没有打破三元条件运算符的规则.双方*a*b返还相同种类.

c c++ syntax ternary-operator lvalue

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

C - Sprintf的变量参数?

我有一个功能;

void foo(const char* format, ...)
{
    char buffer[1080];

    // Supposed way to handle C Variable Arguments?
    va_list argptr;
    va_start(argptr, format);
    sprintf(buffer, format, argptr);
    va_end(argptr);

    printf_s("%s.\n", buffer);
}

int main()
{
    int val = 53;
    foo("%d", val);
}
Run Code Online (Sandbox Code Playgroud)

每次运行时,我都会得到每次运行时都会发生变化的大量数字.12253360, 5306452等我不明白为什么.

这是我的sprintf电话,还是我正在做的事情va_list argptr;?我buffer太大了吗?

谢谢.

c variadic-functions

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

通过超类返回与类名相同的数据类型?

我有一个abstract class有一种abstract方法.我想此方法return相同的数据类型,其重写方法的类,而无需强制转换的结果create或具有使在每个子类的新方法声明.我希望它可以从父类中无缝地声明.

我希望该方法返回一个对象,其数据类型与调用它的类相同.

编辑:我删除了印刷品,因为人们对我的要求感到困惑

abstract class A
{
   public abstract ... create();
}

class B extends A
{
   @override
   public ... create()
   {
      return new B...;
   }
}

class C extends A
{
   @override
   public ... create()
   {
      return new C...;
   }
}
Run Code Online (Sandbox Code Playgroud)

这样

B x1 = new B();
B x2 = x1.create();
// Since create was called on a B object
// a B object is returned, NOT AN …
Run Code Online (Sandbox Code Playgroud)

java oop

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

C - 编译器允许的语法无效?

当我使用Microsoft Visual Studio学习C时,它不允许我创建一个非常大小的数组.我不得不把价值int arr[5];或者做#define size 5或做int arr[size];.但是今天使用Clion,我注意到它允许我执行以下操作:

#include <stdio.h>

int main()
{
    printf("Enter a value: ");
    int x;
    scanf("%d", &x);

    int arr2[x];
    for (int i = 0; i < x; i++)
    {
        arr2[i] = i;
        printf("Array at %d is %d.\n", i, arr2[i]);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个C代码编译和运行没有任何问题 - 没有段错误或任何东西.这是怎么回事?这是合法的C代码,我刚刚在一个不允许它的IDE中学习过,或者这是无效的C代码而我只是使用了一个糟糕的编译器?在我使用Linux的另一台计算机上,我甚至安装了GCC 7.2,并且允许使用相同的语法.我不明白.这是一个CLion问题,CMake问题还是C lang问题?

我的编译器和CMake如下所示.谢谢.

在此输入图像描述

c cmake clion

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