Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 12:02 AM
Evan Dekker
Guest
 
Posts: n/a
Default 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
  #2  
Old July 18th, 2005, 12:02 AM
Roedy Green
Guest
 
Posts: n/a
Default Re: applet paint? not sure why this doesn't work...

On 22 Apr 2004 06:43:36 -0700, ehendrikd@yahoo.com (Evan Dekker) wrote
or quoted :
[color=blue]
> 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);[/color]

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.
  #3  
Old July 18th, 2005, 12:02 AM
Andrew Thompson
Guest
 
Posts: n/a
Default Re: applet paint? not sure why this doesn't work...

On Thu, 22 Apr 2004 17:07:16 GMT, Roedy Green wrote:
[color=blue]
> 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.[/color]

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
  #4  
Old July 18th, 2005, 12:02 AM
A. Bolmarcich
Guest
 
Posts: n/a
Default Re: applet paint? not sure why this doesn't work...

In article <66269bbb.0404220543.a358d97@posting.google.com> , Evan Dekker wrote:[color=blue]
> im not why this code doesn't work:[/color]

[helpful example program snipped]
[color=blue]
> 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.[/color]

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.
[color=blue]
> i have tried overidding update, paintAll, paintComponents, nothing
> draws on top of the current components.[/color]

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.
  #5  
Old July 18th, 2005, 12:02 AM
Evan Dekker
Guest
 
Posts: n/a
Default Re: applet paint? not sure why this doesn't work...

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.