用Java创建网格 [英] Creating a Grid in Java

查看:205
本文介绍了用Java创建网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为学习Java的一种方式,我正在编写这个小应用程序供学龄前儿童练习基本数学.这个想法是,孩子只要在应用程序中就可以解决许多数学问题,只是继续向他们抛出问题,直到他们单击完成"按钮为止.当他们决定要完成时,我想要一个新的JFrame,它将向他们显示他们尝试的所有问题以及答案,以及他们是对是错.

As a way of learning Java, I'm writing this little application for grade schoolers to practice basic math. The idea is that the kid does any number of math problems, as long as they are in the app, it just continues to throw problems at them until they click a 'Done' button. When they decide to be done, I want a new JFrame to come up that will show them all of the problems they attempted, along with their answer, and whether they got the problem right or wrong.

我正在寻找的建议是呈现这些结果的最佳方式.我研究了GridLayout和GroupLayout,但是我认为这些都不是正确的.我在VBA for Excel中做过类似的事情,在那儿我为他们尝试的每个问题运行了一次循环的for循环.每次迭代都会在框架中添加一行标签,并在各个标签中显示问题的要素.我用Java尝试过,但是我什至无法显示标签.

The advice that I am looking for is what is the best way for me present these results. I looked into the GridLayout and the GroupLayout, but I don't think that these are exactly right. I did something similar in VBA for Excel, and there I just ran a for loop with one iteration for every problem they attempted. Each iteration would add a row of labels to the frame with the elements of the problem displayed in the various labels. I tried this in Java, but I'm not even able to get the labels to even display.

因此,在获得所有具体信息并开始发布代码之前,我想问一个更大的问题,即创建这样的视图的最佳方法是什么?"通常,我会朝一个方向走去只是为了浪费时间,然后才有人提出一种完全不同(更好)的方法.

So before I get all specific and start posting my code, I want to ask a bigger question, which is "what is the best method to create a view like this?" Often, I go off in one direction only to waste time before somebody suggests a totally different (and better) approach.

谢谢!

(这是我在Excel中的操作方式的图像.我试图在Java中重复基本相同的操作)

(edit: here's an image of how I did this in Excel. I'm trying to repeat basically the same thing in Java)

推荐答案

进行该设计的一种简单方法是混合使用组件.您可以将一堆JLabelJPanel堆叠在垂直的FlowLayout中.您描述的网格最好在JTable中设计,如下所示:

One simple way to make that design would be to use a mix of components. You could have a bunch of JLabels and JPanels stacked in a vertical FlowLayout. The grid you have described would be best designed in a JTable, something like the below:

这篇关于用Java创建网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆