Solved

Regarding applets

Posted on 2004-04-27
6
317 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

734 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