Swing JPanel实现动态滑动效果
来源:互联网 发布:怎么知道淘宝卖家地址 编辑:程序博客网 时间:2024/06/05 08:37
private static JPanel centerPanel=new JPanel();centerPanel.setLayout(null);//使用绝对布局//向左切换返回,panel为切换的页面public static void returnPanel(final JPanel panel) { int count = centerPanel.getComponentCount(); List list = new ArrayList(); for (Component comp : centerPanel.getComponents()) { list.add(comp); } if (!list.contains(panel)) { centerPanel.add(panel); } panel.setBounds(0, 0, centerPanel.getWidth(), centerPanel.getHeight()); if (count > 0) { for (int i = 0; i < count; i++) { Component comp = centerPanel.getComponent(i); if (comp instanceof JPanel) { final JPanel currentPanel = (JPanel) comp;//当前panel if (currentPanel != panel) { new Thread() { public void run() { Rectangle rec = currentPanel.getBounds(); int y = centerPanel.getWidth(); for (int i = 0; i >= -centerPanel.getWidth(); i -= 20) { //移动当前panel位置 currentPanel.setBounds(i, 0, centerPanel.getWidth(), centerPanel.getHeight()); //移动切换的panel位置 panel.setBounds(y, rec.y, centerPanel.getWidth(), centerPanel.getHeight()); try { Thread.sleep(5); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } y -= 20; } centerPanel.remove(currentPanel);//移除当前panel panel.setBounds(rec.x, rec.y, centerPanel.getWidth(), centerPanel.getHeight()); } }.start(); break; } } } } centerPanel.validate(); centerPanel.repaint();}//向右切换,panel为切换的页面public static void jumpTo(final JPanel panel) { int count = centerPanel.getComponentCount(); List list = new ArrayList(); for (Component comp : centerPanel.getComponents()) { list.add(comp); } if (!list.contains(panel)) { centerPanel.add(panel); } panel.setBounds(0, 0, centerPanel.getWidth(), centerPanel.getHeight()); if (count > 0) { for (int i = 0; i < count; i++) { Component comp = centerPanel.getComponent(i); if (comp instanceof JPanel) { final JPanel currentPanel = (JPanel) comp; if (currentPanel != panel) { new Thread() { public void run() { Rectangle rec = currentPanel.getBounds(); int y = -centerPanel.getWidth(); for (int i = 0; i <= centerPanel.getWidth(); i += 20) { currentPanel.setBounds(i, 0, centerPanel.getWidth(), centerPanel.getHeight()); panel.setBounds(y, rec.y, centerPanel.getWidth(), centerPanel.getHeight()); try { Thread.sleep(5); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } y += 20; } centerPanel.remove(currentPanel); panel.setBounds(rec.x, rec.y, centerPanel.getWidth(), centerPanel.getHeight()); } }.start(); break; } } } } centerPanel.validate(); centerPanel.repaint();}
0 0
- Swing JPanel实现动态滑动效果
- Swing实现动态切换Jpanel
- swing中JPanel如何实现分组框的效果以及设置边框颜色
- JAVA swing中JPanel如何实现分组框的效果以及设置边框颜色
- swing中JPanel如何实现分组框的效果以及设置边框颜色
- swing中JPanel如何实现分组框的效果以及设置边框颜色
- SWING Jpanel
- swing jpanel图片平铺
- SWING之JPanel
- java swing 更新JPanel
- java swing Jpanel
- Swing之JPanel
- MFC窗体滑动、缩放、渐变动态效果的实现
- MFC窗体滑动、缩放、渐变动态效果的实现 .
- Android实现仿网易首页选项卡动态滑动效果
- jQuery实现滑动效果
- 实现页面滑动效果
- ScrollView实现滑动效果
- web网络安全——网站入侵(二)
- python 中的time
- 数据结构之带表头的单链表
- Java中的泛型方法
- Galera replication for MySQL(包括Galera replication原理)
- Swing JPanel实现动态滑动效果
- Java程序的设计思想
- 基于SLR文法,将输入串翻译成三地址代码序列
- 分布式多级缓存中间件引导实践
- 写简答题
- C语言 - 分解字符串函数分解英语句子
- web网络安全——网站入侵(三)
- 分布式hadoop【CentOS7】
- 自定义ProgressDialog的实现