Java swing choppy animation: PLEASE HELP

jklh;j
Edited by: 806886 on Nov 2, 2010 5:21 AM

Hi, [url http://forums.oracle.com/forums/ann.jspa?annID=1391]Welcome to the new home(Announcement:the code tags)
Sorry to change the subject, but your code seems to cause an IllegalArgumentException:
//RGB[0] = random.nextInt(255);
//randomizeColor[0] = 1+random.nextInt(3);
//randomizeColor[0] = 1+random.nextInt(3);
//randomizeColor[0] = 1+random.nextInt(3);
randomizeColor[0] = 1+random.nextInt(4);
randomizeColor[1] = 1+random.nextInt(4);
randomizeColor[2] = 1+random.nextInt(4);
//ball colors change
//for (int i = 0; i < RGB.length; i++)
//    if (RGB[i] >= 250 || RGB[i] <= 4)
//        randomizeColor[i] = -randomizeColor;
//RGB[0]+= randomizeColor[0];
//RGB[1]+= randomizeColor[1];
//RGB[2]+= randomizeColor[2];
for (int i = 0; i < RGB.length; i++) {
RGB[i] += randomizeColor[i];
if(RGB[i]>255) {
RGB[i] = 255;
randomizeColor[i] = -Math.abs(randomizeColor[i]);
}else if(RGB[i]<0) {
RGB[i] = 0;
randomizeColor[i] = Math.abs(randomizeColor[i]);
color = new Color(RGB[0],RGB[1],RGB[2]);
Edited by: aterai on 2010/11/02 19:52                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How do i invoke Windows APIs in JAVA??? Please help.

    Is there a way to invoke Windows APIs in Java??? Please help......Thankx

    Short answer, you don't. However, you should look at Java Native Interface (JNI) very closely. It will allow you to wrap the Win32 API calls so that Java can call your wrapper methods. Another side to it, although not necessarily related to your question is a JavaBeans to COM bridge that you may want to look into as well, though it's probably not going to be a solution for what you're wanting to do right now.

  • Java.lang.UnsatisfiedLinkError - Urgent please help

    Hi,
    I want to thank you for looking into this problem first.
    I have a very headache problem for the past week. I have an applet that uses JNI to call an existing dll to get the system resources. It works fine on windows 2000 server with IE 5.0. The dll get loaded fine and the function call is working fine.
    However, now I tried to move the applet to an application for me to test with jbuilder, I have problems and I get the error java.lang.UnsatisfiedLinkError: ooInit.
    Does anyone know why this is happening in Jbuilder. I traced to see if the dll get loaded with System.loadlibrary("dll"), and it seems to load the library. But when I call the ooInit() native method, it throws that exception.
    Please help. This will be greatly appreciated and I can do something for you guys in return.
    Thank you so much.
    Regards,
    guna

    Here, for the benefit of others who might search for this, is my approach to resolving this error.
    Two things to note:
    1. I didn't worry about paths, etc. - I was in a hurry so I just copied files into required directories.
    2. I named both the Java and C files "mainFrame". I have not subsequently checked to see if this is required, since it worked for me.
    Summary of getting jni routine to work with Jbuilder:
    created Java project mintest, two principle classes - mainFrame and WelcomeFrame
    key code fragments:
    --------------------------------------- mainFrame --------------------------------------------------
    package mintest;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import java.awt.GridBagLayout;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseAdapter;
    public class mainFrame {
        boolean packFrame = false;
        WelcomeFrame frame = new WelcomeFrame();
        public static native int cRoutine(int value);
        static {System.loadLibrary("mainFrame"); }
    public mainFrame() {
        //Pack frames that have useful preferred size info, e.g. from their layout
        //Validate frames that have preset sizes
        if (packFrame) {
          frame.pack();
        else {
          frame.validate();
        // Center the frame
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
          frameSize.height = screenSize.height;
        if (frameSize.width > screenSize.width) {
          frameSize.width = screenSize.width;
        frame.setLocation( (screenSize.width - frameSize.width) / 2,
                          (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);
        try {
          jbInit();
        catch (Exception ex) {
          ex.printStackTrace();
    * Main method
    * @param args String[]
    static public void main(String[] args) {
      try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      catch (Exception e) {
        e.printStackTrace();
      new mainFrame();
            cRoutine(1);     // this works at this point...
            System.out.println("cRoutine - should be 4: " + cRoutine(3));
      private void jbInit() throws Exception {
    }--------------------------------------- end of mainFrame --------------------------------------------------
    --------------------------------------- (portions of) WelcomeFrame --------------------------------------
    package mintest;
    import java.awt.*;
    ..... more imports, setting up of window, buttons, etc. .... iValue is an integer....
      public void jToggleButton1_mousePressed(MouseEvent e) {
          jToggleButton1.setText("cRoutine in: " + iValue + "  out: " + (iValue = 
                                   mainFrame.cRoutine(iValue)));
      }--------------------------------------- end of (portions of) WelcomeFrame -----------------------------
    mainFrame was compiled with Jbuilder into a class file, makeFrame.class. That was copied into
    the C:\Borland\JBuilder2005\jdk1.4\bin directory, and javah was run to create the C header file:
    javah -jni mainFrame
    This generated:
    --------------------------------------- mainFrame.h generated by javah ----------------------------------
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class mainFrame */
    #ifndef _Included_mainFrame
    #define _Included_mainFrame
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     mainFrame
    * Method:    cRoutine
    * Signature: (I)I
    JNIEXPORT jint JNICALL Java_mainFrame_cRoutine
      (JNIEnv *, jclass, jint);
    #ifdef __cplusplus
    #endif
    #endif--------------------------------------- end of mainFrame.h generated by javah -------------------------
    OKAY, HERE COMES THE CRITICAL STEP. DESPITE THE FACT THE COMMENT SAYS DO NOT EDIT, THIS FILE HAS TO BE EDITED TO INCLUDE THE PACKAGE NAME, LIKE THIS:
    --------------------------------------- modified mainFrame.h ----------------------------------
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class mainFrame */
    #ifndef _Included_mainFrame
    #define _Included_mainFrame
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     mainFrame
    * Method:    cRoutine
    * Signature: (I)I
    JNIEXPORT jint JNICALL Java_mintest_mainFrame_cRoutine
      (JNIEnv *, jclass, jint);
    #ifdef __cplusplus
    #endif
    #endif--------------------------------------- end of modified mainFrame.h -------------------------
    This file is then copied to the C:\Borland\BCC55\Include directory. The C code source is placed
    in the C:\Borland\BCC55\Bin directory. Here is the C code - note that it has the package name in
    the function name:
    --------------------------------------- mainFrame.c ----------------------------------
    #include <mainFrame.h>
    #include <stdio.h>
    #include <string.h>
    /* must link gpib-32.obj for Windows*/
    #include <windows.h> /*if using Windows */
    void main(){
    JNIEXPORT jint JNICALL
    Java_mintest_mainFrame_cRoutine(JNIEnv *env, jobject callingObj,jint invalue)
    return (jint) invalue+1;
    }--------------------------------------- end of mainFrame.c -------------------------
    This is now compiled on the command line (from the C:\Borland\BCC55\Bin directory) using:
    bcc32 -tWD -I\Borland\bcc55\include -L\Borland\bcc55\lib mainFrame.c
    Parameters: -tWD creates Windows DLL file
    -I is path to include directory (this is where mainFrame.h is located)
    -L is path to library directory
    Compilation produces mainFrame.dll in the C:\Borland\BCC55\Bin directory. This is copied to the C:\Borland\JBuilder2005\jdk1.4\jre\bin directory so Jbuilder can find it. Then it works.
    So, the key step is adding the package name after javah has generated the header file (and similarly using the package name in the .c source file.)
    Hope this is useful.

  • I need help with animation, PLEASE help!

    I am trying to create pacman animation by using a series of filled arcs that I create by coding in java. I know how to create the arcs, but I don't know how to use them to create animation. In other words I don't know how to put them in sequence to create animation.
    I have searched the web, and all I find is animation that use a series of GIF or JPEG images.
    can you please help me or point me to the right direction.
    by the way, which of these two animation would run faster? The one that uses GIF images, or the one that would use shapes created in java?
    Thanx

    Perhaps you could do this two ways
    One way, (im not sure if this will work), is to create a .gif file that is already animated. An open mouth animated to a closed mouth. But i don't know if Java will accept this.
    The second way would be to create a Thread. And to create however many images you want to display the open to closed mouth. Then continuously change the image so it appears the mouth is opening and closing.
    Put in a delay so it doens't go too fast, and there ya have it.
    Public void run()
    int i =0;
    while(true)
    myThread.sleep(10);
    image = difImage;
    }something like that. Might used a bufferedImage and make just use subImage to pull off each picture you need to change.

  • Java mail api error- Please Help

    Hi, i have set up an smtp server on my local machine. i have given the smtp host address as 127.0.0.1
    I am getting the following error though. please help me out with the problem
    C:\trainee>java Emailer
    javax.mail.SendFailedException: Invalid Addresses;
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at Emailer.sendEmail(Emailer.java:151)
    at Emailer.main(Emailer.java:194)
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    ... 5 more
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    ... 6 more
    Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected]
    ... 6 more

    It's a configuration error in your smtp server.
    See the JavaMail FAQ for more information.

  • Chess: Java Swing problem!! Help need

    Hi, I have just learn java swing and now creating a chess game. I have sucessfully create a board and able to display chess pieces on the board. By using JLayeredPane, I am able to use drag and drop for the piece. However, there is a problem which is that I can drop the chess piece off the board and the piece would disappear. I have try to solve this problem by trying to find the location that the chess piece is on, store it somewhere and check if the chess piece have been drop off bound. However, I could not manage to solve it. Also, I am very confuse with all these layer thing.
    Any suggestion would be very helpful. Thanks in advance

    I wonder if you are biting off a little more than you can chew. This seems like a big project for a beginning coder. Anyway, my suggestions can only be general since we only have general information:
    1) Break the big problem down into little pieces. Get the pieces working, then put them together.
    2) Make sure your program logic is separate from your GUI.
    3) If still having problems, post an SSCCE. See this link to tell you how:
    http://homepage1.nifty.com/algafield/sscce.html
    4) And as camikr would say (and flounder just said): next time, post this in the Swing forum.
    Good luck!

  • Runtime Exception.... NOOB JAVA PROGRAMMMER HERE. PLEASE HELP!

    Hey Oracle ppl,
    I'm a real n00b Java programmer, just learning Java through SL-275-SE6. So, here's a small program that I created, but I get this runtime exception while running it in NetBeans v7.1:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    Here's the source code:
    import java.io.*;
    import java.sql.*;
    public class Expenses {
    void DataBaseInteract() {
    try {
    Connection con;
    Statement st;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:Expenses");
    st = con.createStatement();
    st.execute("create table Expenses(DateofTransaction String, Amount float, Remarks String)");
    DataInputStream in1 = new DataInputStream(System.in);
    System.out.println("Enter today's date, in the format DD/MM/YYYY.");
    String DateofTransaction = (in1.readLine());
    System.out.println("Enter today's transaction amount, ");
    float Amount = Float.parseFloat(in1.readLine());
    System.out.println("Enter remarks, if any:");
    String Remarks = (in1.readLine());
    st.executeUpdate("insert into Expenses values("+DateofTransaction+", "+Amount+", "+Remarks+")");
    con.close();
    catch(Exception e) {
    System.out.println(e);
    public static void main(String[] args) throws Exception {
    Expenses obj = new Expenses();
    obj.DataBaseInteract();
    Please help! I really want this program up and running!!!

    better you can get help from http://forums.netbeans.org/
    eventhough.
    here some inputs,
    http://www.justskins.com/forums/too-few-parameters-expected-80937.html

  • How to send response message from Java mapping class? Please help!

    Hi Experts,
      I have a sync scenario
              -Req-->  -
    >
    SOAP           XI       RFC
              <Res--     <-----
      The Req message contains:
      <Order>
           <Orderid>100</Orderid>
           <Desc>Extrenal Order</Desc>
           <Qty>2500</Qty>
      </Order>
      Response message is:
      <Log>
         <LogTxt>Qty value cannot be more than 3 chars</LogTxt>
      </Log>
      In the XI I have to validate the input request message using a schema. For this I am writing a java mapping program using aii_map_api.jar.
    My requirement is that If the input message schema validation fails then I want to send a response message back to sender.
      How can I send a response message back to the sender in java mapping program?
    Kindly help with sample code example.
    Thanks
    Gopal

    Hi,
    First, I think PI 7.1 has this functionality and perhaps it comes in a SP for PI 7.0 and XI 3.0.  So first have a look at that before creating custom development.
    Second, if you use the java mapping, you will only have access to a request or response message.  I would advise using a custom java module in the module processor and insert this message in the sender communication channel.  This will allow you to validate request and send a response.
    Regards,
    Yaghya

  • Swings Urgent Requirement, Please Help me

    Hi ,
    I have a requirement like when a file dialog is displayed, I have to select only directories/folders. Now with using JFileChoser , I am able to choose file . Is there any possibility to choose only directories without file dialog or atleast by using filedialog?. If some solution Please help me as this is urgent requirement.
    Thanks and Regards,
    Rajeev L.

    JFileChooser has an instance method public void setFileSelectionMode(int mode)
    call when initialising the file chooser.
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );

  • Swing Arrays! Please help!!

    how do you assign the values of an array to another array?
    example:
    String A[] = {"a","b","c"};
    String B = {};//initial as an empty array
    String text;
    if text == null
    how do you assign the values of array A to array B;
    Please help
    Thanks in advance

    This should work
    String[] A = {"a","b","c"};
    String[] B = null;
    boolean condition = true;
    if (condition)
    int size = A.length;
    B = new String[size];
    for (int i = 0; i < size; i++)
    B[i] = A;
    note that the B array size is not dynamic, you have to allocate memory when you come to know what size it should be. If you don t want to worry about these array problems, you can use a Vector or an ArrayList.

  • Moving a TextField in Swing.Possible?please help

    Hi all,
    I'm working on this application to create textfields in a page and resize and reposition them as necessary using the mouse(Just like dragging and dropping components in Visual Basic). Is it possible to provide such a functionality for a Textfield in java? If so how? If you do have some reference sites, please let me know. Any help will be appreciated. Thanks.

    Hi,
    if you just need a simple framework:
    I've created a customizer framework for such tasks: Move and resize components with the mouse and allow further customizations. "Snap-to-grid"-feature included! Maybe you find it useful as a base. (It's open source!)
    I started to write a tutorial (still under construction!):
    http://softsmithy.sourceforge.net/lib/docs/tutorial/swing/customizer/index.html
    For adding components see:
    http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/CustomizerBar.html
    To customize properties use:
    http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JCustomizerPropertyTable.html
    Register it to the SelectionManager of the JCustomizerPane and set the CustomizableProperties-property of the JCustomizer objects.
    Also have a look at the subclasses of JCustomizer.
    E.g. there are
    customizers for images & shapes:
    http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JXIconCustomizer.html
    a label customizer with inline editing:
    http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLabelCustomizer.html
    a line customizer:
    http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLine2DCustomizer.html
    And there are many classes providing support for menu- and toolbar-actions. (Incuding support for some of the "Java Look and Feel Graphics Repository" actions.)
    Look at the *.swing and the *.swing.action packages.
    Just ask me if you don't find them.
    Homepage:
    http://www.softsmithy.org
    Download:
    http://sourceforge.net/project/showfiles.php?group_id=64833
    Source:
    http://sourceforge.net/svn/?group_id=64833
    http://softsmithy.svn.sourceforge.net/viewvc/softsmithy/trunk/lib/src/org/softsmithy/lib/
    API:
    http://softsmithy.sourceforge.net/lib/docs/api/index.html
    If you have questions just ask me!
    -Puce

  • Java program in XP - Please Help

    Hi, I am not sure if I am in the right fourm. I am not a developer, but a network engineer trying to help out my wife. My wife uses a java program to monitor the company she works for web site, which is not linked to a web browser. When she received the java program, it came with Java 1.2.2. Our PC had Windows 98 installed. I purchased a new machine, with Windows XP on it, and installed the java program and JRE on to it. The program does not work. The programmer who wrote the program was fired a few months ago, so I started looking through the internet, and the Sun fourms for a solution. First, the XP machine does not have Microsoft VM on it. Second, I upgraded the java to 1.4.1_02, following the instructions, still with no success. There was a suggestion to dual boot with Windows 98, but I really do not want to do that. What happens is - when you log in to the program, it just freezes. It does not go into the server. Any help is greatly appreciated.

    Possible reasons for the program hanging up
    1) The version of the VM on the machine is not correct.
    2) Even if the version is correct and correctly installed, can you please check whether the PATH and CLASSPATH variables are set correctly on the machine where you are running the program.
    3) I use WINXP as well with the latest version of VM downloaded from Sun and NOT Microsoft.
    Hopefully this might solve the issue.

  • Java Question... please help

    I am running  Snow Leopard  (mac os x version 10.6.8)
    For the past couple of years I've played gin in yahoo games.  
    Yesterday when I entered the gin lobby ...the font was so tiny
    I wasn't able to read it.   I checked Java on my computer and
    it is enabled, however I just realized when I go into the gin
    lobby... there is no java icon on the dock.   Since the font size
    is fine in all other applications, I am presuming this is a Java
    issue.  
    Help if you are able.. please and thanks

    Huh? Is this a Java question? Where's the Java? I just see a little JavaScript. Do you know how to use servlets and JSPs?
    Jesper

  • Okay so i had an iphone 5.  I backed it up on icloud. Then i got the new iphone 5s i restored ot from icloud from my previous iphone 5.  Now everything works find execept now the games are slowy and drops the frame rate and look choppy. Please help.

    Okay so i had an iphone 5.  I backed it up on icloud. Then i got the new iphone 5s i restored ot from icloud from my previous iphone 5.  Now everything works find execept now the games are slowy and drops the frame rate and look choppy. Then i restarted my iphone 5s as a new device downloaded the same apps even the ones optimized for ios 7 and the games still lag. And i just got my iphone 5s replace.  The funny thing is.  While im playing games and their running choppy and slow and if i take a snap shot inside the phone. They run smooth and HD but just for a few seconds and boom they go back to slow and choppy.  Is it the ios 7 or the iphone 5s it self? Like i said this is my replacement iphone 5s because the other 5s did the same thing. And it was running slowly.

    As far as I know you can't delete the primary email address for an iCloud account.  It's assigned when the account is created.  But your neighbor wouldn't have been able to get into your iCloud account without your Apple ID and password.  Are you sure the account wasn't still on your phone when you gave it to him?
    You could migrate a copy of your data to a new iCloud account but I would still be concerned that someone else was using my old account, which presumably still has your data in it.
    I'm fairly certain that you're going to have to have iCloud support help you sort this one out as they may have the ability to make changes to an existing account that users can't.  Make an appointment with the genius bar at a nearby Apple store and have them take a look at it.  If necessary, they should be able to contact iCloud support for you.

  • How to parse XML to Java object... please help really stuck

    Thank you for reading this email...
    If I have a **DTD** like:
    <!ELEMENT person (name, age)>
    <!ATTLIST person
         id ID #REQUIRED
    >
    <!ELEMENT name ((family, given) | (given, family))>
    <!ELEMENT age (#PCDATA)>
    <!ELEMENT family (#PCDATA)>
    <!ELEMENT given (#PCDATA)>
    the **XML** like:
    <person id="a1">
    <name>
         <family> Yoshi </family>
         <given> Samurai </given>
    </name>
    <age> 21 </age>
    </person>
    **** Could you help me to write a simple parser to parse my DTD and XML to Java object, and how can I use those objects... sorry if the problem is too basic, I am a beginner and very stuck... I am very confuse with SAXParserFactory, SAXParser, ParserAdapter and DOM has its own Factory and Parser, so confuse...
    Thank you for your help, Yo

    Hi, Yo,
    Thank you very much for your help. And I Wish you are there...I'm. And I plan to stay - It's sunny and warm here in Honolulu and the waves are up :)
    A bit more question for dear people:
    In the notes, it's mainly focus on JAXB,
    1. Is that mean JAXB is most popular parser for
    parsing XML into Java object? With me, definitely. There are essentially 3 technologies that allow you to parse XML documents:
    1) "Callbacks" (e.g. SAX in JAXP): You write a class that overrides 3 methods that will be called i) whenever the parser encounters a start tag, ii) an end tag, or iii) PCDATA. Drawback: You have to figure out where the heck in the document hierarchy you are when such a callback happens, because the same method is called on EACH start tag and similarly for the end tag and the PCDATA. You have to create the objects and put them into your own data structure - it's very tedious, but you have complete control. (Well, more or less.)
    2) "Tree" (e.g. DOM in JAXP, or it's better cousin JDOM): You call a parser that in one swoop creates an entire hierarchy that corresponds to the XML document. You don't get called on each tag as with SAX, you just get the root of the resulting tree. Drawback: All the nodes in the tree have the same type! You probably want to know which tags are in the document, don't you? Well, you'll have to traverse the tree and ask each node: What tag do you represent? And what are your attributes? (You get only strings in response even though your attributes often represent numbers.) Unless you want to display the tree - that's a nice application, you can do it as a tree model for JTree -, or otherwise don't care about the individual tags, DOM is not of much help, because you have to keep track where in the tree you are while you traverse it.
    3) Enter JAXB (or Castor, or ...): You give it a grammar of the XML documents you want to parse, or "unmarshall" as the fashion dictates to call it. (Actually the name isn't that bad, because "parsing" focuses on the input text while "unmarshalling" focuses on the objects you get, even though I'd reason that it should be marshalling that converts into objects and unmarshalling that converts objects to something else, and not vice versa but that's just my opinion.) The JAXB compiler creates a bunch of source files each with one (or now more) class(es) (and now interfaces) that correspond to the elements/tags of your grammar. (Now "compiler" is a true jevel of a misnomer, try to explain to students that after they run the "compiler", they still need to compile the sources the "compiler" generated with the real Java compiler!). Ok, you've got these sources compiled. Now you call one single method, unmarshall() and as a result you get the root node of the hierarchy that corresponds to the XML document. Sounds like DOM, but it's much better - the objects in the resulting tree don't have all the same type, but their type depends on the tag they represent. E.g if there is the tag <ball-game> then there will be an object of type myPackage.BallGame in your data structure. It gets better, if there is <score> inside <ball-game> and you have an object ballGame (of type BallGame) that you can simply call ballGame.getScore() and you get an object of type myPackage.Score. In other words, the child tags become properties of the parent object. Even better, the attributes become properties, too, so as far as your program is concerned there is no difference whether the property value was originally a tag or an attribute. On top of that, you can tell in your schema that the property has an int value - or another primitive type (that's like that in 1.0, in the early release you'll have to do it in the additional xjs file). So this is a very natural way to explore the data structure of the XML document. Of course there are drawbacks, but they are minor: daunting complexity and, as a consequence, very steep learning curve, documentation that leaves much to reader's phantasy - read trial and error - (the user's guide is too simplicistic and the examples too primitive, e.g. they don't even tell you how to make a schema where a tag has only attributes) and reference manual that has ~200 pages full of technicalities and you have to look with magnifying glas for the really usefull stuff, huge number of generated classes, some of which you may not need at all (and in 1.0 the number has doubled because each class has an accompanying interface), etc., etc. But overall, all that pales compared to the drastically improved efficiency of the programmer's efforts, i.e. your time. The time you'll spend learning the intricacies is well spent, you'll learn it once and then it will shorten your programming time all the time you use it. It's like C and Java, Java is order of magnitude more complex, but you'd probably never be sorry you gave up C.
    Of course the above essay leaves out lots and lots of detail, but I think that it touches the most important points.
    A word about JAXB 1.0 vs. Early Release (EA) version. If you have time, definitively learn 1.0, they are quite different and the main advantage is that the schema combines all the info that you had to formulate in the DTD and in the xjs file when using the EA version. I suggested EA was because you had a DTD already, but in retrospect, you better start from scratch with 1.0. The concepts in 1.0 are here to stay and once your surmounted the learning curve, you'll be glad that you don't have to switch concepts.
    When parser job is done,
    what kind of Java Object we will get? (String,
    InputStream or ...)See above, typically it's an object whose type is defined as a class (and interface in 1.0) within the sources that JABX generates. Or it can be a String or one of the primitive types - you tell the "compiler" in the schema (xjs file in EA) what you want!
    2. If we want to use JAXB, we have to contain a
    XJS-file? Something like:In EA, yes. In 1.0 no - it's all in the schema.
    I am very new to XML, is there any simpler way to get
    around them? It has already take me 4 days to find a
    simple parser which give it XML and DTD, then return
    to me Java objects ... I mean if that kind of parser
    exists....It'll take you probably magnitude longer that that to get really familiar with JAXB, but believe me it's worth it. You'll save countless days if not weeks once you'll start developing serious software with it. How long did it take you to learn Java and it's main APIs? You'll either invest the time learning how to use the software others have written, or you invest it writing it yourself. I'll take the former any time. But it's only my opinion...
    Jan

Maybe you are looking for

  • Can't get Canvas and Timeline Windows to Show

    Not sure what happened but Canvas and Timeline windows won't show. Pls help!

  • N97 Problem - browser won't stay open

    Another problem with my N97: Now when I try to open a page in the standard web browser it just closes down the application. Icheck in the running programs list and it's not there - it has completely closed the app.  Is this a known bug?

  • I want to transfer songs from WMP to iPhone 5

    All my music is in Windows Media Player. I would like to sync it with iTunes so I can put some of it on my iPhone. The only thing I have figured out to do is add a file or folder to iTunes Music Library. When I do it this way none of the info comes i

  • Can I use new TC as a wifi extender?

    Subj.

  • SDK question (basic)

    hi If i download the SDK for iphone, is it possible to make apps with this kit alone? or do you need other software. thought i might give it ago, especially as i have programmed an Acorn Electron before