So I'm creating a game where I'll need multiple methods that can output text (to a JFrame) or display images. I've created a GraphicsEngine that has a paintComponent method - but the thing is, this will run through adding it to a JFrame and not through my calls, and I can't call other GraphicsEngine methods because it requires a Graphics2D object... which I won't have when I call the methods. How would I make a bunch of methods that can add stuff to the JFrame without having their own paintComponent? Please help.
Here's my GraphicsEngine, if anybody feels it's relevant.
import javax.swing.JComponent;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class GraphicsEngine extends JComponent
{
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
BufferedImage img = null;
try {
img = ImageIO.read(new File("Splash.jpg"));
} catch (IOException e) {
}
g2.drawImage(img, 0, 0, null);
}
public void textOut (Graphics2D g2, String text){
for(char c : text.toCharArray()){
System.out.print(c); //I want to be able to print this to JFrame through g2's text printing methods.
delay(30);
}
}
}