Mam problem z MalformedURLException. Dopiero uczę się obsługi wyjątków. Wstawiam kod:
public ImagePanel() throws MalformedURLException {
super();
File imageCompFile = new File("TUTAJ JEST LOGO Z DYSKO");
URL imageNetFile = new URL(
"TUTAJ JEST LOGO Z ADRESU URL"
);
try {
imageFromComp = ImageIO.read(imageCompFile);
} catch (IOException name) {
System.err.println("No i dup*");
name.printStackTrace();
}
try {
imageFromNet = ImageIO.read(imageNetFile);
} catch (MalformedURLException name2) {
System.out.println("Ble ble ble");
name2.printStackTrace();
} catch (IOException name3) {
System.out.println("le le le");
name3.printStackTrace();
}
Dimension dimension = new Dimension(imageFromComp.getWidth(), imageFromComp.getHeight());
setPreferredSize(dimension);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(imageFromComp, 0, 0, this);
g2d.drawImage(imageFromNet, 0, 0, this);
}
public class ImageFrame extends JFrame {
public ImageFrame() throws MalformedURLException {
super();
JPanel ImagePanel = new ImagePanel();
add(ImagePanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
}
public class Test {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ImageFrame();
}
});
}
}
Jak sami widzicie, już bardzo chaotycznie/intuicyjnie próbuje do tego podejść z braku pomysłów (zrozumienia?). Co nie zrobię, w jednym lub innym miejscu wyskakuje unreported exception java.net.MalformedURLException; must be caught or declared to be thrown.
Z góry dziękuje za pomoc.