Results 1 to 8 of 8
  1. #1
    gan5016 is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default Drawing disappear!!!!

    My drawing,(the USA),disappear after resizing the window...Help!!!Thanks!!!!
    And one more things to ask, actually wat is the serializable for??
    import java.awt.Graphics;
    import java.awt.Color;
    import java.io.Serializable;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.net.*;
    import java.text.*;

    public class drawWorld1 extends java.applet.Applet implements Serializable
    {

    String epicountry = "";
    int epilon = 0 ;
    int epilat = 0;


    public void init()
    {
    epicountry = "USA";
    epilat = 37;
    epilon = -95;
    }

    public void paint (Graphics gc)
    {

    int del = -180;
    String dels="";

    //draw the big cross
    gc.setColor(new Color(90,150,200));
    gc.drawLine(20,420,820,420);
    gc.drawLine(420,20,420,820);


    //draw epicenter
    if(epilon<0)
    epilon = 420-(epilon*-2);
    else if(epilon>0)
    epilon = 420+epilon*2;
    else if(epilon==0)
    epilon = 420;

    if(epilat<0)
    epilat = 420-(epilat*-2);
    else if(epilat>0)
    epilat = 420+epilat*2;
    else if(epilat==0)
    epilat = 420;

    gc.setColor(new Color(110,255,110));
    gc.fillOval(epilon-60,epilat-60,120,120);
    gc.setColor(new Color(255,110,25));
    gc.fillOval(epilon-40,epilat-40,80,80);
    gc.setColor(new Color(207,0,20));
    gc.fillOval(epilon-20,epilat-20,40,40);
    gc.setColor(Color.black);
    gc.fillOval(epilon-2,epilat-2,4,4);
    gc.drawString(epicountry,epilon+2,epilat);
    }
    }

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Learn how to use the "Code" tags so the code you post retains its formatting.

    I can't tell from the code whether you are attempting to create an AWT applet or a Swing applet.

    Assuming it's Swing then custom painting is done by extending a JPanel and overriding the paintComponent(...) method. Then the panel is added to the content pane of JApplet.

    Read the section from the Swing tutorial on Custom Painting.

  3. #3
    gan5016 is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    Sorry ,i still dun know wat can i do.Actually i want to display the drawing on HTML page,
    the drawing can be seen while jus open the page.but as i scroll down some of the drawing disappear.:(

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    What part of the tutorial did you not understand? It has a working example.

  5. #5
    gan5016 is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    I havent try out the example...But really thanks i hope it can work as change to my program.:)

  6. #6
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    Java Code:
    import java.awt.Graphics;
    import java.awt.Color;
    import java.io.Serializable;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.net.*;
    import java.text.*;
    All those imports, yet you still use java.applet.Applet instead of importing it... why?
    Java Code:
    implements Serializable
    why? You won't need it.

    Your drawing disappears when you resize the window? See if it also happens using the appletviewer.
    I die a little on the inside...
    Every time I get shot.

  7. #7
    gan5016 is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    oh...bcos i copy paste the code here and there so there may have those redundant code in my program.Is a bit misleading,sorry ah!!

  8. #8
    gan5016 is offline Member
    Join Date
    Aug 2009
    Posts
    18
    Rep Power
    0

    Default

    I tried to draw it in the JPanel and it can work.But there are more things had to add in, i hope will be alright too!!!Thanks a lots guys!!!

Similar Threads

  1. drawing images
    By diggitydoggz in forum New To Java
    Replies: 4
    Last Post: 01-02-2009, 03:15 AM
  2. Drawing a map
    By Karp in forum AWT / Swing
    Replies: 4
    Last Post: 11-07-2008, 12:26 PM
  3. Help with 2-D Drawing
    By Deathmonger in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 02:23 AM
  4. How to make a JButton disappear?
    By diab01ical in forum New To Java
    Replies: 2
    Last Post: 06-04-2008, 02:48 AM
  5. results to code disappear too fast for DOS window
    By dubdubdub in forum New To Java
    Replies: 3
    Last Post: 12-29-2007, 05:07 PM

Posting Permissions

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