【发布时间】:2017-03-28 21:09:53
【问题描述】:
我需要使用下面附加的 KDTreeTester.java 文件进行各种测试运行。每次我完成运行并重新编译文件时更改值(w、h、n、x)会非常低效。
那时我认为在主程序打开之前输入值会非常方便。
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Main program that starts the KDTree visualization
*/
public class KDTreeTester extends JFrame{
int w=400; //width of the window
int h=400; //height of the window
int n=20; //number of points
int x=5; //number of points to be searched (has to be smaller than n)
KDTreeVisualization vis; //the visualization
public KDTreeTester(){
// Initialize the visualization and add it to the main frame.
vis = new KDTreeVisualization(w, h, n);
add(vis);
代码继续,但我认为只有这才是相关部分。 我需要一个框来询问四个值(宽度、高度、点数、要搜索的点数)。我猜必须将其从 String 解析为 int。
实现这一点的最佳方法是什么?
【问题讨论】:
-
在main方法开始之前你不能做任何事情,只有通过cmd启动。您可以使用自定义 JDialog
-
如果您使用的是
JFrame,那么为什么不使用JTextField来收集您的输入?
标签: java jframe user-input