AlexSavAlexandrov
AlexSavAlexandrov

Reputation: 873

Java: How to open a library?

I want to open libraries, because currently I want to see the algorithms used for drawing, modify them and implement them in my program. For example: I have tried to create an algorithm on my own for lines. But I failed. And even if I had succeeded, I fear that it might not give the same result as the algorithm in the libraries. And I don't want this to happen. That's why I want to copy the algorithms used for the methods in libraries. And I really hope that this will help me create the application I'm currently working on and with other applications in the future.

I tried to open the libraries with a code editor. But I had troubles finding the libraries- I don't really know where are they placed nor in what files are their codes stored.

How to open a Java library? Or is there a place in the Internet where the code is uploaded?

Upvotes: 0

Views: 2559

Answers (4)

Russell Zahniser
Russell Zahniser

Reputation: 16364

It sounds like what you want is to get inside the standard Java libraries (so you can see the code for methods like Graphics.drawLine()).

You can download the source files from the same place you got the JDK, if you are on Windows or Linux. For the Mac, see this question. You can even set up Eclipse so that you can debug into that source as if it were your own code.

However, you will probably not find line-drawing code in Java in these libraries - the Graphics implementation will almost certainly use native methods, and may just call existing methods in the OS.

If you are specifically looking for line drawing algorithms, another option would be to look at the Wikipedia page for the Bresenham (aliased) or Wu (antialiased) algorithm.

Edit:

The part of a Graphics2D call that actually puts pixels on the screen is probably inside a system call and therefore the source would not be available.

A java vector graphics library like Batik might have source for some of these algorithms, but probably relies on the Graphics2D calls for most of them. So, you might look for a comprehensive vector graphics library written in a language other than Java, where those graphics calls do not already exist by default.

Alternately, checking the table of contents for a computer graphics book might point you at a variety of algorithms that you could look up on Wikipedia.

Upvotes: 4

durron597
durron597

Reputation: 32343

For any given library:

Make sure to obey all licenses when using another's code

  • If you are referring to the Java SDK source code, you can find it here: http://grepcode.com/
  • If the project is open source, you can usually just get the source from the project website. No problem, though make sure to obey their license.
  • If the project is NOT open source, well, then you're in a pickle licensing wise, so I do NOT endorse this, however, you would need to use a Java Decompiler such as JD-Gui

As far as what drawing algorithms to use, there are so many different ones (obviously, people have been trying to draw quickly for many many years), your best bet is to figure out exactly what you need to do and then search for that specific need separately. There isn't really a good repository of ALL of them, except maybe wikipedia.

Upvotes: 2

If you are trying to look at a standard Java library, see the other answers about getting the source to the JDK.

If you are interested in an open source library (such as something maintained by the Apache project), look on the site of the project for a 'source jar' which you can open with a standard zip utility.

If the library you want is not open source or you cannot find the source for it, you can try to decompile it. If you are using Eclipse, try this decompiler.

Upvotes: 0

Garrett Hall
Garrett Hall

Reputation: 30032

If you are using the libraries they are on your classpath. Check out how to figure out your classpath in whichever IDE you are using and you can find the JARs you depend on. If they are packaged with sources all you need to do it unjar them and look at the sources.

If you don't have access to the sources you can get the code using a Java Decompiler.

Upvotes: 1

Related Questions