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 6 of 6

Thread: Applet doesnt show

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Applet doesnt show

    paint covers all my text..not sure how to fix


    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Assign6 extends JApplet implements ActionListener
    {
    JLabel answerLabel;
    JTextField answerField;
     
    public void init()
    {
    Container c = getContentPane();
    c.setLayout (new FlowLayout());
     
    answerLabel = new JLabel("Answer");
    answerField = new JTextField(20);
    answerField.setEditable(true);
    answerField.addActionListener(this);
     
    c.add(answerLabel);
    c.add(answerField);
     
    } 
     
     public int generateNumbers()
    {
     int x=0;
     x = 1 + (int)(Math.random() * 10);
     return x;
     
    } 
    public void actionPerformed(ActionEvent e)
    {
     String correct = new String("Correct ");
     int x = generateNumbers();
     int y = generateNumbers();
     showStatus("How much is " + x + " times " + y);
     
     int answer;
     answer = Integer.parseInt(answerField.getText());
     int product = x*y;
     if (product == answer){
      showStatus("Very good!");
     }
     else
      showStatus("No. Please try again.");
    } 
     
    public void paint(Graphics g) {
    } 
    } 
     
    {
    }
    {
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Applet doesnt show

    Not sure what you mean by 'paint covers all my text', but if you are going to override the paint function, make sure to call super.paint(g)

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet doesnt show

    when i run it nothing shows

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet doesnt show

    k i have this with super(g). but the question doesn't show now.

    import javax.swing.*;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Assign6 extends JApplet implements ActionListener
    {
    JLabel answerLabel;
    JTextField answerField;
     
    public void init()
    {
    Container c = getContentPane();
    c.setLayout (new FlowLayout());
     
    answerLabel = new JLabel("Answer");
    answerField = new JTextField(20);
    answerField.setEditable(true);
    answerField.addActionListener(this);
     
    c.add(answerLabel);
    c.add(answerField);
     
    } 
     
     public int generateNumbers()
    {
     int x=0;
     x = 1 + (int)(Math.random() * 10);
     return x;
     
    } 
    public void actionPerformed(ActionEvent e)
    {
     String correct = new String("Correct ");
     int x = generateNumbers();
     int y = generateNumbers();
     showStatus("How much is " + x + " times " + y);
     
     int answer;
     answer = Integer.parseInt(answerField.getText());
     int product = x*y;
     if (product == answer){
      showStatus("Very good!");
     }
     else
      showStatus("No. Please try again.");
    } 
    @Override
    public void paint(Graphics g) {
    	super.paint(g); 
    }
    }
     
     
     
    {
    }

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Applet doesnt show

    I'm surprised it even compiles, given showStatus isn't defined anywere

  6. #6
    Junior Member
    Join Date
    Feb 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applet doesnt show

    lol i have no idea..i been and it for a while now tho lol i called super.paint(g) and still black applet i just get the textfield

Similar Threads

  1. Show files name in JFrame
    By altisw5 in forum AWT / Java Swing
    Replies: 15
    Last Post: November 30th, 2011, 08:30 AM
  2. My program doesnt want to do its math point my errors out please
    By Redlight in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2010, 01:56 PM
  3. i can run my program but the math doesnt come otu
    By pairenoid in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 7th, 2010, 01:39 PM
  4. my menu doesnt work can u tell me whats wrong
    By claymore in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 8th, 2010, 04:16 AM
  5. JFrame, frame's title doesnt appear.
    By chronoz13 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 26th, 2009, 03:38 PM