In Adobe After Effects there is something called a "pick whip". It allows you to click on a dot on one object and drag a line from that dot to another element, making a connection between the two. I would like to duplicate this feature in my Java program using swing. I honestly have no idea where to start.
If I've done a bad job explaining what I mean, please comment so I can improve it. If there is some way outside of Swing to do this, I'm willing to try it.
Here are some examples of what I am trying to achieve:
LinePanel illustrates how to animate the line as it is rendered, but you'll have to paint on the glass pane or among JLayeredPane instances to see the line above existing components.
Related
I'm making a launcher for a game I'm developing and I use Graphics2D to render buttons, gui etc. Now I've extended the class that does this (Launcher.java) with the Canvas. This means I can't use JTextFields (plus it would look ugly anyway). So my question is, how would I make a text field without the use of JTextField, this means rendering it, getting key input display the input.
Thanks.
You state: I'm making a launcher for a game I'm developing and I use Graphics2D to render buttons, gui etc.
You seem to be re-inventing the wheel. Why not instead use or create a Look and Feel that works well.
You state: Now I've extended the class that does this (Launcher.java) with the Canvas.
By committing to AWT components you are unnecessarily limiting what you can do. Why not just stick with Swing components?
You state: This means I can't use JTextFields
You can if you stick with Swing.
You state: (plus it would look ugly anyway).
Without images, it's hard to discuss this point.
You state: So my question is, how would I make a text field without the use of JTextField, this means rendering it, getting key input display the input.
Again, why commit to re-invent the wheel? Use Swing components including JTextFields, avoid AWT, and if you still feel the GUI is ugly, consider posting images and a small compilable and runnable program that we can mess with and that shows us directly your problem.
I'm sorry this is probably way too basic to be on here, but it's a subject I've been struggling with for about a month now and I don't know where else to go (as far as I know there is no "noob overflow", lol).
I'm trying to create a class that would:
1. put an image on a window (a JFrame, JPanel or other container)
2. be able to support keyboard and mouse listeners
3. could have multiple instances in the same container
So anyway I've tried all the usual places - Google, YouTube, the official Java site (sorry forgot the URL) and of course here on Stack Overflow - but haven't been able to find anything even remotely similar to what I'm trying to do.
Of course, I've also considered the possiblity that maybe it can't be done at all. There doesn't seem to be any kind of standard "JImage" or "JGraphic" that works like JButton or JLabel, and for whatever reason graphics requires a completely different list of (extremely involved) processes and procedures. As an example, in this post: How to "really" draw images in a Java app - it took me 60+ lines of code and 2 classes to just come close. That project didn't work in the end because for some reason it would only let me create one instance (even it you created 2-4 in the main method, it would only display the last one you told it to add).
But anyway, assuming that I'm not trying to "re-invent the wheel" here and it is actually possible (in Java), does anyone have an idea as to how (or at least know of a better site to study it)? Unfortunately most of the sites I've visited tend to assume you know all the inner workings of images (I know what a pixel is but that's about it - Buffers, Rastars etc. are still beyond me). It would be absolutely outstanding if there were a site that would explain it in layman's terms, if such a site exists. Thanks in advance.
Just use a plain old JLabel.
Regarding your requirements:
put an image on a window (a JFrame, JPanel or other container).
You can give a JLabel an ImageIcon of the image of interest and it will display it. This can then be easily placed in any other container such as a JPanel or JFrame.
be able to support keyboard and mouse listeners
Any component that extends JComponent, such as a JLabel allows for use of MouseListener, MouseMotionListener and can listen for keyboard input via Key Bindings.
could have multiple instances in the same container
You can add as many as you'd like to any container. Just be cognizant and respectful of the layout managers in use.
I have a question.
I just started with Java and may have some small basic things. Now I wonder how a kind of pages (sections) in a program makes.
I do not mean some kind of tabbed panel, or if you click on a button that a text is visible.
I mean that for example all over the screen a separate part of the program looks. As the main menu of a game.
There is nothing else than the main menu visible at that time. If you for example a button from that menu click. The game is loading.
(I'm using the building of a standard game as an example)
If you for example the main menu click on another button (eg "Settings")
Then wort settings "page" is visible, and there is nothing else that the program is really doing.
I do not know how this type of navigation is called. But almost every program does have something.
How can I do this too? What should I do for example, as a new file, import the classes of a particular page, or something?
You seem to be searching for CardLayout. As shown here.
I think you should look for "state machines", which is a way for structuring your code, and implement your menu changing swing components (like JPanel, for example) in a JFrame. If I understand what you want, I think this can be an option.
There is no short answer, but based on your question, you need to read alot. I would suggest the swing tutorial It explains use of Panels, Frames, Layout managers and other containers.
You can also use the Matisse builder in netbeans (relevant plugin in eclipse)
In all my time so far working with Java and its Swing GUI framework, I've never quite figured out (or even attempted to try) how to make the interface animate components.
Say I wanted the screen to slide left into the next screen or have a JLabel "fly" to a new location. Perhaps you want a menu to smoothly open in an animated fashion. How does this work?
Do you have to use SwingWorker? Even if that's the case... how can you control the painting of components if the layout manager is already doing that?
Have a look at the book Filthy Rich Clients, you will find some really good answers there.
I think that there no reason for use SwingWorker, SwingWorker is designated for running long Backgroung Task(s) on output would be on Event dispatch Thread,
For animations in Swing is there javax.swing.Timer, examples here
Take a look at Trident library. You can use it to interpolate various properties in your class.
Is there any way to create a custom component in swing. By custom I mean say right now I am able to create a circle and do actions like dragging it etc.
But now I also want that along with the circle a text label with its number is also present. Can we combine them into a new type of component where say we can do actions on it collectively?
If yes please give me pointers on how to do so.
Yes, just extend JComponent and handle painting and interaction however you want. If there is a component that already does most of what you want you could extend that class and tweak it slightly.
I would suggest reading some of the tutorials about how JComponent works:
http://download.oracle.com/javase/tutorial/uiswing/components/jcomponent.html
Here is a similar question but I am sure you can find more specific ones that have been asked once you get deeper into it.
How to create a custom Swing Component
The Swing tutorial as a whole if very useful to understand how other components work etc.
http://download.oracle.com/javase/tutorial/uiswing/components/index.html
You can create your own Swing component extending JComponent. Several question here on Stack on the topic like this one.
Personally, I advise you to get this book: Java Swing as it contains an excellent guide on how to create Swing components.