Note that there are some explanatory texts on larger screens.

plurals
  1. POJApplet not showing paint or draw methods
    text
    copied!<p>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. </p> <p>The animation method in separate class.</p> <pre><code>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&lt;70){ long timePassed = System.currentTimeMillis()-cumTime; cumTime += timePassed; //mve.update(timePassed); } }*/ public void drawCircle(int y, Graphics2D g2) { g2.fillOval(50,y,50,50); } } </code></pre> <p>The Main Method</p> <pre><code>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); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload