Convert applet from AWT to Swing

Hi I'm trying to convert my applet from awt to swing so that when I drag an object it doesn't flicker using swing auto double buffering. I've made a small change of changing Applet to JApplet and importing swing, this does stop the flickering however it also draws the path that object was dragged across (therefore drawing a line to the screen). How can I stop it from drawing the objects path and just dragging the object across the screen? are there more changes needed to fully convert the Applet to swing? Any help will be much appreciated. Here is my code:

Re: Convert applet from AWT to Swing

You've overriden the paint() of the JApplet class. I don't think you are getting the double buffering.
Try creating a JPanel, moving and renaming the paint() method to paintComponent() into the JPanel class.
Add a call to the super method.

Re: Convert applet from AWT to Swing

Originally Posted by Norm

You've overriden the paint() of the JApplet class. I don't think you are getting the double buffering.
Try creating a JPanel, moving and renaming the paint() method to paintComponent() into the JPanel class.
Add a call to the super method.

Hi thanks for your reply but sorry I'm still a bit lost, im new to java. I changed the main "SheepDog" class to a JPanel and changed paint() to paintComponent() and also added the line super.paintComponent(g); in the paintComponent() but it wont run now. Is there a way of adding the JPanel to a JApplet?

Re: Convert applet from AWT to Swing

Hi, I'm afraid I still cant get it to work, I created a separate class (MainPanel) for the JPanel, put the paintComponent() in that class, I then created an instance of the new class in the SheepDog class, however it still doesn't work, it compiles but nothing is shown in the applet. I feel like I'm really close, any ideas whats wrong.
here is the code:

Re: Convert applet from AWT to Swing

I'm using eclipse and viewing the applet with appletviewer. Appletviewer opens but nothing is shown, when i click on the screen the following error message is shown in the console:
Exception in "AWT-EventQueue-1" java.lang.NullPointerException at mandAndDog MainPanel paintComponent(MainPanel.java 22).

Do I need to create instances of the sheep and dog objects in both the SheepDog class and the MainPanel class?