Staram się napisać prosty edytor grafiki na uczelnię, ale już mam problem z samym narysowaniem obrazka z pliku. Plik jest wybierany z jFileChooser1 i ma być wyświetlony w jPanel2 (chyba że jest jakiś lepszy sposób). Do pisania używam NetBeans więc część kodu została dodana z automatu.
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = jFileChooser1.showOpenDialog(GrafikaView.this);
if (returnVal == jFileChooser1.APPROVE_OPTION) {
file = jFileChooser1.getSelectedFile();
try {
image = ImageIO.read(file);
} catch (IOException ex) {
Logger.getLogger(GrafikaView.class.getName()).log(Level.SEVERE, null, ex);
}
imagex=image.getWidth();
imagey=image.getHeight();
Dimension dimension = new Dimension(imagex, imagey);
jPanel2.setSize(dimension);
g.drawImage(image, imagex, imagey, null); <- Tu nie wiem co wstawić dokładnie...
}
}
Fragment kodu z menu Otwierania pliku. Gdy wybiorę plik dostaje java.lang.NullPointerException. Jakieś wskazówki?