Profile Picture
Zoomed image.
Some annoying EU rule forces me to tell you
we might use cookies. The funny thing is by entering
most pages, it's already too late. So completely
useless. Good job, EU
Cookies are nothing dangerous and is just a way to
store data on your machine. Otherwise, how do we
know you are you?


Animation and Design Library


Work with Java Swing components in a cleaner and faster way!

The Animation and Design Library is a bit like jQuery for Java.
Write element.fadeOut(); instead of creating boring and time wasting while loops.


In this documentation we will be making a demo application.

WARNING: This documentation was made for an older version of this library.
It has been updated but might not be 100% correct

Animation and Design Library let's you use the normal Swing. This means, it will look the same. But if you want it to look like Windows there is a trick with UIManager you can use. However, we did it for you! All you have to do is to write DesignLib.makeOsLookAndFeel();.

Now let's make our frame. As said above we use Swing, but when you create Frames we have a few tweaks ;) We suggest you use Frame. But IMPORTANT! Take the one.krake import! Frame f = Frames.newFrame("Pigs: The history behind these wild animals"); Now, to this method there is various parameters to change the size and such, but the default size is 500x500.

Here comes two normal Swing lines we'll just dump here. I already know I suck at making documentations, thanks. f.setLayout(new FlowLayout());
JLabel l = new JLabel("The story of the world's most dangerous animals");

Now comes the fun part! Let's make our JLabel into our new, cleaner component: DC, short for Design Component. Do this via DC c = DesignLib.$(l);. One thing! You could actually just do DC c = DesignLib.$(new JLabel("The story of the world's most dangerous animals"));, all in one line. We will do that later, and with our DC it's quite few times we actually need the old component. Especially since you can do c.getComponent(); to get the good old Java component, which is usually enough.

With our DC we will now change font. Do c.font(20); to make it bigger. Here are some methods that exist with fonts:

Noticed that all of them (except one, which returns the font) return DCs? It's because you can stack many of the methods up. Such as frame.add(DesignLib.$(new JLabel("Hi")).font(20).getComponent());. All in a nice, beutiful line!

Now let's add it to the screen. Because we do have a JLabel we won't be using the getComponent method in DC. Instead we do it directly: f.add(l);. But now let's also add a link about these pigs ;) The Animation and Design Library comes with a JLink. It can show a link (obvious? ;)). This is the code we will be using: DC w = DesignLib.$(new JLink("As seen in Wikipedia", ""));. Then we'll hide and add it using f.add(w.hide().getComponent());. Yeah you get this now, I will fast forward a bit. We make a button too, saying next.

Now let's show our frame. All we have to do it f.makeVisible();. BAM!

We'll make our first animation now! First, hide our first component we added, the JLabel. c.hide();. Then let's schedule a fade in! Schedule with DesignLib#schedule(int seconds, Runnable task).
WARNING: The schedule method takes use of Swing timers and the delay might
not be accurate. For example 2 seconds might turn out to be 3. This is the
way Java Swing works, and not too much I can do about it. Animations should
be more accurate though, they don't run on the Swing thread. But that also means,
be careful with how you use it. You might need to use EventQueue.invokeLater.
I haven't needed to use that myself too much, though.

Fade in via c.fadeIn();. DesignLib.schedule(2, () -> c.fadeIn()); Good.

With DC#animateDone we can wait for a list of animations to be done. This is automatically done if you have two animations on the same DC. Let's do this! c.animateDone(() -> w.fadeIn());
w.animateDone(() -> next.fadeIn());

Now let's see what happens if we press the button I spoke of earlier. We have the DC#click method for this. -> {});. Now let's write anything inside the block!

However! I will let you explore that. The code will be posted below. Let your IDE check methods! Explore the JAR for functions! Or even ask in a forum. Or ask me on Skype ;) Chat with me on Skype

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JLabel;


public class Test{
  public static void main(String[] args){
    Frame f = Frames.newFrame("Pigs: The history behind these wild animals");
    f.setLayout(new FlowLayout());
    JLabel l = new JLabel("The story of the world's most dangerous animals");
    DC c = DesignLib.$(l);
    DC w = DesignLib.$(new JLink("As seen in Wikipedia"""));
    DC next = DesignLib.$(new JButton("Next..."));
    DesignLib.schedule(2() -> c.fadeIn());
    c.animateDone(() -> w.fadeIn());
    w.animateDone(() -> next.fadeIn()); -> {
      Alert.progress("Switching page...").go("Page 1/2..."100).animateDone(p -> {
        Alert.defaults().title_say("A friendly warning");
        Alert.err("Application crashed. All systems fail.");
        Alert.warn("GET OUTTA THE WAY""You computer is gonna blow.");
        Alert.say("Just a friendly warning :D");
        boolean outta = Alert.ask("So... Are you out of the way yet?");
        Alert.say(outta ? "Liar, since you could pressed OK." "THEN MOVE IT SON");
        Alert.say("Wait, false alarm.");
        Alert.say("Are you angry with me?");
        boolean mis = Alert.confirm("You are about to make a very big mistake and say yes.");
          Alert.err("WELL SCR** YOU");
          Alert.say("Thanks for cancelling that :D\nYou are not mine forever!\nWatcha think?");
          String s = Alert.prompt("What do you want to reply?");
          Alert.say("jk :D");