Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

about drawing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Right! We're on it! Let's get to work tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic