Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Regarding applets

Posted on 2004-04-27
6
Medium Priority
?
323 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Accepted Solution

by:
objects earned 375 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

927 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