Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:08:15+00:00 2026-06-14T20:08:15+00:00

I have a animation class which simply draws two circles and a line (no

  • 0

I have a animation class which simply draws two circles and a line (no main method), in another class i have a main method which is passed the animation class as a object and should show the two circles that I have drawn but it doesn’t show, it only shows the window none of the circles or the line that I have done, if i was to put the main method in my animation class it will work perfectly, this is a user error somehow but I’m not sure what or why.

The animation method in separate class.

import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.Graphics.*;
import javax.swing.JApplet;

public class Animation extends JApplet{

    public void init(){

}
public static void createAndShowGUI(JApplet j)
{
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
    frame.setVisible(true);
    frame.setSize(500,500);

    frame.getContentPane().add("Center", j);
}

public void paint(Graphics g){
    Graphics2D g2 = (Graphics2D) g;
    int x=50;
    int y=10;
    g2.setPaint(Color.black);

    g2.draw(new Line2D.Double(x,y,50,400));

    drawT(g2);
    drawH(g2);  
        //create a method that translates
    }

public void drawH(Graphics2D g2)
{
    int y=25;
    g2.setColor(Color.blue);
    drawCircle(y,g2);
}

public void drawT(Graphics2D g2){
    int y=100;
    g2.setColor(Color.green);
    drawCircle(y,g2);
}/*
public void raceLoop(){
    long startingTime = System.currentTimeMillis();
    long cumTime=startingTime;
    while(mve.hposition<70){
        long timePassed = System.currentTimeMillis()-cumTime;   
        cumTime += timePassed;
        //mve.update(timePassed);   
    }
}*/

public void drawCircle(int y, Graphics2D g2)
{
g2.fillOval(50,y,50,50);
}
}

The Main Method

import javax.swing.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.Graphics.*;
import javax.swing.JApplet;

public class Race {

public static void main(String[] args) {
    JApplet applet = new JApplet();
    Animation animie = new Animation();
    animie.createAndShowGUI(applet);

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:08:17+00:00Added an answer on June 14, 2026 at 8:08 pm
    1. You don’t need to (or want) extend from JApplet if all you’re going to is use a JFrame. You’re better of (in any case), extending from JPanel (as this can then be added to a JApplet or JFrame)
    2. You’ve not added anything to the JFrame, so, in fact, you program is doing exactly what you told it to.
    3. You should very rarely need to override the paint method of a top level container (like JApplet or JFrame), instead, use JPanel and override it’s paintComponent method.
    4. You should always call super.paintXxx, the paint methods chain together to paint the various aspects of the application and it will end in tears if you break this chain.

    You might like to have a read through

    • Creating a GUI With JFC/Swing
    • Performing Custom Painting
    • Painting in AWT and Swing

    For some more background

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a animation class which stores the frames in a std::list, the header
I have added a shake animation class (Css3) which i add when the text
I have a class which extends a SWC , in the swc i have
I always have an class which needs to set up a timer for as
So I have a ViewController Class which is my first view, I then add
I have an image slider ( NivoSlider ) which simply fades through a range
I want have animation on hovering a which shall slide from top and on
I have a class called IssuesView which implements INotifyPropertyChanged . This class holds an
As it is right now I have a Board object which contains an 8x8
I have a class that extends View, in which I place an instance of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.