Cześć
Napisałem kod wyświetlający obrazek z pliku:
public class RysowanieTest extends JPanel
{
public void paintComponent(Graphics g)
{
// g.setColor(Color.ORANGE);
// g.fillRect(20, 50, 100, 100);
Image picture = new ImageIcon("C:/Users/Rubesom/Thinking Java/Kurs/src/Grafika/test.jpg").getImage();
g.drawImage(picture, 3, 4, this);
}
public static void main(String[] args)
{
RysowanieTest gui1 = new RysowanieTest();
JButton przycisk1 = new JButton("Button1");
JFrame frame = new JFrame();
frame.setSize(300, 300);
frame.setVisible(true);
frame.add(gui1);
frame.add(BorderLayout.SOUTH, przycisk1);
}
}
Ale kiedy będę miał plik jar to już przy takim sposobie podania lokalizacji pliku mi to nie zadziała. Jak sobie z czymś takim radzić?
Doczytałem, że muszę chyba użyć metodygetPath
ale nie chce mi działać taki kod:
File file = new File("test.jpg");
Image picture2 = ((file) new ImageIcon()).getPath();
Dostaję informacje "file cannot be resolved to a type".