So here's my problem it's simple I hope, Currently I'm using a paint method in Class2 to paint many different graphic objects, the problem is when i paint a lot of things it starts lagging and has to repaint the whole map and everything over again, is there a way of making it paint once and stay or maybe some way of rendering it so it only has to paint once?
BTW: I know its wrong section but i wasn't getting anyone to help me..
Code:public class Class1{
JFrame MainFrame = new JFrame();
JPanel MainPanel = new Class2();
JScrollPane MainPane = new JScrollPane(MainPanel);
public Class1(){
MainFrame.setTitle("TEST");
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainFrame.add(MainPane);
MainPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
MainPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
MainPanel.setPreferredSize(new Dimension(100000, 100000));
MainFrame.setSize(810, 630);
MainFrame.setVisible(true);
MainFrame.setResizable(false);
MainFrame.setLocationRelativeTo(null);
}
public static void main(String[] args){
Class1 class1 = new Class1();
}
}
Code:
public class Class2 extends JPanel{
public Class2(){
setBackground(Color.green);
setFocusable(true);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
mapGraphics(g); objectsGrahpics(g); playerText(g); playerGraphics(g);
}
private void objectsGrahpics(Graphics g){
Graphics2D objectsGrahpics = (Graphics2D) g;
g.drawString("Test", 25,25);
}
private void mapGraphics(Graphics g){
Graphics2D mapGraphics = (Graphics2D) g;
g.drawString("Test", 50,60);
}
private void playerText(Graphics g){
}
private void playerGraphics(Graphics g){
Graphics2D CarGraphics = (Graphics2D) g;
}
