473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

applet paint? not sure why this doesn't work...

hi all

im not why this code doesn't work:
/////////

import java.applet.*;
import java.awt.*;

public class TestApplet extends Applet {
public void init() {
setLayout(new GridLayout(5, 1));

add(new Label("hello this is label"));
add(new TextField());
add(new Button("a button to press"));
add(new TextArea());
add(new Checkbox("a checkbox to check"));
}

public void paint(Graphics poGraphics) {
super.paint(poG raphics);

System.out.prin tln("here");

Color oForegroundColo r = poGraphics.getC olor();
poGraphics.setC olor(getBackgro und());
poGraphics.fill 3DRect(20, 20, 100, 100, true);
poGraphics.setC olor(oForegroun dColor);
}
}

////////

what i am trying to achieve is a option pane like popup in the applet
(yes, no, ok, etc) that draws on top of the current components.

i have tried overidding update, paintAll, paintComponents , nothing
draws on top of the current components.

i am writting for 1.1 but using 1.4, dont know if that is relevant.

thanks in adavance
evan
Jul 17 '05 #1
4 5550
On 22 Apr 2004 06:43:36 -0700, eh*******@yahoo .com (Evan Dekker) wrote
or quoted :
public void paint(Graphics poGraphics) {
super.paint(poG raphics);

System.out.prin tln("here");

Color oForegroundColo r = poGraphics.getC olor();
poGraphics.setC olor(getBackgro und());
poGraphics.fill 3DRect(20, 20, 100, 100, true);
poGraphics.setC olor(oForegroun dColor);


Normally you would create a custom Component based on Canvas for AWT
or JPanel for Swing and add that component to your Applet. With Swing
you are supposed to override paintComponent, not paint.

For your experiment, I would use explicit and unique colours e.g.
Color.MAGENTA not getColor and getBackground to eliminate the
possibility that is where your problem lies.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #2
On Thu, 22 Apr 2004 17:07:16 GMT, Roedy Green wrote:
For your experiment, I would use explicit and unique colours e.g.
Color.MAGENTA not getColor and getBackground to eliminate the
possibility that is where your problem lies.


Not the upper case constants,
not for this case!

The OP stated..
"i am writting for 1.1 but using 1.4,
dont know if that is relevant."

The upper case color constants were
only defined in 1.4, you can check it
on the on-line compiler..
<http://www.physci.org/javac.jsp?bcp=1 1>

The first importable source, CardTest,
will fail for 1.1

And to the OP - the on-line compiler is
a great way to ensure you do not acidentally
introduce post 1.1 classes/methods/attributes.

[ F'Ups set to c.l.j.help ]

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #3
In article <66************ *************@p osting.google.c om>, Evan Dekker wrote:
im not why this code doesn't work:
[helpful example program snipped]
what i am trying to achieve is a option pane like popup in the applet
(yes, no, ok, etc) that draws on top of the current components.
You cannot achieve it with heavyweigh AWT components. There is no
defined order in which the applet and the five components in it will be
painted. If you want a popup, create and show a Dialog when appropriate.
i have tried overidding update, paintAll, paintComponents , nothing
draws on top of the current components.


With some implementations of Java, the paint method of the applet may
not be invoked due to painting optimizations. Because the dimensions of
the applet are completely covered by the heavyweight components in it,
the paint method of the applet is not necessarily invoked. Anything
that the paint method of the applet would have drawn, may be drawn over
by the heavyweight components in the applet.

Followup-to set to comp.lang.java. gui.
Jul 17 '05 #4
thanks for the replys ppl, but i solved it myself.

for ppl in the future with the same problem, here is my solution:

////////////
import java.applet.*;
import java.awt.*;
import java.awt.event. *;

public class TestApplet extends Applet implements ActionListener {
TestCanvas foTestCanvas = null;

public void init() {
setLayout(null) ;
foTestCanvas = new TestCanvas(this );
foTestCanvas.se tLocation(20, 20);
foTestCanvas.se tSize(100, 100);
foTestCanvas.se tVisible(false) ;
add(foTestCanva s);

Label oLabel = new Label("hello this is label");
oLabel.setLocat ion(10, 10);
oLabel.setSize( 100, 20);
add(oLabel);

TextField oTextField = new TextField();
oTextField.setL ocation(10, 40);
oTextField.setS ize(100, 20);
add(oTextField) ;

Button oButton = new Button("a button to press");
oButton.setLoca tion(10, 70);
oButton.setSize (100, 20);
add(oButton);

oButton.addActi onListener(this );

TextArea oTextArea = new TextArea();
oTextArea.setLo cation(10, 100);
oTextArea.setSi ze(100, 20);
add(oTextArea);

Checkbox oCheckbox = new Checkbox("a checkbox to check");
oCheckbox.setLo cation(10, 130);
oCheckbox.setSi ze(100, 20);
add(oCheckbox);
}

public void actionPerformed (ActionEvent poActionEvent) {
foTestCanvas.se tVisible(true);
repaint();
}
}

class TestCanvas extends Canvas implements MouseListener {
TestApplet foTestApplet = null;

public TestCanvas(Test Applet poTestApplet) {
foTestApplet = poTestApplet;
addMouseListene r(this);
}

public void paint(Graphics poGraphics) {
Color oForegroundColo r = poGraphics.getC olor();
poGraphics.setC olor(getBackgro und());
poGraphics.fill 3DRect(0, 0, getWidth(), getHeight(), true);
poGraphics.setC olor(oForegroun dColor);
}

public void mouseClicked(Mo useEvent poMouseEvent) {
}
public void mousePressed(Mo useEvent poMouseEvent) {
}
public void mouseReleased(M ouseEvent poMouseEvent) {
setVisible(fals e);
foTestApplet.re paint();
}
public void mouseEntered(Mo useEvent poMouseEvent) {
}
public void mouseExited(Mou seEvent poMouseEvent) {
}
public void mouseDragged(Mo useEvent poMouseEvent) {
}
}

/////////////

cheers
evan
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8297
by: Laura | last post by:
Hello, Newbie question: Does anyone know how to dynamically set the screen width in an applet? I have an applet that creates a horizontal bar menu on a webpage, and I would like the width to be 100%. Unfortunately, this doesn't work with Explorer. so, in my html page, I wrote a function like this: <SCRIPT LANGUAGE="JavaScript"> int...
3
2887
by: Jeff T. | last post by:
I have an applet that sizes itself to the size of the browser frame that it is running in. On IE the applet resizes upon dragging the frame divider. I'm having a problem with getting this applet to resize itself when I resize the html frame if it's in Netscape 7.x. Seems like the problem is the lack of a refresh signal to the java applet...
2
3475
by: Michael | last post by:
Hello Currently I'm migrating an applet from Java 1.1 to 1.3. Targetplattform: Microsoft Internet Explorer 5.x with Sun's Java VM 1.3.1 Problem: The attached applet works fine with the Microsoft VM. But when I use Suns' VM the applet hangs after opening the dialog. And you have to
0
9858
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ********************************** package Celcom.Client;
4
3939
by: foleyflint | last post by:
Hello, lately I've been trying to make an applet that has a background image and a couple of canvas objects on it holding an image each. I created the class ImageCanvas which extends Canvas adn draws a picture in the canvas. Next I have to place the canvas on the applet and there I got stuck because I don't know how to control the position of...
1
2369
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing in the right direction. Ok the problem. I am creating a program that ask the user to input a height value, the program will then do a...
5
2018
by: cozsmin | last post by:
Hy all, i have aproblem, i made a simple applet that works fine at a first glance, so i just wanted to add some drawing on it like : class Ap extends java.applet.Applet { java.awt.Graphics g; public void start() {
2
3439
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in advance for responding. I have made a stub of the codes for better understanding. Situation: I have a Java servlet (HelloWorldServlet) running on a...
1
5110
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the following code. in the following code i am using SelectionArea class which extends a canvas on which i am performing drawing operation. i am using image...
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5341
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1897
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.