witam mam problem z rysowaniem, mam dwie klasy: pierwsza tworzy okno, druga natomiast będzie rysować kwadraty. problem polega na tym że metoda paint nie chce się wywoływać. proszę o pomoc, proszę w tej chwili nie czepiać się części logicznej kodu, program tak jak teraz jest według mnie już powinien coś rysować, chcę wiedzieć dlaczego tego nie robi, podwójne buforowanie zaimplementowałem.
o to kod:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.HeadlessException;
import javax.swing.JFrame;
/**
*
* @author marcin
*/
public class JavaApplication1 extends JFrame{
/**
* @param args the command line arguments
* program rysuje kwadrat z 9 malymi kwadratami w srodku w roznych kolorach
* kwadrat moze zmieniac pozycje
*/
private int widthWindow, heightWindow;
public JavaApplication1() {
widthWindow = 480;
heightWindow = 320;
setTitle("kolorowy kwadrat");
setSize(new Dimension(widthWindow, heightWindow));
setVisible(true);
//setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
public static void main(String[] args) {
// TODO code application logic here
JavaApplication1 javaApplication1 = new JavaApplication1();
KlasaKwadrat klasaKwadrat = new KlasaKwadrat();
klasaKwadrat.repaint();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JPanel;
/**
*
* @author marcin
*/
public class KlasaKwadrat extends JPanel{
private Image dbImage;
private Graphics dbGraphics;
private int widthSquare = 20;
private int heightSquare = 20;//ustawienie wielkosci kwadratu
private int startDrawPositionX = 30;
private int startDrawPositionY = 30;
static int [][]plansza = {{0, 1, 2},//rysowanie kwadratow
{3, 4, 5},
{6, 7, 8}
};
public void paint(Graphics graphics){
dbImage = createImage(getWidth(), getHeight());
dbGraphics = dbImage.getGraphics();
paintComponent(dbGraphics);
graphics.drawImage(dbImage, 0, 0, this);
}
public void paintComponent(Graphics graphics){
for(int i = 0; i < plansza.length; ++i){
for(int j = 0; j < plansza[0].length; ++j){
if(plansza[i][j] == 0){
graphics.setColor(Color.red);
graphics.fillRect((widthSquare * j) + startDrawPositionX,
(heightSquare * i) + startDrawPositionY,
widthSquare, heightSquare);
} else if(plansza[i][j] == 1){
} else if(plansza[i][j] == 2){
} else if(plansza[i][j] == 3){
} else if(plansza[i][j] == 4){
} else if(plansza[i][j] == 5){
} else if(plansza[i][j] == 6){
} else if(plansza[i][j] == 7){
} else if(plansza[i][j] == 8){
}
}
}
repaint();
}
}