想要在Timer生成事件时另外画线 [英] want to drawLine additionally when Timer generates Events

查看:64
本文介绍了想要在Timer生成事件时另外画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在标题中写道, 我想在Timer生成事件时另外drawLine.

As I wrote in title, I want to drawLine additionally when Timer generates events.

线条将绘制为

第一次;

第二次;

ㅡ
ㅡ

  1. 我要在保持现状之前添加行
  2. 如果不能完成第一个目标,(因为我还不擅长Java,那只是我的主意)我想在第N个事件中绘制N行,然后在第(N + 1)个中重新绘制新的N + 1行事件.

哪些可以用Java完成?

Which could be done in Java?

P.S.如何停止Swing Timer?

P.S. How to stop the Swing Timer?

推荐答案

您基本上必须(无顺序):

You'll basically have to (not in order):

  • 建立一个在计时器的每个滴答声中发生的事件
  • 将其传递到新的计时器 (有关停止计时器的信息,请参见文档)
  • 设置某种基于计数器或基于刻度的增量计数器
  • 基于递增计数器,重写组件中的paintComponent方法以绘制线条
  • 从事件内部,在组件上调用repaint()(将在每个计时器滴答时发生)
  • Build an event to happen on each tick of the timer
  • Pass it to a new timer (stopping the timer is in the documentation)
  • Set some sort of incrementing counter, either coordinate-based or tick-based
  • Override the paintComponent method in a component to draw the lines, based on the incrementing counter
  • From inside the event, call repaint() on your component (will happen on each timer tick)

分别处理这些任务中的每一项,当您感觉已经掌握了每个任务时,可以尝试将它们放在一起.

Work on each one of those tasks individually, and when you feel you've mastered each one, you can try putting them all together.

这篇关于想要在Timer生成事件时另外画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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