I've been trying this for hours now with no avail.
I'm trying to use the paintComponent method in my Game.java class, but I'm not sure exactly how to do this.
I've tried calling the function directly but of course it does not work as it needs to return something.
The method I need to use is in this "Circles.java" class:
package testgame;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import javax.swing.JPanel;
import javax.swing.JPanel;
public class Circles extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Bubbles(g); }
private void Bubbles(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
RenderingHints rh
= new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHints(rh);
int x, y, size;
x = (int) (Math.random() * 500) + 15;
y = (int) (Math.random() * 450) + 15;
size = (int) (Math.random() * 30) + 10;
g2d.setColor(Color.green);
g2d.drawOval(x, y, size, size); }
}
This is the class that needs the paintComponent method (Game.java):
package testgame;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class Game extends JFrame {
public static void LoadUI() {
JFrame frame = new JFrame("Just a test!");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(550, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true); }
public static void main(String[] args) {
frame.add(new (Circles())); }
}
The error I get is at the:
frame.add(new (Circles()));
The error being:
identifier expected
cannot find symbol
symbol: method Circles()
location: class Game
cannot find symbol
symbol: variable frame
location: class Game