Java的滑动JPanels [英] Java sliding JPanels

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

问题描述

我有了各种各样的显示按钮的菜单,我能够做单击时按钮调用各自JPanels。问题是,我想做出时,其调用,而不是瞬间弹出的JPanel的幻灯片。我尝试使用补间动画引擎和Java的初学者,我觉得很铺天盖地,所以我决定用定时动画。我能够做的JPanel在上面滑行到一侧,但由于某些原因,接下来的面板不希望显示,即时通讯真的累了,可以有人帮助,请!有code是如下:

 公共类侦听程序实现的ActionListener {
    @覆盖
    公共无效的actionPerformed(ActionEvent的五){        新的定时器(0,新的ActionListener(){
           公共无效的actionPerformed(ActionEvent的五){              mainpane.setLocation(mainpane.getX() - 10,0);
              如果(mainpane.getX()+ mainpane.getWidth()== 0)
              {
                 ((定时器)e.getSource())停止();
                   的System.out.println(计时器停止​​);
              }
           }
        })。开始();
   }
}


解决方案

滑动面板可能会非常棘手。下面是一些入门code。修改以适应
您的需求。添加错误检查和异常处理是必要的。

本例使用Jbutton将和一个JTree的内容,但你可以使用任何类型的内容。

用法:

 静态公共无效的主要(最终字串[] args)抛出异常{
    SwingUtilities.invokeAndWait(新的Runnable(){
        @覆盖
        公共无效的run(){
            最终的JFrame的JFrame =新的JFrame(){
                {
                    最后PanelSlider42<&的JFrame GT;滑块=新PanelSlider42<&的JFrame GT;(本);
                    最终的JPanel的JPanel = slider.getBasePanel();                    slider.addComponent(新的JButton(1));
                    slider.addComponent(的新的JButton(22));
                    slider.addComponent(的新的JButton(333));
                    slider.addComponent(的新的JButton(4444));                    的getContentPane()加(JPanel中)。
                    的setSize(300,300);
                    setLocationRelativeTo(NULL);
                    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    调用setVisible(真);
                }
            };
        }
    });
}

该IMPL是漫长的...

 包com.java42.example code。进口java.awt.BorderLayout中;
进口java.awt.Component中;
进口java.awt.Container中;
进口java.awt.Cursor中;
进口java.awt.Insets中;
进口java.awt.Point中;
进口java.awt.Toolkit中;
进口java.awt.event.ActionEvent中;
进口java.awt.event.ActionListener;
进口java.awt.event.KeyAdapter;
进口java.awt.event.MouseAdapter;
进口java.awt.event.MouseMotionAdapter;
进口的java.util.ArrayList;进口javax.swing.JButton中;
进口javax.swing.JDialog中;
进口javax.swing.JFrame中;
进口javax.swing.JPanel中;
进口javax.swing.JWindow中;
进口javax.swing.SwingUtilities中;公共类PanelSlider42< ParentType的延伸集装箱> {私有静态最终诠释RIGHT = 0×01;
私有静态最终诠释LEFT = 0×02;
私有静态最终诠释TOP = 0×03;
私有静态最终诠释BOTTOM = 0×04;
私人最终的JPanel basePanel =新JPanel();
私人最终ParentType的父母;
私人最终对象锁=新的对象();
私人最终的ArrayList<成分> jPanels =新的ArrayList<成分>();
私人最终布尔useSlideButton = TRUE;
私人布尔isSlideInProgress = FALSE;私人最终的JPanel的glassPane;
{
    的glassPane =新JPanel();
    glassPane.setOpaque(假);
    glassPane.addMouseListener(新MouseAdapter(){
    });
    glassPane.addMouseMotionListener(新MouseMotionAdapter(){
    });
    glassPane.addKeyListener(新KeyAdapter(){
    });
}公共PanelSlider42(最终ParentType的母公司){
    如果(家长== NULL){
        抛出新的RuntimeException(ProgramCheck:家长不能为空);
    }
    如果((父的instanceof的JFrame)||(父的instanceof的JDialog)||(父的instanceof的JWindow)||(父的instanceof的JPanel)){
    }
    其他{
        抛出新的RuntimeException(ProgramCheck:父类型不支持。+ parent.getClass()getSimpleName());
    }
    this.parent =父母;
    连接();
    basePanel.setSize(parent.getSize());
    basePanel.setLayout(新的BorderLayout());
    如果(useSlideButton){
        最终的JPanel状态面板=新JPanel();
        basePanel.add(状态面板,BorderLayout.SOUTH);
        statusPanel.add(的新的JButton(幻灯片左){
            私有静态最后的serialVersionUID长= 9204819004142223529L;
            {
                setMargin(新插图(0,0,0,0));
            }
            {
                addActionListener方法(新的ActionListener(){
                    @覆盖
                    公共无效的actionPerformed(ActionEvent的最终E){
                        slideLeft();
                    }
                });
            }
        });
        statusPanel.add(的新的JButton(向​​右滑动){
            {
                setMargin(新插图(0,0,0,0));
            }
            私有静态最后的serialVersionUID长= 9204819004142223529L;
            {
                addActionListener方法(新的ActionListener(){
                    @覆盖
                    公共无效的actionPerformed(ActionEvent的最终E){
                        slideRight();
                    }
                });
            }
        });
        statusPanel.add(的新的JButton(向​​上滑动){
            {
                setMargin(新插图(0,0,0,0));
            }
            私有静态最后的serialVersionUID长= 9204819004142223529L;
            {
                addActionListener方法(新的ActionListener(){
                    @覆盖
                    公共无效的actionPerformed(ActionEvent的最终E){
                        slideTop();
                    }
                });
            }
        });
        statusPanel.add(的新的JButton(向​​下滑动){
            {
                setMargin(新插图(0,0,0,0));
            }
            私有静态最后的serialVersionUID长= 9204819004142223529L;
            {
                addActionListener方法(新的ActionListener(){
                    @覆盖
                    公共无效的actionPerformed(ActionEvent的最终E){
                        slideBottom();
                    }
                });
            }
        });
    }
}公众的JPanel getBasePanel(){
    返回basePanel;
}私人无效连接(){
    最后ParentType的W = this.parent;
    如果(W的instanceof的JFrame){
        最终的JFrame J =(JFrame的)瓦;
        如果(j.getContentPane()getComponents()长度方式> 0){
            抛出新的RuntimeException(ProgramCheck:家长已经包含内容的。);
        }
        j.getContentPane()加(basePanel)。
    }
    如果(W的instanceof的JDialog){
        最终的JDialog J =(的JDialog)瓦;
        如果(j.getContentPane()getComponents()长度方式> 0){
            抛出新的RuntimeException(ProgramCheck:家长已经包含内容的。);
        }
        j.getContentPane()加(basePanel)。
    }
    如果(W的instanceof的JWindow){
        最终的JWindow J =(的JWindow)瓦;
        如果(j.getContentPane()getComponents()长度方式> 0){
            抛出新的RuntimeException(ProgramCheck:家长已经包含内容的。);
        }
        j.getContentPane()加(basePanel)。
    }
    如果(W的instanceof的JPanel){
        最终的JPanel J =(JPanel中)瓦;
        如果(j.getComponents()长度方式> 0){
            抛出新的RuntimeException(ProgramCheck:家长已经包含内容的。);
        }
        j.add(basePanel);
    }
}公共无效addComponent(最终色差分量){
    如果(jPanels.contains(组分)){
    }
    其他{
        jPanels.add(组分);
        如果(jPanels.size()== 1){
            basePanel.add(组分);
        }
        component.setSize(basePanel.getSize());
        component.setLocation(0,0);
    }
}公共无效removeComponent(最终色差分量){
    如果(jPanels.contains(组分)){
        jPanels.remove(组分);
    }
}公共无效slideLeft(){
    滑动件(左);
}公共无效slideRight(){
    滑动件(右);
}公共无效slideTop(){
    幻灯片(TOP);
}公共无效slideBottom(){
    幻灯片(BOTTOM);
}私人无效enableUserInput(最终ParentType的W){
    如果(W的instanceof的JFrame){
        ((JFrame的)W).getGlassPane()调用setVisible(假)。
    }
    如果(W的instanceof的JDialog){
        ((的JDialog)W).getGlassPane()调用setVisible(假)。
    }
    如果(W的instanceof的JWindow){
        ((的JWindow)W).getGlassPane()调用setVisible(假)。
    }
}私人无效disableUserInput(最终ParentType的W){
    如果(W的instanceof的JFrame){
        ((JFrame的)W).setGlassPane(的glassPane);
    }
    如果(W的instanceof的JDialog){
        ((的JDialog)W).setGlassPane(的glassPane);
    }
    如果(W的instanceof的JWindow){
        ((的JWindow)W).setGlassPane(的glassPane);
    }
    glassPane.setVisible(真);
}私人无效enableTransparentOverylay(){
    如果(父的instanceof的JFrame){
        ((JFrame的)母公司).getContentPane()的setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
    如果(父的instanceof的JDialog){
        ((的JDialog)母公司).getContentPane()的setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
    如果(父的instanceof的JWindow){
        ((的JWindow)母公司).getContentPane()的setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
}私人无效的幻灯片(最终诠释slideType){
    如果(!isSlideInProgress){
        isSlideInProgress =真;
        最终线程T0 =新主题(新的Runnable(){
            @覆盖
            公共无效的run(){
                parent.setCursor(Cursor.get predefinedCursor(Cursor.WAIT_CURSOR));
                disableUserInput(父);
                幻灯片(真,slideType);
                enableUserInput(父);
                parent.setCursor(Cursor.get predefinedCursor(Cursor.DEFAULT_CURSOR));
                isSlideInProgress = FALSE;
            }
        });
        t0.setDaemon(真);
        t0.start();
    }
    其他{
        Toolkit.getDefaultToolkit()音()。
    }
}私人无效的幻灯片(最终布尔useLoop,最终诠释slideType){
    如果(jPanels.size()2){
        通信System.err.println(没有足够的面板);
        返回;
    }
    同步(锁){
        组件componentOld = NULL;
        组件componentNew = NULL;
        如果((slideType == LEFT)||(slideType == TOP)){
            componentNew = jPanels.remove(jPanels.size() - 1);
            componentOld = jPanels.get(0);
            jPanels.add(0,componentNew);
        }
        如果((slideType == RIGHT)||(slideType == BOTTOM)){
            componentOld = jPanels.remove(0);
            jPanels.add(componentOld);
            componentNew = jPanels.get(0);
        }
        最终诠释W = componentOld.getWidth();
        最终诠释H = componentOld.getHeight();
        最后点P1 = componentOld.getLocation();
        最终点P2 =新点(0,0);
        如果(slideType == LEFT){
            p2.x + = W;
        }
        如果(slideType == RIGHT){
            p2.x - = W;
        }
        如果(slideType == TOP){
            p2.y + = H;
        }
        如果(slideType == BOTTOM){
            p2.y - = H;
        }
        componentNew.setLocation(P2);
        INT步骤= 0;
        如果((slideType == LEFT)||(slideType == RIGHT)){
            步骤=(int)的(((浮点)parent.getWidth()/(浮点)Toolkit.getDefaultToolkit()getScreenSize()宽度)* 40.f);
        }
        其他{
            步骤=(int)的(((浮点)parent.getHeight()/(浮点)Toolkit.getDefaultToolkit()getScreenSize()高度)* 20.f);
        }
        步骤=步骤下; 5? 5:一步;
        basePanel.add(componentNew);
        basePanel.revalidate();
        如果(useLoop){
            最终诠释最大=(slideType == LEFT)|| (slideType RIGHT ==)? W:H;
            最终长T0 = System.currentTimeMillis的();
            的for(int i = 0; i =(最大/步)!我++){
                开关(slideType){
                    案例LEFT:{
                        p1.x - =步;
                        componentOld.setLocation(P1);
                        p2.x - =步;
                        componentNew.setLocation(P2);
                        打破;
                    }
                    案例RIGHT:{
                        p1.x + =步骤;
                        componentOld.setLocation(P1);
                        p2.x + =步骤;
                        componentNew.setLocation(P2);
                        打破;
                    }
                    案例TOP:{
                        p1.y - =步;
                        componentOld.setLocation(P1);
                        p2.y - =步;
                        componentNew.setLocation(P2);
                        打破;
                    }
                    案例BOTTOM:{
                        p1.y + =步骤;
                        componentOld.setLocation(P1);
                        p2.y + =步骤;
                        componentNew.setLocation(P2);
                        打破;
                    }
                    默认:
                        新的RuntimeException(ProgramCheck)的printStackTrace()。
                        打破;
                }                尝试{
                    视频下载(500 /(最大/步));
                }赶上(最终例外五){
                    e.printStackTrace();
                }
            }
            最终长T1 = System.currentTimeMillis的();
        }
        componentOld.setLocation(-10000,-10000);
        componentNew.setLocation(0,0);
    }
}
}

I have a menu that has a variety of buttons on display, I'm able to make the buttons call their respective JPanels when clicked. The thing is I would like to make the Jpanel slide in when its called instead of instantaneously popping in. I tried using tween engine and as Java beginner, I find it really overwhelming, so I decided to use timed animation. I was able to make the Jpanel on top to slide to one side but for some reason the next panel doesn't want to display, im really tired, can someone help please! There code is below:

public class Listener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {

        new Timer(0, new ActionListener() {
           public void actionPerformed(ActionEvent e) {                

              mainpane.setLocation(mainpane.getX() - 10, 0);
              if (mainpane.getX() + mainpane.getWidth() == 0) 
              {
                 ((Timer) e.getSource()).stop();
                   System.out.println("Timer stopped");
              } 
           }
        }).start();   
   } 
}

解决方案

Sliding panels can be tricky. Here is some starter code. Modify to fit your needs. Add error checking and exception handling as necessary.

This example uses JButtons and a JTree as content but you can use just about any type of content.

Usage:

static public void main(final String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            final JFrame jFrame = new JFrame() {
                {
                    final PanelSlider42<JFrame> slider = new PanelSlider42<JFrame>(this);
                    final JPanel jPanel = slider.getBasePanel();

                    slider.addComponent(new JButton("1"));
                    slider.addComponent(new JButton("22"));
                    slider.addComponent(new JButton("333"));
                    slider.addComponent(new JButton("4444"));

                    getContentPane().add(jPanel);
                    setSize(300, 300);
                    setLocationRelativeTo(null);
                    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    setVisible(true);
                }
            };
        }
    });
}

The impl is lengthy ...

package com.java42.example.code;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

public class PanelSlider42<ParentType extends Container> {

private static final int           RIGHT             = 0x01;
private static final int           LEFT              = 0x02;
private static final int           TOP               = 0x03;
private static final int           BOTTOM            = 0x04;
private final JPanel               basePanel         = new JPanel();
private final ParentType           parent;
private final Object               lock              = new Object();
private final ArrayList<Component> jPanels           = new ArrayList<Component>();
private final boolean              useSlideButton    = true;
private boolean                    isSlideInProgress = false;

private final JPanel               glassPane;
{
    glassPane = new JPanel();
    glassPane.setOpaque(false);
    glassPane.addMouseListener(new MouseAdapter() {
    });
    glassPane.addMouseMotionListener(new MouseMotionAdapter() {
    });
    glassPane.addKeyListener(new KeyAdapter() {
    });
}

public PanelSlider42(final ParentType parent) {
    if (parent == null) {
        throw new RuntimeException("ProgramCheck: Parent can not be null.");
    }
    if ((parent instanceof JFrame) || (parent instanceof JDialog) || (parent instanceof JWindow) || (parent instanceof JPanel)) {
    }
    else {
        throw new RuntimeException("ProgramCheck: Parent type not supported. " + parent.getClass().getSimpleName());
    }
    this.parent = parent;
    attach();
    basePanel.setSize(parent.getSize());
    basePanel.setLayout(new BorderLayout());
    if (useSlideButton) {
        final JPanel statusPanel = new JPanel();
        basePanel.add(statusPanel, BorderLayout.SOUTH);
        statusPanel.add(new JButton("Slide Left") {
            private static final long serialVersionUID = 9204819004142223529L;
            {
                setMargin(new Insets(0, 0, 0, 0));
            }
            {
                addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        slideLeft();
                    }
                });
            }
        });
        statusPanel.add(new JButton("Slide Right") {
            {
                setMargin(new Insets(0, 0, 0, 0));
            }
            private static final long serialVersionUID = 9204819004142223529L;
            {
                addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        slideRight();
                    }
                });
            }
        });
        statusPanel.add(new JButton("Slide Up") {
            {
                setMargin(new Insets(0, 0, 0, 0));
            }
            private static final long serialVersionUID = 9204819004142223529L;
            {
                addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        slideTop();
                    }
                });
            }
        });
        statusPanel.add(new JButton("Slide Down") {
            {
                setMargin(new Insets(0, 0, 0, 0));
            }
            private static final long serialVersionUID = 9204819004142223529L;
            {
                addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        slideBottom();
                    }
                });
            }
        });
    }
}

public JPanel getBasePanel() {
    return basePanel;
}

private void attach() {
    final ParentType w = this.parent;
    if (w instanceof JFrame) {
        final JFrame j = (JFrame) w;
        if (j.getContentPane().getComponents().length > 0) {
            throw new RuntimeException("ProgramCheck: Parent already contains content.");
        }
        j.getContentPane().add(basePanel);
    }
    if (w instanceof JDialog) {
        final JDialog j = (JDialog) w;
        if (j.getContentPane().getComponents().length > 0) {
            throw new RuntimeException("ProgramCheck: Parent already contains content.");
        }
        j.getContentPane().add(basePanel);
    }
    if (w instanceof JWindow) {
        final JWindow j = (JWindow) w;
        if (j.getContentPane().getComponents().length > 0) {
            throw new RuntimeException("ProgramCheck: Parent already contains content.");
        }
        j.getContentPane().add(basePanel);
    }
    if (w instanceof JPanel) {
        final JPanel j = (JPanel) w;
        if (j.getComponents().length > 0) {
            throw new RuntimeException("ProgramCheck: Parent already contains content.");
        }
        j.add(basePanel);
    }
}

public void addComponent(final Component component) {
    if (jPanels.contains(component)) {
    }
    else {
        jPanels.add(component);
        if (jPanels.size() == 1) {
            basePanel.add(component);
        }
        component.setSize(basePanel.getSize());
        component.setLocation(0, 0);
    }
}

public void removeComponent(final Component component) {
    if (jPanels.contains(component)) {
        jPanels.remove(component);
    }
}

public void slideLeft() {
    slide(LEFT);
}

public void slideRight() {
    slide(RIGHT);
}

public void slideTop() {
    slide(TOP);
}

public void slideBottom() {
    slide(BOTTOM);
}

private void enableUserInput(final ParentType w) {
    if (w instanceof JFrame) {
        ((JFrame) w).getGlassPane().setVisible(false);
    }
    if (w instanceof JDialog) {
        ((JDialog) w).getGlassPane().setVisible(false);
    }
    if (w instanceof JWindow) {
        ((JWindow) w).getGlassPane().setVisible(false);
    }
}

private void disableUserInput(final ParentType w) {
    if (w instanceof JFrame) {
        ((JFrame) w).setGlassPane(glassPane);
    }
    if (w instanceof JDialog) {
        ((JDialog) w).setGlassPane(glassPane);
    }
    if (w instanceof JWindow) {
        ((JWindow) w).setGlassPane(glassPane);
    }
    glassPane.setVisible(true);
}

private void enableTransparentOverylay() {
    if (parent instanceof JFrame) {
        ((JFrame) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
    if (parent instanceof JDialog) {
        ((JDialog) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
    if (parent instanceof JWindow) {
        ((JWindow) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
        parent.remove(basePanel);
        parent.validate();
    }
}

private void slide(final int slideType) {
    if (!isSlideInProgress) {
        isSlideInProgress = true;
        final Thread t0 = new Thread(new Runnable() {
            @Override
            public void run() {
                parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                disableUserInput(parent);
                slide(true, slideType);
                enableUserInput(parent);
                parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                isSlideInProgress = false;
            }
        });
        t0.setDaemon(true);
        t0.start();
    }
    else {
        Toolkit.getDefaultToolkit().beep();
    }
}

private void slide(final boolean useLoop, final int slideType) {
    if (jPanels.size() < 2) {
        System.err.println("Not enough panels");
        return;
    }
    synchronized (lock) {
        Component componentOld = null;
        Component componentNew = null;
        if ((slideType == LEFT) || (slideType == TOP)) {
            componentNew = jPanels.remove(jPanels.size() - 1);
            componentOld = jPanels.get(0);
            jPanels.add(0, componentNew);
        }
        if ((slideType == RIGHT) || (slideType == BOTTOM)) {
            componentOld = jPanels.remove(0);
            jPanels.add(componentOld);
            componentNew = jPanels.get(0);
        }
        final int w = componentOld.getWidth();
        final int h = componentOld.getHeight();
        final Point p1 = componentOld.getLocation();
        final Point p2 = new Point(0, 0);
        if (slideType == LEFT) {
            p2.x += w;
        }
        if (slideType == RIGHT) {
            p2.x -= w;
        }
        if (slideType == TOP) {
            p2.y += h;
        }
        if (slideType == BOTTOM) {
            p2.y -= h;
        }
        componentNew.setLocation(p2);
        int step = 0;
        if ((slideType == LEFT) || (slideType == RIGHT)) {
            step = (int) (((float) parent.getWidth() / (float) Toolkit.getDefaultToolkit().getScreenSize().width) * 40.f);
        }
        else {
            step = (int) (((float) parent.getHeight() / (float) Toolkit.getDefaultToolkit().getScreenSize().height) * 20.f);
        }
        step = step < 5 ? 5 : step;
        basePanel.add(componentNew);
        basePanel.revalidate();
        if (useLoop) {
            final int max = (slideType == LEFT) || (slideType == RIGHT) ? w : h;
            final long t0 = System.currentTimeMillis();
            for (int i = 0; i != (max / step); i++) {
                switch (slideType) {
                    case LEFT: {
                        p1.x -= step;
                        componentOld.setLocation(p1);
                        p2.x -= step;
                        componentNew.setLocation(p2);
                        break;
                    }
                    case RIGHT: {
                        p1.x += step;
                        componentOld.setLocation(p1);
                        p2.x += step;
                        componentNew.setLocation(p2);
                        break;
                    }
                    case TOP: {
                        p1.y -= step;
                        componentOld.setLocation(p1);
                        p2.y -= step;
                        componentNew.setLocation(p2);
                        break;
                    }
                    case BOTTOM: {
                        p1.y += step;
                        componentOld.setLocation(p1);
                        p2.y += step;
                        componentNew.setLocation(p2);
                        break;
                    }
                    default:
                        new RuntimeException("ProgramCheck").printStackTrace();
                        break;
                }

                try {
                    Thread.sleep(500 / (max / step));
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }
            final long t1 = System.currentTimeMillis();
        }
        componentOld.setLocation(-10000, -10000);
        componentNew.setLocation(0, 0);
    }
}
}

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

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