小编chr*_*sco的帖子

如何使用Timer类调用方法,执行某些操作,重置计时器,重复?

我是一名Java初学者,并且已经为这个问题提供了各种解决方案,并且已经让我自己打结了.我已经尝试过使用Threads,然后发现了这个Timer类,并且到目前为止没有成功.如果您可以使用main方法发布可执行代码,那么我可以看到它正常工作并从那里开始玩,那将是很棒的.

  1. 启动计划
  2. 呼叫 doSomething()
  3. 生成随机数并设置那么长的Timer.
  4. 当定时器关闭时,doSomething()再次呼叫.

可能使用这个:http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html

java timer scheduled-tasks

28
推荐指数
2
解决办法
13万
查看次数

Java GUI:如何在JFrame上的JPanel中设置JButton的焦点?

我已经进行了实验和搜索,我似乎无法弄清楚我认为什么是简单的东西,当我的小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)

java user-interface swing

16
推荐指数
2
解决办法
5万
查看次数

标签 统计

java ×2

scheduled-tasks ×1

swing ×1

timer ×1

user-interface ×1