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 clear

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

    Default Applet clear

    when i run it its blank and im not sure why?


     
    {import java.awt.*;        // Container, FlowLayout
    	import java.awt.event.*;  // ActionEvent, ActionListener
    	import java.util.Random;
    	import java.util.Scanner;
    	import javax.swing.*;
     
    	public class Assign6 extends JApplet {
     
    		Random randomNumbers = new Random();
     
    		int answer; 
     
    		public void createQuestion()
    		{
     
    		int digit1 = randomNumbers.nextInt( 10 );
    		int digit2 = randomNumbers.nextInt( 10 );
     
    		answer = digit1 * digit2;
    		System.out.printf( "How much is %d times %d?\n", digit1, digit2 );
    		} 
     
     
    		public void checkResponse( int guess )
    		{
    		if ( guess != answer )
    		System.out.println( "No. Please try again." );
    		else
    		{
    		System.out.println( "Very Good!" );
    		createQuestion();
    		} 
    		} 
    		} 
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Applet clear

    You have written a command line app not an applet.

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

    Default Re: Applet clear

    how would i go about fixing it to make it applet?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Applet clear

    Read an applet tutorial.

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

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

    Default Re: Applet clear

    k made the applet but not the paint covers out my Text fields? do i override the paint? if so how?

    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) {
    } 
    } 
     
    {
    }

Similar Threads

  1. [NEED HELP] to clear result on my tic-tac-toe game
    By bontet in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 28th, 2010, 03:50 PM
  2. an easy clear java programming tutorial
    By zkil_jpf in forum The Cafe
    Replies: 2
    Last Post: April 22nd, 2010, 08:40 AM
  3. getting errors needed to be clear
    By erinbasim in forum Enterprise JavaBeans
    Replies: 1
    Last Post: February 4th, 2010, 03:24 AM
  4. clear screen.
    By chronoz13 in forum Java Theory & Questions
    Replies: 10
    Last Post: December 5th, 2009, 07:27 AM
  5. Replies: 3
    Last Post: November 15th, 2008, 07:17 AM