Results 1 to 1 of 1
  1. #1
    edo_nick is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Applet run twice

    my applet run twice. (Kam na obed v Žiline)
    In init method I just set background.

    public void init() {
    Color c = new Color(150, 250, 150); //#EDEFF4

    // applet rendering method
    public void start(){


    All logic is nested in paint method.

    public void paint(Graphics g){
    try {
    g.drawRect(9, 9, 101, 21);
    String menu = menuBuilder(g, true);
    g.drawString(menu, 10, 15);
    } catch (Exception e) {
    g.drawString(e.getMessage(), 30, 15);


    menuBuilder method collects String through web to display and while collecting draw progress bar.
    I think about using start() method to nest menuBuilder method and in paint method just draw collected string but I can not pass Graphics object to start() method to draw progress bar.
    After some tests I found that calling this method cause duplicate drawing (running)

    public static byte[] getBytesFromUrl(URL iurl) throws IOException, InterruptedException {
    ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
    HttpURLConnection urlConn = (HttpURLConnection) iurl.openConnection();
    urlConn.setRequestProperty("Pragma", "no-cache");
    urlConn.setRequestProperty("Cache-Control", "no-cache");

    /* when I comment out this part applet draws only once

    InputStream openStream = new BufferedInputStream(urlConn.getInputStream());

    byte[] buf = new byte[16384];
    int len;
    while (true) {
    len =;
    if (len == -1) {
    tmpOut.write(buf, 0, len);

    ByteBuffer bb = ByteBuffer.wrap(tmpOut.toByteArray(), 0, tmpOut.size());
    byte[] binaryData = tmpOut.toByteArray();

    /* when I comment out this part
    return binaryData;

    How to avoid to draw applet twice?
    Last edited by edo_nick; 03-16-2011 at 12:44 PM. Reason: Error correction

Similar Threads

  1. applet class inside java.applet.* or java.awt.*
    By Manish87 in forum Java Applets
    Replies: 1
    Last Post: 09-27-2010, 03:15 PM
  2. Replies: 2
    Last Post: 09-29-2009, 04:33 PM
  3. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 01:54 PM
  4. BFS using APPLET
    By bharanidharanit in forum Java Applets
    Replies: 3
    Last Post: 12-30-2008, 03:45 AM
  5. Replies: 4
    Last Post: 06-08-2007, 07:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts