Java Swing 元素转换

发布于 2024-11-06 20:06:26 字数 117 浏览 0 评论 0原文

我正在尝试制作一个小型的非商业应用程序,并使其具有设计良好的界面,具有屏幕转换等功能。我在一个 JFrame 中的单独面板上拥有每个“屏幕”,并且希望能够在面板之间转换时平滑地滑动它们。有什么办法可以轻松地实现这一点吗?

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. Is there any way to accomplish this somewhat easily?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜妞爱困 2024-11-13 20:06:26

由于您尚未接受答案,我可以建议您使用 SlidingLayout 库吗?
这是一个非常小的库,其目的是在某些组件的两个布局之间创建平滑的过渡。因此,在两个屏幕之间进行转换非常容易。这是我刚刚制作的一个示例:

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

两个转换之间的差异取决于两行代码。您还可以通过在每个组件上应用不同的延迟来创建更奇特的过渡,因此它们不会同时出现,而是在它们之间存在一些时间变化。

我希望它对你有用:)

Since you did not accepted an answer yet, may I suggest you the SlidingLayout library?
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:

enter image description here enter image description here

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 :)

你在看孤独的风景 2024-11-13 20:06:26

这是一个典型的动画用例。最简单的方法是使用动画框架。我建议Trident

This is a typical animation use case. The easiest way is to use animation framework. I'd suggest Trident

完美的未来在梦里 2024-11-13 20:06:26

我用 Java 编写了一个简单的程序来执行简单的幻灯片转换。您可以调整它来做其他事情(除了滑动)。

这是我的实现的链接:
http://www.java-forums.org/entry.php?b=1141

这是我编写的一个侦听器,用于检测屏幕上的手指拖动:

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) {

        }

    }

希望这会有所帮助。

I've written a simple program in Java to do simple slide Transitions. 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

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.

椵侞 2024-11-13 20:06:26

或者,您可以使用这个简单的动画库 AnimaationClass 围绕其 x 和 y 轴移动 JComponent,然后隐藏/处置它们。

这提供了不错的(基本且流畅的)动画。

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

它附带了一个 javadoc,如果您以某种方式不明白。

Alternatively, you could use this simple animation library, AnimaationClass, to move JComponents about their x and y axes then hide/dispose of them.

This offers decent (basic and smooth) animation.

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

It comes with a javadoc if somehow you don't understand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文