Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about drawing

 
Aimin Fei
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello evrybody!
I want to draw a shape on a panel inside an applet. How can it be done?
class A extends JApplet
{
JPanel myPanel = new JPanel();
public void init()
{
add the myPanel to north of the applet;
}
public void paint(Graphics g)
{
// all drawing here are on applet. How can I draw on
// myPanle
}
}
ThankS!
 
Suma MM
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML FILE:
----------------------------------------------------------------
< html >
< applet code=A.class height=400 width=800>
< /applet>
< /body>< /html>
-----------------------------------------------------------------

SOURCE CODE:
-----------------------------------------------------------------import java.awt.*;
import javax.swing.*;
public class A extends JApplet
{
JPanel myPanel;
Container c;
public void init()
{
myPanel = new JPanel();
c = getContentPane();
c.add(myPanel);
}
public void paint(Graphics g)
{
g.drawRect(50,50,400,100);
}
}
-----------------------------------------------------------------
I don't understand why u would want to draw a shape on a panel because even without a panel, u would be getting the same output; the reason being that both JApplet and JPanel inherit (directly/indirectly) from the class "Container".
[This message has been edited by Suma MM (edited August 12, 2001).]
[This message has been edited by Suma MM (edited August 12, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic