简体   繁体   English

Java Swing元素转换

[英]Java Swing element transitions

I am trying to make a small non-commercial app and make it have a well designed interface, with screen transitions and such. 我正在尝试制作一个小型的非商业应用程序,并使其具有精心设计的界面,屏幕转换等。 I have every "screen" on separate panels in one JFrame and wish to be able to slide them smoothly when transitioning between panels. 我在一个JFrame中的单独面板上有每个“屏幕”,并且希望能够在面板之间转换时平滑地滑动它们。 Is there any way to accomplish this somewhat easily? 有没有办法轻易地完成这个?

Since you did not accepted an answer yet, may I suggest you the SlidingLayout library ? 由于您还没有接受答案,我可以建议您使用SlidingLayout库吗? It's a very small library which aim is to create smooth transitions between two layouts of some components. 它是一个非常小的库,目的是在一些组件的两个布局之间创建平滑过渡。 Thus, making a transition between two screens is very easy to do. 因此,在两个屏幕之间进行转换非常容易。 Here's an example I just made: 这是我刚才做的一个例子:

在此输入图像描述在此输入图像描述

The difference between the two transitions relies on two lines of code. 两个转换之间的差异依赖于两行代码。 You can also create more fancy transitions by applying a different delay on each component, so they appear not all at once but with some timing variations between them. 您还可以通过在每个组件上应用不同的延迟来创建更多花哨的过渡,因此它们不会同时出现,但它们之间会有一些时序变化。

I hope it may be useful to you :) 我希望它对你有用:)

This is a typical animation use case. 这是一个典型的动画用例。 The easiest way is to use animation framework . 最简单的方法是使用动画框架 I'd suggest Trident 我建议三叉戟

Alternatively, you could use this simple animation library, AnimaationClass, to move JComponents about their x and y axes then hide/dispose of them. 或者,您可以使用这个简单的动画库AnimaationClass来移动JComponents关于它们的x和y轴,然后隐藏/处理它们。

This offers decent (basic and smooth) animation. 这提供了体面(基本和流畅)动画。

http://www.teknikindustries.com/downloads.html http://www.teknikindustries.com/downloads.html

It comes with a javadoc if somehow you don't understand. 它带有一个javadoc,如果你不明白你不明白。

I've written a simple program in Java to do simple slide Transitions. 我用Java编写了一个简单的程序来做简单的幻灯片转换。 You can adapt it to do other things (than sliding). 你可以调整它来做其他事情(而不是滑动)。

Here is a link to my implementation: http://www.java-forums.org/entry.php?b=1141 以下是我的实施链接: http//www.java-forums.org/entry.php?b = 1141

And here is a Listener I wrote to detect a finger drag on the screen: 这是我写的一个侦听器,用于检测屏幕上的手指拖动:

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
 *
 * @author Ozzy
 */
public class GestureListener implements MouseListener, MouseMotionListener {

        int dragStartX;
        int dragStartY;
        int dragEndX;
        int dragEndY;

        int currentX;
        int currentY;

        boolean dragged;

        private void dragGesture() {
            if (dragged) {
                int distance = dragEndX - dragStartX;
                System.out.println("Drag detected. Distance: " + distance);
                if (distance > 144) /** 2 inches on 72dpi */ {
                    //finger going right
                    MyApp.scrollLeft();
                } else if (distance < -144) {
                    //finger going left
                    MyApp.scrollRight();
                } else {
                    //do nothing
                }
                dragged = false;
            }
        }

        public void mouseDragged(MouseEvent e) {
            dragged = true;
            Point pos = e.getPoint();
            dragEndX = pos.x;
            dragEndY = pos.y;
        }

        public void mouseMoved(MouseEvent e) {
            Point pos = e.getPoint();
            currentX = pos.x;
            currentY = pos.y;
        }

        public void mouseClicked(MouseEvent e) {

        }

        public void mousePressed(MouseEvent e) {
            Point pos = e.getPoint();
            dragStartX = pos.x;
            dragStartY = pos.y;
        }

        public void mouseReleased(MouseEvent e) {
            dragGesture();
        }

        public void mouseEntered(MouseEvent e) {

        }

        public void mouseExited(MouseEvent e) {

        }

    }

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM