Solved

Regarding applets

Posted on 2004-04-27
6
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
ejb wildfly example 2 110
String array comparison 4 57
maven not picking latest jar instead picking old jar from .m2 12 74
Java pass by reference 3 74
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

732 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