473,382 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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(poGraphics);

System.out.println("here");

Color oForegroundColor = poGraphics.getColor();
poGraphics.setColor(getBackground());
poGraphics.fill3DRect(20, 20, 100, 100, true);
poGraphics.setColor(oForegroundColor);
}
}

////////

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 5543
On 22 Apr 2004 06:43:36 -0700, eh*******@yahoo.com (Evan Dekker) wrote
or quoted :
public void paint(Graphics poGraphics) {
super.paint(poGraphics);

System.out.println("here");

Color oForegroundColor = poGraphics.getColor();
poGraphics.setColor(getBackground());
poGraphics.fill3DRect(20, 20, 100, 100, true);
poGraphics.setColor(oForegroundColor);


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=11>

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*************************@posting.google.com> , 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.setLocation(20, 20);
foTestCanvas.setSize(100, 100);
foTestCanvas.setVisible(false);
add(foTestCanvas);

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

TextField oTextField = new TextField();
oTextField.setLocation(10, 40);
oTextField.setSize(100, 20);
add(oTextField);

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

oButton.addActionListener(this);

TextArea oTextArea = new TextArea();
oTextArea.setLocation(10, 100);
oTextArea.setSize(100, 20);
add(oTextArea);

Checkbox oCheckbox = new Checkbox("a checkbox to check");
oCheckbox.setLocation(10, 130);
oCheckbox.setSize(100, 20);
add(oCheckbox);
}

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

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

public TestCanvas(TestApplet poTestApplet) {
foTestApplet = poTestApplet;
addMouseListener(this);
}

public void paint(Graphics poGraphics) {
Color oForegroundColor = poGraphics.getColor();
poGraphics.setColor(getBackground());
poGraphics.fill3DRect(0, 0, getWidth(), getHeight(), true);
poGraphics.setColor(oForegroundColor);
}

public void mouseClicked(MouseEvent poMouseEvent) {
}
public void mousePressed(MouseEvent poMouseEvent) {
}
public void mouseReleased(MouseEvent poMouseEvent) {
setVisible(false);
foTestApplet.repaint();
}
public void mouseEntered(MouseEvent poMouseEvent) {
}
public void mouseExited(MouseEvent poMouseEvent) {
}
public void mouseDragged(MouseEvent 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
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...
3
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...
2
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...
0
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 ...
4
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...
1
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...
5
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 { ...
2
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.