Solved

Regarding applets

Posted on 2004-04-27
6
310 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 78
array11 challenge 16 52
Java and GPO 11 47
Problem to start Neon 20 54
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now