Solved

Regarding applets

Posted on 2004-04-27
6
315 Views
Last Modified: 2010-03-31
Hi,

I am having a problem using the paint method in applet.....in the init() method, i add several JLabels, and set the background colour......now in the paint method i draw couple of line using drawLine function....the applet comes up with the background colour and the lines....but there are no labels on it.........first of all i thought that it might be overwritting the labels with the lines.....so i added the labels in the init method as well as in the paint method after i add the lines.....still the labels dont show up....

also i tried to call the applet from main, but the applet doesnt get displayed....if i use a frame and add the applet to the frame, it appears....but then i cannot close it...it keeps on running.....ne suggestions for displaying applet all by itself....or destroying one after added in a frame.....

all suggestions are welcome...

thanx
prerak
0
Comment
Question by:shahpaulin
6 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10935640
If you're using JApplet you should override the painComponent() method. And don't forget to call super.paintComponent()
0
 
LVL 1

Expert Comment

by:developer007
ID: 10935697
Yeh..

 I think u have to setup some layout for ur applet. Then try to add the labels.

 Even I have done same kinda of thing many time..it works for me.. if possible try to paste the code where u are getting actual problem.

 setLayout(new BoxLayout());
 add(new Lable("werwe");
 ....

 
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 10936236
If you want to close JFrame add this:
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

and with Frame you'll have to add WindowListener and implement method WindowClosed(...).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 10936573
> If you're using JApplet you should override the painComponent() method.

no, overriding paint() is correct.

you need to make sure you call super.paint(g); to get the labels painted.

> also i tried to call the applet from main, but the applet doesnt get displayed

you need to add the applet to your gui/frame like any other component.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10937360
>>....or destroying one after added in a frame.....

Try

applet.stop();
remove(applet);
revalidate();
repaint();
0
 

Author Comment

by:shahpaulin
ID: 10941432
Thnx for all the help..

when i used super.paint(g), then it does show me the labels and  the lines....but the background color and the image disappeared....especially how do i get the background image and other images back......

i tried adding the applet to the frame, btu then when i try loading an image, it gives out the getDocumentBase() error - "null pointer exception".....how do i overcome this...



Thnx,
Prerak
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pagenation logic how it is working in my code 1 69
going to wrong jsp page 2 46
What browser will run Java? 7 123
dao vs facade design patterns 2 31
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question