翻阅Java / Swing中的书 [英] Flip Book in Java/Swing

查看:84
本文介绍了翻阅Java / Swing中的书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是gyus看过那些基于flash的翻书。我想在Java中创建相同的东西。我正在使用JTextArea作为本书的叶子。我想知道的是如何通过重写与Mouse / KeyListener结合的componentPaint方法来实现页面翻转效果?

You gyus have seen those flash based flip books. I want to create the same in Java. I am using JTextArea for leaf of the book. What I want to know is how can I go about implementing the page flip effect, by overriding the componentPaint method combined with Mouse/KeyListener perhaps?

推荐答案

您需要将现有页面渲染到屏幕外缓冲区,然后转换缓冲区以呈现页面翻转。

You would need to render the existing page into an off-screen buffer, then transform the buffer to render the page flip.

所以,


  • 创建一个屏幕大小的屏幕外图像缓冲区。

  • 获取缓冲区的图形上下文并使用该上下文调用super.componentPaint

  • 您现在已将页面呈现为平坦到您的屏幕外缓冲区中

  • 随着你的 - 屏幕上下文,

    • 清除区域,

    • 复制缩小的屏幕外页面以显示翻转

    • 在顶部绘制一个alpha渐变,以遮盖页面,使其看起来像3D

    • create an off-screen image buffer of the size of the screen.
    • Get the graphics context of the buffer and call super.componentPaint with that context
    • You've now got your page rendered 'flat' into your off screen buffer
    • With your on-screen context,
      • clear the area,
      • copy the offscreen page scaled to show the flip
      • draw an alpha gradient over the top to 'shade' the page so it looks 3D

      你需要在一个线程中驱动它,以便在动画时重复调用重绘在玩。所以设置一个' pageIsTurning '标志,以及' percentageTurned ',它将指示paint方法需要做什么特殊绘图及其在动画中的位置。在重复调用paint方法时更新percentageTurned标志,然后一旦完成,重置标志并允许componentPaint方法默认为super.componentPaint。

      You'd need to drive this in a thread to repeatedly invoke the re-draw whilst the animation plays out. So Set a 'pageIsTurning' flag, and 'percentageTurned' that will indicate to the paint method that it needs to do the special drawing and where it is in the animation. Update the percentageTurned flag as you repeatedly call the paint method, then once things are complete, reset the flag and allow the componentPaint method to default to super.componentPaint.

      这篇关于翻阅Java / Swing中的书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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