Problemer med billeder
Hejsa,Jeg har en applet, som ikke viser de billeder den burde. Koden ser sådan ud:
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class FlytSpiller extends JApplet {
public void init() {
Container c = getContentPane();
TegnBane bane = new TegnBane(c);
}
}
class TegnBane extends JPanel {
private int x, y;
private TegnePanel tegnePanel;
private ImageIcon mand;
private ImageIcon bane;
private JCheckBox checkw;
private JCheckBox check;
private URL url;
public TegnBane(Container c) {
BorderLayout Layout = new BorderLayout();
JCheckBox check = new JCheckBox();
JCheckBox checkw = new JCheckBox();
check.setText("Flyt dig mand!");
try{
url = new URL("http://www.todi.dk/temp");
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
mand = new ImageIcon(url,"mand.jpg");
bane = new ImageIcon(url,"bane.gif");
tegnePanel = new TegnePanel();
c.add(checkw, Layout.NORTH);
c.add(tegnePanel, Layout.CENTER);
c.add(check, Layout.SOUTH);
tegnePanel.addMouseMotionListener(new MouseMotionListener());
tegnePanel.addMouseListener(new MouseListener());
c.setSize(450,290);
}
private class MouseMotionListener extends MouseMotionAdapter{
public void mouseDragged (MouseEvent e) {
// if (check.isSelected())
{
x = e.getX();
y = e.getY();
repaint();
}
}
}
private class MouseListener extends MouseAdapter
{
public void mousePressed (MouseEvent e)
{
mand = new ImageIcon(url,"mand2.jpg");
repaint();
}
public void mouseReleased (MouseEvent e)
{
mand = new ImageIcon(url,"mand.jpg");
repaint();
}
}
private class TegnePanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
bane.paintIcon(this, g, 0, 0);
mand.paintIcon(this, g, x-20, y-40);
repaint();
}
}
}
og den reagerer således: http://www.todi.dk/temp/bane.html
Nogen der ved hvad der er galt?
Mvh
PBLV