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