File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes about drawing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about drawing" Watch "about drawing" New topic
Author

about drawing

Aimin Fei
Greenhorn

Joined: Aug 11, 2001
Posts: 2
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

Joined: Apr 30, 2001
Posts: 31
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).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about drawing
 
Similar Threads
How to launch a webpage from a browser from an application and an applet
more tabbedpane - panel questions
How to Add Graphics to Jpanel
How do I draw .JPG Image to JPanel?
Problem with custom painting and multiple JPanel