Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Drawing lines/string in JPanel in JApplet

843805Apr 15 2007 — edited Apr 16 2007
I am creating an applet (JApplet) that has a JPanel and would like to draw lines, image and strings in the JPanel . I'm having trouble getting the lines to appear in the JPanel. See code below, in the following code I am not drawing the line/string in the panel. How can I modify the code to draw lines in the JPanel, not in the base applet content or point me towards some simple examples. I will also need to modify the line/image/strings based on some user feedback; so I have to call paint again with modifications to the lines/string etc.

JApplet Code: na.java
//<APPLET code="na.class" width=500 height=500></APPLET>
import java.awt.*;
import java.net.*;  
import java.sql.*;
import javax.swing.*;
 
public class na extends JApplet {
     JPanel nj = new JPanel();
     Image my_gif;
     URL base;
 
     public na() {
	   getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
     }	  
 
 
     public void init(){
	  try{	
	       base = new URL("http://maps.yahoo.com/maps_result?addr=&csz=Chicago%2C+Ill&country=us&new=1&name=&qty=");
	  }
	  catch (Exception e) {}
 
 
	  getContentPane().add (nj);  
     }
 
     public void paint(Graphics g) {
 
	  g.setColor(Color.red);
	  g.drawString ("Applet Started!!!", 5,10);
	  //g.drawImage(my_gif,10,50,100,100,this); //draw image with specified size
	  g.drawLine(5,200,50,220);
	  
	  nj.setBounds(100,190,100,100);
	  nj.setVisible (true);
	  
     }
}
Thanks,
Mathew
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2007
Added on Apr 15 2007
3 comments
178 views