Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot find symbol: implements Drawable
    text
    copied!<p>I am trying to do a custom drawing for each Gladiator object I create, then move them around. I am currently getting a cannot find symbol error inside Gladiator class on "public class Gladiator implements Drawable{" regarding keyword Drawable. I am pretty sure I am importing what I need to (likely more)... </p> <pre><code>public class Test2 extends JFrame { private PaintPanel paintPanel; public Test2() { setDefaultCloseOperation(EXIT_ON_CLOSE); setMinimumSize(new Dimension(800, 600)); paintPanel = new PaintPanel(); getContentPane().add(paintPanel, BorderLayout.CENTER); pack(); paintPanel.initGame(); } class PaintPanel extends JPanel implements ActionListener { private List&lt;Gladiator&gt; gladiators; private Timer timer; public void initGame() { timer = new Timer(50, this); timer.start(); } @Override public void actionPerformed(ActionEvent e) { repaint(); System.out.println("Refreshing "); } public PaintPanel(){ super(); gladiators = new ArrayList&lt;Gladiator&gt;(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; for (Gladiator s : gladiators){ g2.draw(s); } } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Test2 gamePanel = new Test2(); gamePanel.setVisible(true); } }); } </code></pre> <p>}</p> <p>Gladiator class:</p> <pre><code>import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Shape; import java.util.ArrayList; import java.util.List; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; public class Gladiator implements Drawable { int minreach = 60; int maxreach = 100; int z = maxreach * 2; int n = minreach * 2; int[] location = new int[] {25,25}; public void Draw(Graphics g){ g.setColor(Color.green); g.fillArc(location[0], location[1], z, z, 45, 90); g.setColor(Color.red); g.fillArc((location[0]+(z-n)/2),(location[1]+(z-n)/2), n, n, 45, 90); g.setColor(Color.black); g.fillArc((location[0]+(z-30)/2),(location[1]+(z-30)/2), 30, 30, 0, 360); } </code></pre> <p>}</p> <p>Why am I getting this error? I need to be able to draw my gladiators to screen. Do I need separate classes for my visual representation (abstract?) and my game object as some tutorials I have read seem to suggest?</p> <p>Edit:</p> <p>I removed drawable entirely because as I had assumed it was just part of java syntax, I may not even need it. Here is code:</p> <pre><code>public class Test2 extends JFrame { private PaintPanel paintPanel; public Test2() { setDefaultCloseOperation(EXIT_ON_CLOSE); setMinimumSize(new Dimension(800, 600)); paintPanel = new PaintPanel(); getContentPane().add(paintPanel, BorderLayout.CENTER); pack(); paintPanel.initGame(); } class PaintPanel extends JPanel implements ActionListener { private List&lt;Gladiator&gt; gladiators; private Timer timer; public void initGame() { timer = new Timer(50, this); timer.start(); } @Override public void actionPerformed(ActionEvent e) { repaint(); System.out.println("Refreshing "); } public PaintPanel(){ super(); gladiators = new ArrayList&lt;Gladiator&gt;(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; for (Gladiator s : gladiators){ g2.draw(s); } } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Test2 gamePanel = new Test2(); gamePanel.setVisible(true); } }); } </code></pre> <p>}</p> <p>Gladiator class:</p> <pre><code>import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Shape; import java.util.ArrayList; import java.util.List; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; public class Gladiator { int minreach = 60; int maxreach = 100; int z = maxreach * 2; int n = minreach * 2; int[] location = new int[] {25,25}; public void Draw(Graphics g){ g.setColor(Color.green); g.fillArc(location[0], location[1], z, z, 45, 90); g.setColor(Color.red); g.fillArc((location[0]+(z-n)/2),(location[1]+(z-n)/2), n, n, 45, 90); g.setColor(Color.black); g.fillArc((location[0]+(z-30)/2),(location[1]+(z-30)/2), 30, 30, 0, 360); } </code></pre> <p>}</p> <p>My error now is on line "g2.draw(s);" and says "actual argument Gladiator cannot be converted to Shape by method invocation conversion". Thanks for any help... how to convert my Gladiator to a shape? Or should I be extending Shape somehow?</p>
 

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