我是一名Java初学者,并且已经为这个问题提供了各种解决方案,并且已经让我自己打结了.我已经尝试过使用Threads,然后发现了这个Timer类,并且到目前为止没有成功.如果您可以使用main方法发布可执行代码,那么我可以看到它正常工作并从那里开始玩,那将是很棒的.
doSomething()doSomething()再次呼叫.可能使用这个:http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html
我已经进行了实验和搜索,我似乎无法弄清楚我认为什么是简单的东西,当我的小GUI应用程序启动时,我的START按钮具有焦点,所以用户所要做的就是按下他们的Enter /返回键,与使用鼠标单击"开始"按钮的效果相同.这是我的代码.谢谢你的帮助 :)
private void initialize() {
// Launch the frame:
frame = new JFrame();
frame.setTitle("Welcome!");
frame.setSize(520, 480);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Add the image:
ImageIcon heroShotImage = new ImageIcon("heroShot.jpg");
JPanel heroShotPanel = new JPanel();
JLabel heroShot = new JLabel(heroShotImage);
heroShotPanel.add(heroShot);
// Create a panel to hold the "Start" button:
JPanel submitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
// Create the "Start" button, which launches business logic and dialogs:
JButton start = new JButton("Start");
start.setToolTipText("Click to use library");
start.setFocusable(true); // How do I …Run Code Online (Sandbox Code Playgroud)