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?
问题:
回答1:
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:
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 :)
回答2:
This is a typical animation use case. The easiest way is to use animation framework. I'd suggest Trident
回答3:
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.
回答4:
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.