Hi Again…
I have this piece of Code
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JProgressBar;
import sun.java2d.SunGraphics2D;
public class MainPanel extends JPanel {
private JPanel controlPanel = null;
private JPanel statusPanel = null;
private JLabel hplbl = null;
private JProgressBar healthPB = null;
private JLabel mplbl = null;
private JProgressBar manaPB = null;
private JProgressBar experiencePB = null;
private JPanel chatPanel = null;
private JPanel charUsePanel = null;
private ArrayList actors;
private BufferedImage background, backgroundTile;
private int backgroundY;
private SunGraphics2D graphics;
public MainPanel() {
super();
initialize();
}
public void game(){
initWorld();
}
private void initialize() {
this.setLayout(new BorderLayout());
this.setSize(800,600);
this.setOpaque(false);
this.add(getControlPanel(), java.awt.BorderLayout.SOUTH);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.fillRect(10,10,50,50);
g.setColor(Color.RED);
g.fillOval(220,250,50,50);
graphics =(SunGraphics2D) g;
}
public void initWorld(){
super.paint(graphics);
graphics.fillRect(20,20,50,50);
this.paint(graphics);
}
private JPanel getControlPanel() {
if (controlPanel == null) {
controlPanel = new JPanel();
controlPanel.setLayout(new BorderLayout());
controlPanel.add(getChatPanel(), java.awt.BorderLayout.EAST);
controlPanel.add(getCharUsePanel(), java.awt.BorderLayout.CENTER);
}
return controlPanel;
}
private JPanel getStatusPanel() {
if (statusPanel == null) {
hplbl = new JLabel();
mplbl = new JLabel();
statusPanel = new JPanel();
GridBagConstraints gbc = new GridBagConstraints();
statusPanel.setLayout(new GridBagLayout());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.CENTER;
gbc.ipadx = 15;
gbc.insets = new Insets(5,10,5,0);
hplbl.setText("HP");
mplbl.setText("MP");
statusPanel.add(hplbl, gbc);
gbc.gridx++;
statusPanel.add(getHealthPB(), gbc);
gbc.gridx = 0;
gbc.gridy++;
statusPanel.add(mplbl, gbc);
gbc.gridx++;
statusPanel.add(getManaPB(), gbc);
}
return statusPanel;
}
private JProgressBar getHealthPB() {
if (healthPB == null) {
healthPB = new JProgressBar();
healthPB.setValue(75);
healthPB.setString("Test");
healthPB.setStringPainted(true);
}
return healthPB;
}
private JProgressBar getManaPB() {
if (manaPB == null) {
manaPB = new JProgressBar();
manaPB.setString("test2");
manaPB.setStringPainted(true);
manaPB.setValue(65);
}
return manaPB;
}
private JProgressBar getExperiencePB() {
if (experiencePB == null) {
experiencePB = new JProgressBar();
experiencePB.setStringPainted(true);
}
return experiencePB;
}
private JPanel getChatPanel() {
if (chatPanel == null) {
chatPanel = new JPanel();
}
return chatPanel;
}
private JPanel getCharUsePanel() {
if (charUsePanel == null) {
charUsePanel = new JPanel();
charUsePanel.setLayout(new BorderLayout());
charUsePanel.add(getExperiencePB(), java.awt.BorderLayout.NORTH);
charUsePanel.add(getStatusPanel(), java.awt.BorderLayout.WEST);
}
return charUsePanel;
}
}
I have this problem that of which that I am unable to loop the repainting of components…
This means… after i have painted on to the component…
I want to loop the repainting to take place in a loop…
however… since Graphics is an abstract class I can’t seem to figure it out…
any helpers?
Thanks you!