Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Applet array paint/print question

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Applet array paint/print question

    Hi,

    How do I paint or print an multi-array in applets?



    Here is my code:

    import java.awt.Graphics;
    import javax.swing.*;
    import java.applet.*;

    public class Applettest extends JApplet {

    public void init() {

    int Choice = 0;

    String userChoice = JOptionPane.showInputDialog("Enter a number, 0 to 2");
    Choice = Integer.parseInt(userChoice);
    paint(null,Choice);

    }

    public void paint(Graphics g, int testPass) {

    String Multi[][]={{"Line 1","Line 2","Line 3"},{"Line 4","Line 5","Line 6"},{"Line 7","Line 8","Line 9"}};

    g.drawString(Multi[testPass][testPass], 10,10);


    }
    }

    My error:
    java.lang.NullPointerException
    at applets.Applettest.paint(Applettest.java…
    at applets.Applettest.init(Applettest.java:…
    at sun.applet.AppletPanel.run(AppletPanel.j…
    at java.lang.Thread.run(Thread.java:722)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Applet array paint/print question

    java.lang.NullPointerException
    at applets.Applettest.paint(Applettest.java…
    What variable is null? Your error message text has left off the line number where the error occurred.

    paint(null,Choice);
    Why do you call the paint() method with a null value?

    If you want to override the paint method, You need to read the API doc for the paint() method to see how to code it.

Similar Threads

  1. Applet paint program frame work.
    By ShaunB in forum Java Swing Tutorials
    Replies: 4
    Last Post: October 31st, 2012, 08:44 AM
  2. Print array with commas
    By GoPro in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 27th, 2012, 12:41 AM
  3. Inheriting Applet and paint() GUI Method Logic?
    By Jakesta42 in forum Object Oriented Programming
    Replies: 1
    Last Post: August 8th, 2011, 06:58 AM
  4. Need help on print , scrollbar for my applet
    By Anandprasad in forum Member Introductions
    Replies: 2
    Last Post: May 12th, 2011, 09:00 AM
  5. Applet paint program frame work.
    By ShaunB in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: May 5th, 2010, 06:35 PM

Tags for this Thread