开发者

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 i开发者_运维百科s 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜