   [java] Paint from two classes
  Well I am wondering if it is possible to paint from 2 classes such as:Engine.class renders and paints all the playable area graphicsGame.class paints the simple graphics such as status and chat uses Engine.class to render and paint the majority of the game (all in the same 1024X768 game area)And if this is possible how would I implement this? Would this be an easy way to go? I am trying to make a java game engine for all the java games I am/will make(ing).Any help or positive criticism will be appreciated.   
  As long as you have a Graphics object to paint with, it doesn't matter whether you use it in 2 classes or in 200 (for instance if every object paints itself). Just pass it to wherever you need it. How you split up your rendering is entirely up to you and will depend on what makes sense to you and what you are trying to accomplish.   ;  Now that I know it is possible, how would I do it like:gFrame.add(new Game(gFrame));gFrame.add(new Engine(gFrame));or would I actually have to go through a different method?   ;  BUMP   ;  I have trouble understanding your question without context (is this Swing? AWT? LWJGL? what does "do it" mean exacty? there's a bunch of different things to do).I don't have much experience in Swing (assuming your code is Swing) but that looks about right for adding components (assuming your engine and game subclass some Swing component). There might be more you have to do, like setting them visible. On the other hand, painting Swing components over each other is a bit more tricky Try some of these approaches. Alternatively, I think it would be better to have one class for the canvas you will paint on. You can still have as many painting classes as you want if you pass around the Graphics object (probably from that canvas' paint method).[Edited by - lightbringer on May 8, 2009 3:21:00 PM];  I'm Using JFrame here is a slight example of how I'm using it:import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;import java.io.*;import java.net.*;import java.util.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.image.*;import javax.imageio.*;import java.lang.*;import java.applet.*;import java.lang.reflect.Method;import javax.swing.JOptionPane;import javax.swing.JApplet;import java.net.URLEncoder;import java.lang.Object;import java.awt.geom.*;public class game extends Component implements Runnable, ActionListener, KeyListener, MouseListener, MouseMotionListener{public static void main(String[] arg){game playable = new game(arg);}public game(String[] args){GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); GraphicsConfiguration gc = dev.getDefaultConfiguration();DisplayMode mode = new DisplayMode(1024, 768, 32, DisplayMode.REFRESH_RATE_UNKNOWN);HDf = new JFrame("Game");HDf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);HDf.setUndecorated(true);HDf.setVisible(false);HDf.add(new game(HDf));HDf.pack();HDf.setResizable(false);dev.setFullScreenWindow(HDf); if(dev.isDisplayChangeSupported()) dev.setDisplayMode(mode);}public game(JFrame HDF){HDF.setVisible(true);HDF.addMouseListener(this);HDF.addKeyListener(this);HDF.addMouseMotionListener(this);runner = new Thread(this);runner.start();}public void mouseClicked (MouseEvent me){int got = 0;int X=me.getX();int Y=me.getY();}public void mouseDragged (MouseEvent mme){}public void mouseMoved (MouseEvent mme){XPos = mme.getX();YPos = mme.getY();}public void mouseEntered (MouseEvent me){}public void mousePressed (MouseEvent me){}public void mouseReleased (MouseEvent me){}public void mouseExited (MouseEvent me){} public void actionPerformed(ActionEvent e){}public void keyTyped(KeyEvent event){int got = 0;char keyP = event.getKeyChar();}public void keyPressed(KeyEvent event){}public void keyReleased(KeyEvent event){}public void run(){while (runner == Thread.currentThread() ){repaint();}}public void paint (Graphics gg){//basic paint functions}public void update(Graphics gg){paint(gg);}}and I was wondering just to paint in the same area if i could put HDf.add(new engine(HDf)); under HDf.add(new game(HDf)); and make a new class almost identical to the one above and it still work out correctly?   ;  Looking over the JFrame javadoc, it seems you're supposed to call frame.getContentPane().add() instead of frame.add()Even then, I don't think this will work as you expect - the two components will probably be arranged next to each other by the layout manager. Why don't you just try it out?   