Where is the ClipboardContent class in JAVA? - java

Though a Java novice, I managed to import plain text from the clipboard (sourced in Excel). It looks like the ClipboardContent class would allow me to import formatted text (html, xml...) but my attempts so far always result in "class not found" for any reference to ClipboardContent.
I suspect there's an import (or full reference) that will fix this but my references and on-line searches have not been fruitful so far.
I'll appreciate any clues I can get.

Java has some pretty great documentation online.
here is where you can find anything about that you could need that has to do with basic java's classes. I recommend going here using a ctrl+F for whatever class you need and click on it. on that page it will give you everything you need to know about it.

javafx clipboardcontent api
Make sure you import "javafx.scene.input.ClipboardContent" (assuming this is what you need).
Just a FYI - you can run into cases were you find similar or identical named classes in other packages. If you are using Eclipse IDE, you can hover over an class object and it will provide you a hint on where to import it from if Eclipse has those dependencies. If it doesn't have it, then you will need to add that dependency (like a jar file) and add it as part of your library.

Related

is there anything in java like header files in C/C++

In C, there is this concept of header files that lets you include the header files required for most of the program in one go and so you can only import that one header file in each of your program. I find this pretty neat. Now, I have been working in JAVA for a while and afaik I cannot group together a set of imports that I require for almost every file and put them in one. Am I wrong? And is this better than putting all the required bunch in one java file.
There's no such thing. If you require a class from another package (that isn't in java.lang), you'll have to import. But that's practically trivial when using a proper IDE. In Eclipse or NetBeans, you're usually one key combo away from fixing your imports.
There's no equivalent to header files in java, however you can import whole packages:
import mypackage.*

Is there a better way to view un-attached source class decleration in Eclipse?

When looking at a class declaration that has no attached, why is it not in plain text allowing it to at least be searchable. Is there a way to view this output in a search format?
Please let me know of a plugin. Thx
If I understand what you are asking here, if you are referring to a class file, then no. You would need to import the source code as a plugin. As an example, take a look at this tutorial
The "Outline" View will display the structure of the class, even if no source is attached, so you can at least see all the class' members, including parameters and return types. The View also has some sorting and filtering abilities, so it might help to find the info you're looking for.
Another option would be to plugin a decompiler, which should open up class files as source files "on the fly". I don't use any personally, but just Google "eclipse decompiler" and see which one you like.

How to download the edu.mit.sketch.geom libraries

On the Java API, I see references to packages named "edu.mit.sketch.geom." I'm looking for some advanced geometry libraries (mainly collision interpretation), and after a brief overview of the methods contained the package is looking really good, and I'd like to try it out.
However, I can't find any downloads. It doesn't appear to be in the standard Java library, and I'd like to package it as a jar in my project, but a few Google searches return references to the package but no download.
Does anyone know where I can get it?
I Google'd around a bit and the only place I could find what looks like the toolkit you want was on the handouts page of the 6.893 course at MIT: direct link; there doesn't seem to be a project site, at least, not a public one.

How to add automatically the imports in a Java project?

I generate (from a progam java) some Java classes but actually, I don't add the import in each class. I'd like to have a kind of parser that is able to see which import needs to be added in a class. Maybe, it's possible to reuse the fonctionnality of Eclipse because it's able to do that. However, I don't know where I can find that.
Do you have any idea?
Many thanks,
Bat
What about using only Full Qualified Names for classes when creating the code for the generated Java classes?
What are you going to do about name collisions? You use a "Date" - is it java.util.Date or java.sql.Date? You use a "XMLFoo", is it com.foomatics.XMLFoo or is it org.openfoo.XMLFoo? It's better to add the imports as you add the code.
Maybe you can create a HashSet of all the imports you're going to need as you generate the code, and then add them in at the top when you're done?
I see now... the problem is definitely on your generator. Work on that because even if you can extract the functionality from Eclipse, you won't get a 100% working solution every time. So my suggestion is just forget it and fix your generator.
As Paul said, you have to decide the imported class yourself. I usually type on Eclipse and at the end of the class I press Ctrl+Space to get some suggestions. So, for example I want to have java.util.Date, I will write Date and then Ctrl+Space and select java.util.Date and Eclipse will automatically import java.util.Date for me.
If the code is already there, I will do quick fix (F1 on Eclipse) and it will also suggest some fixes to the code I have (one of them is to import the suitable class).

Where can I find the source code of the "build" classes in Java?

In the beginning of my Java code I have:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
And then I have the following:
public class KeyEventDemo extends JFrame
implements KeyListener,
ActionListener
I am trying to understand what the code does. And I started from the beginning. For example I want to know there the class JFrame is defined (I think it belong either to "java.awt.event" or "javax.swing" package. I also would like to see hot the interface KeyListener is defined.
My problem is that I do not know where to find the corresponding source code. I tried the following:
locate event | grep awt
Nothing was found. Can anybody help we with that, pleas.
Do you have access to an IDE (such as Eclipse or Intellij) ? It will help enormously with navigating around your code, and that of the JDK. If you're not using one already I'd strongly recommend it.
For your particular question, the awt classes are part of the JDK package. You'll need the JDK source code. You can download version 6 source code here.
The source code doesn't always come with java, just the compiled classes. However you don't really need the source code, you need the description of the interfaces/classes used. These are called API documentation.
Here is the java api documentation for java 5:
http://java.sun.com/j2se/1.5.0/docs/api/
There is usually a file called src.zip which contains all the source code - try unzipping that, or pointing your IDE at it, and looking in there.
The source code can usually be found in a file called src.zip that is found inside your JDK installation directory. At least that's true for the Sun JDK.
Unless you download from code providing website,you cant see its code.
You can use Decompiler for looking at thecode from the build files
One thing to consider is that it's generally considered bad practice to use an import such as
import javax.swing.*;
Instead, try:
import javax.swing.JFrame;
and do one import statement per class that you need. This improves maintainability. It will also help you figure out exactly what classes you need to look up in the API. I would definitely agree that you should start with the API over the source code. The Swing source code is, in my experience, more complex to navigate through than the Swing Javadoc. What you want to do is check out the Javadoc for JFrame, KeyEventListener, and ActionListener. Sun's Swing Trail is also helpful in looking at the hows and whys, especially when it comes to events.

Categories