Problem repainting applet

Hello (first, sorry for my English),
I have a JApplet that contains a component that extends a JPanel. That component contains a button and a (self-done) progress bar that extends a Canvas.
The % of completing is variable, but applet doesn't refresh correctly. Only I can watch the 0% and 100%, all the intermediate values are lost.
I use repaint() after a new %, but it doesn't works :(
Help me please!!!
Thanks!

I would suggest you place your applet to servlet communication in a separate thread. Then have your paint method check to see if this thread is finished, otherwise sleep for a bit, and call repaint()?

Similar Messages

  • Problem calling applet method using IE

    I've searched through the forum and can't seem to find anything that can help me fix this. I'm trying to call an applet's method using Javascript. This is working fine under Netscape, but not IE. Everything I've read seems to indicate that I'm doing this right, but I'm getting "Object doesn't support this property or method" when I try to call the applet method from IE.
    In this example method, I'm trying to call the applet's countChars method, which should return the length of the string you pass into it. Works under Netscape 6.2, but not IE 6.0
    Here's my applet code:
    import java.lang.String;
    public class test extends java.applet.Applet {
    public static int countChars(String s) {
    return s.length();
    And my HTML
    <HTML>
    <HEAD>
    <script language="Javascript">
    function refreshApplet()
    /*     i = document.forms.myForm.TestApplet.countChars();
         document.forms.myForm.output.value=i; */
         document.forms.myForm.output.value=document.applets["TestApplet"].countChars(document.forms.myForm.input.value);
    </script>
    </HEAD>
    <BODY>
    <APPLET CODE = "test.class" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" scriptable="true">
    </APPLET>
    <br>
    <form name="myForm">
    <input type="text" name="input">
    <input type="button" value="click me" onClick="refreshApplet();">
    <hr>
    <input type="text" name="output">
    </form>
    </BODY>
    </HTML>
    Thanks in advance!
    Craig Drabik
    Sr. Programmer/Analyst
    University at Buffalo

    I have very similar problem, my applet works OK using Netscape (6.2 and 7.0), but with IE 6.0 It only works with windows XP;
    The reported error is "Object doesn't support this property or method"
    Can someone please help me to solve this problem.
    Cheers
    Horus
    This is my code:
    - I call the applet using javaScript and input the method setData with two strings.
    function graphic()
         var dataZenith;
         var dataManual;
         initVariables();
         dataZenith = graphicZENith(); //Call other Javascript functions
         dataManual = graphicManual(); //Call other Javascript functions
         document.AppletOne.setData(dataZenith,dataManual);
    I run the applet with this HTML code:
    <applet NAME="AppletOne" code="Appl.class" width="450" height="450"
    MAYSCRIPT></applet>
    //Applet code/////////////
    import java.awt.*;
    import java.awt.geom.*;
    import java.applet.*;
    import java.util.*;
    public class Appl extends Applet {
         private int [] myArray1 = new int [156];     
         private int [] myArray2 = new int [156];
         private boolean flag = false;
         // maxDataYAxesNumber es usado para dividir el eje de las Y
    public void init()
              setFont(new Font("SansSerif", Font.BOLD, 12));
              setBackground (Color.white);
              setSize(getSize());     
    // Get data and put in an array
    public void setData(String data1, String data2)
              final String DELIMITER = ",";
              final StringTokenizer theTokens1 =
                   new StringTokenizer(data1, DELIMITER);     
              final StringTokenizer theTokens2 =
                   new StringTokenizer(data2, DELIMITER);
              try
                        String dataX = data1;
                        for (int i = 0; i < 156; i++)
                        myArray1[i] = Integer.parseInt(theTokens1.nextToken().trim());
                        myArray2[i] = Integer.parseInt(theTokens2.nextToken().trim());
              catch (NumberFormatException e) {};
              flag = true; //I get the data OK
              repaint();
    public void paint (Graphics g){
    Graphics2D g2d = (Graphics2D)g;
    setData(data1, data2) ;
    if (flag == true)
                   //Call other functions to process the graphic
    else g2d.drawString(" Sorry I can get Data", 100,80);          

  • Repaint applet

    Hi!
    I have a problem repainting my JApplet (BorderLayout) as the browser window is maximized or minimized. The scrollbars of a small window remains when maximizing the browser. Any ideas?

    I found this reply on a similar problem...
    In your html, capture the 'onresize' event of the browser. In onresize, you can use the capability that javascript can communicate with an applet. Call the repaint method of your applet from javascript trigger by onresize.
    Check out this link:
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html

  • Caching problem in Applets - Java Control Panel

    I have a problem of applets being cached in Java Control Panel. Is there a way in Java to stop caching applets programatically in the Java Control Panel.
    There is one way to stop caching files by unchecking "Keep Temporary Files on my Computer" under Java Control Panel --> General --> Settings page.
    But I want to do this programatically using some Java programming/Java Scripting/some parameter in applet tag.
    Some solutions like setting cache_option = No, cache_archive= jar file name in PARAM tag in applet and classloader_cache="false" have been already tried. But noting is seeming to be working out.
    Can somebody please provide a solution.

    Following is the listener status
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ
    ction
    Start Date 11-APR-2007 11:51:12
    Uptime 0 days 0 hr. 1 min. 28 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Listener Parameter File I:\oracle\product\10.2.0\db_1\network\admin\listener.o
    ra
    Listener Log File I:\oracle\product\10.2.0\db_1\network\log\listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jbpsouthcbg)(PORT=1521)))
    Services Summary...
    Service "jbpsouth" has 2 instance(s).
    Instance "jbpsouth", status UNKNOWN, has 2 handler(s) for this service...
    Instance "jbpsouth", status READY, has 2 handler(s) for this service...
    Service "jbpsouth_XPT" has 1 instance(s).
    Instance "jbpsouth", status READY, has 2 handler(s) for this service...
    The command completed successfully

  • Problem downloading applet in W2K with SP4.

    Hi,
    We are using a Security Applet in our web application for validation purposes. We were using W2K Professional / W2K Server with SP3 and Sun JRE 1.3.x. The application was working as expected.
    We are now testing with W2K Server with SP4 (to upgrade to SP4). The current testing environment is W2K Server with SP4 and Sun JRE1.3.x. Now with the setup, we are facing a problem in downloading the applet (Security Applet). The downloading applet fails and the subsequent loading as well.
    Please advice. Does it requires any particular settings to be done at Client?
    The specs are
    Windows 2000 Server, SP4
    IE 6 SP1
    Sun Jre 1.3.x
    Problem:Downloading applet fails.
    PS: When we test with SP3, we can see the applet downloaded (CAB File), with SP4 it was not found.
    Thanks in Advance,
    Prakash

    Does the w2k sp4 server host your pages and applet?
    If yes then why install the SUN JRE 1.3 on the server, doesn't the client need this?
    Is the cab format supported by SUN jre or is it meant for msjvm and if so why is the client trying to open
    the cab with sun jre?
    http://java.sun.com/j2se/1.4.2/docs/guide/deployment/deployment-guide/upgrade-guide/article-02.html
    What's on the server doesn't have anything to do with the applet. The server is
    just serving it. Forcing the client/consumer of the html page with the applet is trying to open an applet
    with sun jre while the applet is ment for msjvm causes the error.
    The client can fix this by opening IE and check under tools -> internet options -> advanced -> UNCHECK
    the use sun jre ... for <applet tag. For the XP machine you might have a problem. Some of the don't have
    the msjvm at all so there is nothing to run the <applet, I tried to download it at microsoft but was unable
    to find it.

  • Severe Problem in Applets

    I hav problem in Applets by use of threads.The prb. is that i am supposed to create three threads in applets.Thread one will read a file and extract a character array of size 10 from it and Thread 2 will display those characters in Textarea of Applets and after 10 seconds Thread3 will delete those chracters from textarea and next character set of Array of size 10 from Thread one will be assigned to Thread2 and process should go on untill it reads all character from file.Please sort this problem with source code.All are warmly welcome.
    Anuj.

    Thread one will read a file Since applets cannot read from the filesystem you have to use the URL object to read the file and place the
    file in the same location as your applet:
              try {
                   url = new URL(this.getCodeBase(), "yourfile.txt");
                   URLConnection conn = url.openConnection();
                   InputStream in = conn.getInputStream();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   byte[] buf = new byte[1024];
                   int len;
                   while ((len = in.read(buf)) > 0) {
                        bos.write(buf, 0, len);
                   byte[] data = bos.toByteArray();
    //               String dataString = new String(data,"Shift_JIS"); // depending on your file encoding
              } catch (Exception e) {
                   e.printStackTrace(System.out);
              }How to use threads:
    http://java.sun.com/docs/books/tutorial/essential/threads/index.html

  • Problem in Applet while communicating with Javascript

    Hi,
    I’m facing a problem with applet. Applet calls JavaScript methods and vice versa. Applet works fine with JRE 5 to JRE 6 up to build no 1.6.0._7 but it fails with build no 1.6.0_10.
    The problem description is given below:
    After embedding applet in my HTML page using <OBJECT> tag, I’ve to check either any problem during applet’s execution, I want to get the error reason by calling my defined method getErrorReason() in applet that returns the error reason, I call the getErrorReason() against the applet’s object in JavaScript immediately after embed applet code in my HTML page, a JavaScript errors occurs and my applet fails to perform its execution.
    JavaScript error: Object does not support this property.
    The error points to the HTML page area where I’m calling getErrorReason() against applet object.
    The above JavaScript error occurs after the successful completion of Applet’s init(). I’m facing this problem only in JRE 6 build 1.6.0_10-b33.
    Please suggest me any solution.
    Thanks in advance.
    Regards,
    Israr Ahmed

    Hi Bharath,
    Even i got similar error and i tried deleting the below(Attaching the stack trace is always better way.)
    1) delete the folder ‘workspace’ or rename(including all files and subfolders) in the path D:\Documents and Settings\lzcr8r\Documents\SAP\workspace
    2) delete all .dtr/.dtc/.metadata directories in your personal folder (e.g. C:\Documents and Settings\lzcr8r).
    Restart the IDE once you are done with the above steps.
    Second part to increase the virtual mem
    1) RtClick on the Shortcut of NWDS -->Properties and in the Target put the below
    "C:\Program Files\SAP\IDE\IDE70\eclipse\SapIde.exe" -vmargs -Xms512m -Xmx1536m  "C:\j2sdk1.4.2_08\bin\javaw.exe"
    2) You can also try  Creating a bat file with the complete path of your IDE and start your ide from the bat
       content in the bat eg: "C:\Program Files\netbeans-4.1\bin\netbeans.exe" -vmargs -Xms512m -Xmx1536m
    Here -Xms512m is the min JVM size and -Xmx1024m is the max JVM size.
    You can place this batch file anywhere and double click the batch file.
    It will automatically start your IDE
    3) if you are using Tomcat you can try creating an env variable and assign Value
    Variable Name:  CATALINA_OPTS
    Variable Value:  -server -Xmx800m
    please award points if usefull.
    Regards
    Souza
    Edited by: Souza Aluri on Apr 9, 2008 9:46 AM

  • Paint()/repaint() problem w/applet

    Hi all. Here's my dilemma: I'm trying to create an applet that asks for simple multiplication answers, and draws a string giving feedback after the question is answered ("Very good!" or "No, try again."). The problem is that the book says to draw everything from paint(), and gives the impression that repaint() should magically refresh everything on the applet, which it does not. How can I make the strings I drew in paint() go away and give way to new strings based on user answer (whether correct or not), instead of piling up on top of each other, because they don't refresh? Also, my JButton and JTextField aren't showing up until the mouse is scrolled over them. Thanks for your time!
    code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Week5Class extends JApplet implements ActionListener
        static int int1 = (int)(Math.random()*10);
        static int int2 = (int)(Math.random()*10);
        JTextField answer = new JTextField(3);
        JButton verifyAnswer = new JButton("Click to see if correct");
        public void init()
            Container myContainer = getContentPane();
            myContainer.add(answer);
            myContainer.add(verifyAnswer);
            verifyAnswer.addActionListener(this);
            myContainer.setLayout(new FlowLayout());
        static int j = 0;
        static int i;
        public void paint(Graphics gr)
              gr.drawString("How much is " + int1 + " * " + int2 + "?", 10, 70);
              if(i == 1)
                  gr.drawString("VeryGood!", 300, 200);
              else if(i == 0 && j != 0)
                  gr.drawString("No. Please try again.", 300, 200);
              j++;
        public void actionPerformed(ActionEvent e)
            int x = 300;
            int y = 200;
            if(Integer.parseInt(answer.getText()) == (int1*int2))
                int1 = (int)(Math.random()*10);
                int2 = (int)(Math.random()*10);
                i = 1;
                repaint();
            else
                i = 0;
                repaint();
    }

    The problem is that you're mixing doing your own drawing and using child objects. The paint method you've overriden would be the one that draws the text field and button.
    A far easier approach would be to use a JLabel to display your response message, and insert that as another component into the container, as you've inserted the button and input field.
    Then use setText() on the label to change the message.
    If you really want to have an area that you draw arbitary shapes on it's best to create your own child component, add it to the container, and override it's paintComponent method. Alternatively create a class which implments the Icon interface and put it in a JLabel.
    FlowLayout isn't very clever, by the way, try a BorderLayout or maybe a BoxLayout.

  • Chess Piece display problem in applet

    Hi,
    I'm writing a chess game applet which will be played between to players over the internet. I'm currently working on the applet side at the moment and will develop the server side once I have completed the applet. I'm currently having problems displaying the actual chess pieces on the board at the moment. One of my design decisions was to make a Board class which extends a JPanel. I have painted the actual chess board squares within the Board JPanel. I then propose to draw the pieces on top of these squares (good design decsion? Can anyone suggest another way. I was thinking of having the images as a separate layer which will sit on top of the squares but wasn't sure how to implement it). The chess pieces are contained in a gif strip www.dur.ac.uk/j.d.p.murphy called ChessPieces02.gif . The problem I am having is to display several pieces at the same time. I lloked at a Java tutorial which suggested using g.clipRect() method to display a defined section of the strip (i.e. a single piece of a certain length). Below is the Board class that I am using.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Board extends JPanel{
    // Holds location of the mousePressed event
    Point point = null;
    // Size of a square square on the board
    int square_size = 40;
    // Mediatracker to monitor the loading of the images
    MediaTracker tracker;
    Image image;
    void init() {
    tracker = new MediaTracker(this);
    image = Toolkit.getDefaultToolkit().getImage("ChessPieces02.gif");
    tracker.addImage(image, 0);
    try {
    //Start downloading the images. Wait until they're loaded.
    tracker.waitForAll();
    } catch (InterruptedException e) {
    e.printStackTrace();
    throw new Error("error");
    if (tracker.isErrorAny()) {
    throw new Error("Could not load image");
    addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (point == null)
    point = new Point(0, 0);
    int x = e.getX();
    int y = e.getY();
    System.out.println("X co-ord: " + x + " Y co-ord: " + y);
    // Floor the x and y values to the nearest unit of 25
    x = x - x % square_size;
    y = y - y % square_size;
    point.setLocation(x, y);
    repaint();
    System.out.println(point);
    public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background
    System.out.println("Chess Board Paint");
    // Loop to produce the black and white squares to represent the board
    for(int jj = 0; jj < 8; jj ++){
    for(int ii = 0; ii < 8; ii++){
    if(ii % 2 == jj % 2)
    g.setColor(Color.white);
    else
    g.setColor(Color.lightGray);
    g.fillRect(ii * square_size, jj * square_size, square_size, square_size );
    // Draw a highlighted square
    if (point != null){
    g.setColor(Color.green);
    g.fillRect( (int)point.getX(), (int)point.getY(), square_size, square_size);
    //imageStrip is the Image object representing the image strip.
    //imageWidth is the size of an individual image in the strip.
    //imageNumber is the number (from 0 to numImages)
    // of the image to paint.
    int stripWidth = image.getWidth(this);
    int stripHeight = image.getHeight(this);
    int imageWidth = stripWidth / 6;
    System.out.println("Width = " + imageWidth);
    g.clipRect(120, 0, imageWidth, stripHeight / 2);
    g.drawImage(image, 0 * imageWidth, 0, this);
    What code do i need to add more pieces to the board? I plan to make a ChessPiece array (8x8) which will holld all the chess pieces on the board. Should I hold this array in the board class to make drawing the pieces easier? Any other tips for game development would also be most welcome.
    Thanks

    cross post, I think.
    http://forum.java.sun.com/thread.jsp?thread=496287&forum=406

  • Swing JComboBox causes scrolling problems in applet

    I have an applet with a JPanel that contains a JComboBox that lists font selections for a JTextPane in a JPanel below it. It contains about 12 items, of which only five are visible at a time. If I choose any of the first five and scroll the page on which the applet is running, there are no issues. However, if I scroll the page after scrolling down the list to the sixth item, regardless of whether or not I actually select it, it causes the graphics in the applet to corrupt. The JComboBox code is:
    private JComboBox getFontFaceCB() {
                   String[] fontNames = new String[fontlist.length];
                   for (int i = 0; i < fontlist.length; i++){
                        fontNames[i] = fontlist.getFamily();
                   if (fontFaceCB == null) {
                        fontFaceCB = new JComboBox(fontNames);
                        fontFaceCB.setBackground(Color.white);
                        fontFaceCB.setPreferredSize(new Dimension(150, 30));
                        fontFaceCB.setMaximumRowCount(5);
                        fontFaceCB.setSelectedIndex(0);
                        fontFaceCB.addItemListener(new java.awt.event.ItemListener() {
                             public void itemStateChanged(java.awt.event.ItemEvent e) {
                                            currentFont = fontlist[fontFaceCB.getSelectedIndex()];
                                            StyleConstants.setFontFamily(textStyles, currentFont.getFamily());
                                            jTextPane.setCharacterAttributes(textStyles, true);
                                            viewWidget.repaint();
                   return fontFaceCB;
              }This also happens if I set the default index to something that one must scroll down to reach (e.g. the sixth index) I was wondering if anyone else has come across this issue and has any idea as to how this may be resolved.
    Also, if the window is minimized, resized, etc. the graphics also corrupt, but only after the aforementioned condition.
    Edited by: BANZ111 on Dec 12, 2007 3:59 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I have found the solution:
    I had lightweight components intertwined with heavyweight ones, which, until now, I never regarded as being a possible source of problems. Apparently, when you scroll down a JComboBox, it changes from light to heavy weight? At any rate, I found this with a lot of other useful tips here:
    http://72.5.124.55/javase/6/webnotes/trouble/TSG-Desktop/html/gchzf.html#gdldq
    Perhaps this can be of use to anyone else who gets a similar problem.

  • Big Problem in Applet-Servlet Communication-(Help)

    I wrote an method to send serialized objects from Applet to Servlet,
    the method is as following:
    private ObjectInputStream postObjects (URL servlet, Serializable objs[], String sessionID) throws Exception {
    ObjectInputStream in = null;
    ObjectOutputStream out = null;
    try{
    URLConnection con = servlet.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type","application/x-java-serialized-object");
    con.setAllowUserInteraction(false);
    con.setRequestProperty("Cookie", sessionID);
    out = new ObjectOutputStream(con.getOutputStream());
    int numObjects = objs.length;
    for(int x = 0; x < numObjects; x++){
    out.writeObject(objs[x]);
    out.flush();
    out.close();
    in = new ObjectInputStream(con.getInputStream());
    }catch(Exception e){
    e.printStackTrace(System.err);
    throw e;
    }finally{
    return in;
    when I call this method, I got the following error message in Applet console,
    my platform is Salaris 5.8 + iPlanet 6.0.
    java.io.EOFException
         at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2150)
         at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2619)
         at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:726)
         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:251)
         at com.shinewave.lms.core.client.ServletProxy.postObjects(ServletProxy.java:255)
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:76)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    java.lang.NullPointerException
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:77)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    java.lang.NullPointerException
         at com.shinewave.lms.core.client.ServletProxy.doInitialize(ServletProxy.java:82)
         at com.shinewave.lms.core.client.APIAdapterApplet.LMSInitialize(APIAdapterApplet.java:60)
    Please help me to solve this problem, thank you very much.

    Hi..
    Sorry abt this. But I was hoping if u could help out on this..
    I am trying to implement a applet to servlet communication...
    wherin the servlet would read data from the database... and send it back to the applet which gets displayed on the applet...
    But the problem is that the applet is not able to establish a connection with the servlet..
    I am also using another supportive class whose object is basically passed from the servlet to the applet..
    could u help me..
    below is the piece of code...
    APPLET:
    import java.net.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class TestApplet extends JApplet implements ActionListener
         JButton btnLoad;
         JTextField tfEmpno, tfFname, tfLname, tfSalary;
         URL url;
    private String webServerStr = null;
    private String hostName = "sandy";
    private int port = 8085;
    private String servletPath = "/jdbcTest.DBDetailsServlet";     
    public TestApplet()
         super();
    // suppress Warning Message
    getRootPane().putClientProperty"defeatSystemEventQueueCheck",Boolean.TRUE);
         public void actionPerformed(ActionEvent ae)
              if(btnLoad.getText().equals("Load"))
                   if(loadData())
                        btnLoad.setText("Save");
              else
                   btnLoad.setText("Load");
    //               saveData();
         public void init()
              setBackground(Color.pink);
              tfEmpno = new JTextField(10);
              tfFname = new JTextField(10);
              tfLname = new JTextField(10);
              tfSalary= new JTextField(10);
              JPanel panel = new JPanel();
              panel.setLayout(new FlowLayout());
              panel.add(tfEmpno);
              panel.add(tfFname);
              panel.add(tfLname);
              panel.add(tfSalary);
              getContentPane().add(panel, BorderLayout.CENTER);
              JPanel bottom = new JPanel(new FlowLayout());
              btnLoad = new JButton("Load");
              btnLoad.addActionListener(this);
              bottom.add(btnLoad);
              getContentPane().add(bottom, BorderLayout.SOUTH);
         public boolean loadData()
              try
         System.out.println("Web Server host name: " + hostName);
         webServerStr = "http://" + hostName + ":" + port + servletPath;
         System.out.println("Web String full = " + webServerStr);
                   String servletGET = webServerStr + "?"
         + URLEncoder.encode("UserOption") + "="
         + URLEncoder.encode("AppletDisplay");     
    //               url = new URL(getCodeBase(),"http://sandy:8080/servlet/jdbcTest.DBDetailsServlet");
                   System.out.println("Complete Servlet Url => " + servletGET);
                   url = new URL(servletGET);
                   URLConnection con = url.openConnection();
                   con.setUseCaches(false); // Turn off caching.
                   InputStream in = con.getInputStream();
                   System.out.println("\nsuccess ....... con.getInputStream() ");
                   ObjectInputStream ois = new ObjectInputStream(in);
                   System.out.println("\nsuccess ....... new ObjectInputStream(in) ");
                   Object object = ois.readObject();
                   System.out.println("\nGot the object from servlet...");
                   if(object != null)
                        System.out.println("\nObject NOT null ...");
                        ArrayList result = (ArrayList) object;
                        jdbcTest.EmployeeValue empval = (jdbcTest.EmployeeValue) result.get(0);
                        tfEmpno.setText(""+empval.getEmp_no());
                        tfFname.setText(empval.getFname());
                        tfLname.setText(empval.getLname());
                        tfSalary.setText(""+empval.getSalary());
                        System.out.println("\nObject processed " + result);
                        repaint();
                   return true;
              catch(Exception e)
                   e.printStackTrace();
                   System.out.println("\n\n loadData()=> E X C E P T I O N : " + e + "\n");
                   return false;               
         public void saveData()
              //yet to be implemented..
    SERVLEt:
    package jdbcTest;
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class DBDetailsServlet extends HttpServlet
         public void doGet(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
              System.out.println("\nInside the doGet()\n");
              ArrayList results = getDetails();
              ObjectOutputStream oos = new ObjectOutputStream(res.getOutputStream());
              oos.writeObject(results);
         public void doPost(HttpServletRequest req,HttpServletResponse res )throws ServletException, IOException
              System.out.println("\nInside the doPost()\n");
              doGet(req,res);
         public ArrayList getDetails()
              try
                   System.out.println("\nServlet : inside GetDetails...");
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:odbc:SandyDSN","","");
                   java.sql.Statement stmt = con.createStatement();
                   System.out.println("\n Statement created..");
                   java.sql.ResultSet rs = stmt.executeQuery("SELECT * FROM EMP WHERE EMP_NO = 222");
                   System.out.println("\n Query Executed...");
                   ArrayList results = new ArrayList();
                   while(rs.next())
                        EmployeeValue empval = new EmployeeValue();
                        empval.setEmp_no(rs.getLong("EMP_NO"));
                        empval.setFname(rs.getString("FNAME"));
                        empval.setLname(rs.getString("LNAME"));
                        empval.setSalary(rs.getLong("SALARY"));
                        results.add(empval);
                   System.out.println("\n Resultset Obtained...");
                   stmt.close();
                   con.close();
                   return results;
              catch(Exception e)
                   System.out.println("Error while retreiving details....." + e);
                   return null;
         public boolean saveDetails(EmployeeValue empval)
              try
                   return true;
              catch(Exception e)
                   System.out.println("Error while updating details....." + e);
                   return false;
    The utility class EMployeeValue is as below:
    package jdbcTest;
    import java.io.*;
    class EmployeeValue implements Serializable
         private long emp_no;
         private String fname;
         private String lname;
         private long salary;
         public EmployeeValue()
              super();
         public EmployeeValue(long eno, String fn, String ln,long sal)
              super();
              setEmp_no(eno);
              setFname(fn);
              setLname(ln);
              setSalary(sal);
         public long getEmp_no()
              return emp_no;
         public java.lang.String getFname()
              return fname;
         public java.lang.String getLname()
              return lname;
         public long getSalary()
              return salary;
         public void setEmp_no(long newEmp_no)
              emp_no = newEmp_no;
         public void setFname(java.lang.String newFname)
              fname = newFname;
         public void setLname(java.lang.String newLname)
              lname = newLname;
         public void setSalary(long newSalary)
              salary = newSalary;

  • Problem clearing applet's screen for different images

    I have an applet that displays several jpg-images.
    Images are photos of different sizes that are portrait
    and landscape.
    Problem is that the rest of a portrait image remains at
    the screen when a landscape image is dispayed and
    in the same way the rest of a landscape image remains
    at the screen when a portrait image is displayed.
    I thought update and repaint methods should do the
    work but something is wrong.
    Code that should do it is:
    private void runWork() {
       curFrame = 0;
       try {
            while(noStopRequested) {
         waitWhilePaused();
         curFrame = (curFrame + 1) % image.length;
         repaint();
         Thread.sleep(5000);
       } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
    public void paint(Graphics g) {
        update(g);
    public void update(Graphics g) {
       g.drawImage(image[curFrame], 0, 0, this);
    }What am I doing wrong?
    Thanks in advance

    Yeah, I knew flickering would probably happen. I've never done double-buffering exactly in an applet, but I can give you an idea how it's done.private void runWork() {
       Image offScreen = createImage(appletWidth, appletHeight);
       Graphics offGraphics = offScreen.getGraphics();
       try {
          while (noStopRequested) {
             waitWhilePaused();
             curFrame = (curFrame + 1) % image.length;
             offScreen.clearRect(0, 0, appletWidth, appletHeight);
             offScreen.drawImage(image[curFrame], 0, 0, this);
             repaint();
       catch (...) {}Then in paint():public void paint(Graphics g) {
       g.drawImage(offScreen, 0, 0, this);
    public void update(Graphics g) {
       paint(g);
    }Might not be perfect, but it should give you an idea. Basically you want to draw the screen OFF the screen before drawing it to the screen. That way you don't clear the screen and draw the image. You do it all in one paint().
    Michael Bishop

  • Problem with applet, popup window and focus loss

    Hi all !
    I've got a problem when my applet lose the focus. Let me explain :
    I've got an applet embed in a jsp page. There are several buttons in it that allow the user to open modal windows.
    The problem comes when the user gives the focus to another application whithout closing the modal window first.
    When he tries to come back to the web page owning the applet (using the task bar), then the modal window stays behind it and blocks any action on the applet.
    Does anyone know how to force the modal window to be displayed in front of the applet, even when the user plays with focuses ?
    Thank's in advance.

    thank you for your help, sils.
    I've written that code :
    * Cr�� le 31 ao�t 05
    package com.scor.apricot.web.rpc.ltnp.applet.listener.ldf;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    public class AppletWindowListener extends WindowAdapter {
         private JPanel panel;
         private JDialog dialogWindow;
         public AppletWindowListener(JPanel panel, JDialog dialogWindow) {
              this.panel = panel;
              this.dialogWindow = dialogWindow;
         public void windowActivated(WindowEvent e) {
              if (dialogWindow!=null && dialogWindow.isShowing())
                   dialogWindow.toFront();
    }Is that right ?
    I don't know how to add the listener, where must I put the addWindowListener method ? It seems that this method cannot be used with a JApplet object.

  • Problem with Applets in same page

    Hai to all,
    I am having a problem with GUI in applets
    My first class extends a JPanel named A_a
    import javax.swing .*;
    import java.awt.*;
    import java.awt.event.*;
    public class A_a extends JPanel
    JButton jb;
    JTextArea text;
    public A_a()
    setLayout(new FlowLayout());
    jb=new JButton("Click me");
    //add(jb);
    text=new JTextArea(5,20);
    add(text);
    public void text_appendText(String aa)
    System.out.println("I AM IN A_a");
    text.append(aa);
    text.revalidate();
    revalidate();
    /*public static void main(String ags[])
    A_a a = new A_a();
    JFrame frame=new JFrame();
    frame.getContentPane().add(a);
    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) { System.exit(0); }
    frame.setSize(200,200);
    frame.show();
    and then I am using other class B_b which is an applet carries a exitsing panel (A_a) inside it .
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class B_b extends JApplet
    public A_a a;
    public void init()
    a=new A_a();
    getContentPane().add(a);
    public void text_appendText(String aa)
    final String aaa =aa;
    new Thread(new Runnable()
         public void run()
              a=new A_a();
              a.setBackground(new java.awt.Color(255,200,200));
              System.out.println("I AM IN B_b");
              a.text.append(aaa);
              a.text.revalidate();
              getContentPane().remove(a);
              resize(500,500);
         }).start();
    and the I am using the second applet C_c in which by performing a button action the old panel A_a should get removed and replace the new panel D_a (which is not here )in the applet B_b with all other components(namely button , text fields etc)
    import javax.swing .*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.*;
    public class C_c extends JApplet implements ActionListener
    JButton jbt;
    JTextArea jta;
    public void init()
    getContentPane().setLayout(new FlowLayout());
    jbt=new JButton("Click me");
    jbt.addActionListener(this);
    getContentPane().add(jbt);
    jta=new JTextArea(5,20);
    getContentPane().add(jta);
    public void actionPerformed(ActionEvent ae)
    Enumeration e = getAppletContext().getApplets();
    Applet applets = null;
              while(e.hasMoreElements())
                   applets=(Applet)e.nextElement();
                   if ( applets instanceof B_b)
                             System.out.println("I AM CLASS C_c");
                             ((B_b)applets).text_appendText(jta.getText());          
                             ((B_b)applets).remove());
                             ((B_b)applets).getContentPane().add(D_d);
    both the applets C_c and B_b are in same browser page
    How can i achive that pls help .

    please help me its urgent for my project

  • Problem with Applet for Microsoft VM

    Hi there!
    I implemented an applet (first for SUN JVM 1.4.1_02) that has to communicate with a servlet via serialized objects. Therefore the applet sends a request and expects the response :
    //establish connection
    URLConnection l_con= l_url.openConnection();
    l_con.setUseCaches(false);
    l_con.setDoOutput(true);
    l_con.setDoInput(true);
    l_con.setRequestProperty("Content-Type", "application/x-java-serialized-object");
    //send request to servlet               
    ObjectOutputStream l_outputStream = new ObjectOutputStream(l_con.getOutputStream());     
    l_outputStream.writeObject(l_obj);                    
    l_outputStream.flush();               
    l_outputStream.close();
    //get response
    ObjectInputStream l_obInStr = new ObjectInputStream(l_con.getInputStream());
    l_response = (MyResponseClass)l_obInStr.readObject();
    l_obInStr.close();This works absolutely fine for the Sun VM. Now I have to use the Microsoft VM (because I don't want the users to install anything on their clients).
    I compiled the client classes like that:
    javac -target 1.1 classname.javaThe applet starts correctly but there is a problem with the communication that I recognized in the console:
    java.io.IOException: Cannot write output after reading input.
         at com/ms/net/wininet/http/HttpURLConnection.getOutputStream (HttpURLConnection.java)
         at myclass/MyApplet.callToServlet (MyApplet.java:109)
    Does anyone know what this error means ?
    Thanks a lot in advance.

    Hi there!
    I solved my problem by removing all the System.out.println-statements that I used for debugging issues.
    Anyway, I want to know if there are more restrictions concerning this matter for using the Microsoft VM instead of the Sun VM. (Because it HAS worked with the debugging statements with the Sun VM).
    Thank you.

Maybe you are looking for

  • IPod Touch 1g "unable to connect to wifi"

    Hi . I recently got an iPod touch 1g from my sister's friend , and everything on it works fine, except the wifi. Everytime I try to go on wifi I'll click "other >" and type in my Router name and password , and it says it ither cannot connect or its u

  • Assemble Documents with READ_ONLY permissions set

    Greetings, We receive a boatload of documents from different sources, and have to package them together.  Adobe Assembler service seemed the obvious choice, but we've run into one problem in particular. Many of the documents we receive have Read Only

  • How to re connect on SQL developer

    i am using SQL Developer 2.1.1.64 on a Windows. From time to time, the connection to the Oracle server will be reset. Is there a quick way to re establish the connection from the tab where I've the SQL statements? on SSMS, i would right click and pic

  • Current best practice for Time service settings for Hyper-V 2012 R2 Host and guest OS's

    I am trying to find out what the current best practice is for Time service settings in a Hyper-V 2012 environment. I find conflicting information. Can anyone point me in the right direction. I have found some different sources (links below) but again

  • Use operation in detail stamp

    Hi!! I am using jdeveloper 11.1.1.5 I had dragged and dropped departmentVO as af:table I had also dragged and dropped EmployeeVO in my DetailStamp of my af:table. While doin so I have an arrow occurs on the left side of my table if i clck the arrow i