Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-25-2009, 10:28 AM
Member
 
Join Date: Aug 2009
Posts: 18
Rep Power: 0
gan5016 is on a distinguished road
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);
}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-25-2009, 05:52 PM
Senior Member
 
Join Date: Jul 2009
Posts: 298
Rep Power: 1
camickr is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-25-2009, 06:22 PM
Member
 
Join Date: Aug 2009
Posts: 18
Rep Power: 0
gan5016 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-25-2009, 06:42 PM
Senior Member
 
Join Date: Jul 2009
Posts: 298
Rep Power: 1
camickr is on a distinguished road
Default
What part of the tutorial did you not understand? It has a working example.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-25-2009, 07:12 PM
Member
 
Join Date: Aug 2009
Posts: 18
Rep Power: 0
gan5016 is on a distinguished road
Default
I havent try out the example...But really thanks i hope it can work as change to my program.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-25-2009, 08:12 PM
Senior Member
 
Join Date: Aug 2008
Posts: 374
Rep Power: 2
Supamagier is on a distinguished road
Default
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?
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-26-2009, 03:41 AM
Member
 
Join Date: Aug 2009
Posts: 18
Rep Power: 0
gan5016 is on a distinguished road
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!!
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-26-2009, 03:58 AM
Member
 
Join Date: Aug 2009
Posts: 18
Rep Power: 0
gan5016 is on a distinguished road
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!!!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 03:39 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org