473,322 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

drawing on Applet

14
Hy all,
i have aproblem, i made a simple applet that works fine at a first glance,
so i just wanted to add some drawing on it like :

Expand|Select|Wrap|Line Numbers
  1. class Ap extends java.applet.Applet {
  2.  
  3.     java.awt.Graphics g;
  4.  
  5.     public void start() {
  6.         g = getGraphics();
  7.         paint(getGraphics());
  8.         getGraphics().drawString("ok let's get it on !!",53,94);    
  9.     }
  10.  
  11.     public void paint(java.awt.Graphics g) {
  12.         getGraphics().drawString ("paint()",33,120);
  13.         g = getGraphics();
  14.     }
  15. }
  16.  
so put this applet in a page and see that it will only paint "paint()" , not what i wrote inside start(), if i did the same with a windowed component like frame/jframe/window it had printed both "ok lt's get it on " and "paint ()"
and i want to have it done outside paint() as i need adtion triggered paintings, so i cannot rely only on paint

Kind Regards !
Feb 28 '08 #1
5 2007
JosAH
11,448 Expert 8TB
What does 'getGraphics()' do and where does it come from?

kind regards,

Jos
Feb 28 '08 #2
cozsmin
14
What does 'getGraphics()' do and where does it come from?

kind regards,

Jos
well it comes like this.getGraphics() , u should know that appet derives from container that has getGraphics(), if u do not know what getGraphics does in container then it is bad :)

Kind Regards
Feb 28 '08 #3
cozsmin
14
JosAH i did not mean to be meen :), i now realize that this is not a java specific forum, and i was wrong to assume u knew it all

kind regards !
Feb 28 '08 #4
JosAH
11,448 Expert 8TB
JosAH i did not mean to be meen :), i now realize that this is not a java specific forum, and i was wrong to assume u knew it all
No hard feelings and about that getGraphics() method, I could've looked it up.
I find it a bit strange though that you're drawing 'on your own'. When I use swing
I let the AWT thread determine when something needs to be drawn and stick
the actual drawing functionality somewere in, or derived from the paint (or
paintComponent) method. I never had to use the getGraphics method, i.e the
AWT Thread always passes a Graphics object to my paint(Component) method ...

kind regards,

Jos
Feb 28 '08 #5
BigDaddyLH
1,216 Expert 1GB
I suggest:

1. moving from the old AWT to Swing
2. Switching from (J)Applets to standalone applications
3. Taking Sun's Swing tutorial: http://java.sun.com/docs/books/tutor...ing/index.html
Feb 28 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Remon Huijts | last post by:
Hi there, For a very specific service, I have created a PHP script that uses the GD library functions to create a PNG image from a few lines of XML data describing a simple diagram/drawing. It's...
2
by: timtt | last post by:
does anyone guideline to speed up drawing in awt applet?? i have thousands of g.drawstring() + d.drawline() actually, does Swing applet draw much faster than awt applet??
1
by: nathanlaan | last post by:
This is the stupidest thing I have ever seen. Java 1.2, 1.3, and 1.4.1, and 1.4.2 all define the Applet.getDocumentBase() method differently! How am I supposed to get the directory of the document...
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
0
by: Hermund ?rdalen | last post by:
Hi! We're developing some children's pages for one of our customers. Already we've found some nice crossword and puzzle programs/applets. What we really need now is a drawing program. It must...
0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
5
by: barbaros | last post by:
Hello everybody, I need to put some dynamic drawings on my web page. More precisely, I need to draw a number of geometric figures (circles, rectangles) which evolve into a graphics windows...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.