Prikker skal dukke op
Hey.Nogen der kan fortælle mig hvorfor boldene ikke kommer frem når man trykker??
---
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class Applet1 extends JApplet
{
public static Container c;
public Bold bold = new Bold();
public Bold bold2 = new Bold();
private XYLayout xYLayout;
public Applet1()
{
}
public void init()
{
try
{
c = getContentPane();
c.setBackground(new Color(100,100,100));
c.setLayout(xYLayout);
c.addMouseListener(new musselytter());
c.add(bold2, new XYConstraints(50, 50, 20, 20));
}
catch (Exception e)
{
e.printStackTrace();
}
}
private class musselytter
extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
bold = new Bold();
c.add(bold, new XYConstraints(e.getX() - 10, e.getY() - 10, 20, 20));
}
}
public class Punkt extends Thread
{
private Bold bold;
public Punkt(Bold _bold)
{
bold = _bold;
}
public void run()
{
c.validate();
bold.setVisible(true);
try
{
bold.setOpaque(false);
for (int i = 20; i > 0; i--)
{
bold.setX(i);
repaint();
this.sleep(100);
}
}
catch (Exception e)
{
}
bold.setVisible(false);
c.remove(bold);
}
}
public class Bold
extends JPanel
{
private int x;
public Bold()
{
}
public void setX(int _x)
{
x = _x;
}
public void paintComponent(Graphics g)
{
super.paintComponents(g);
g.setColor(Color.BLACK);
g.fillOval( (20 - x) / 2, (20 - x) / 2, x, x);
g.setColor(Color.WHITE);
g.fillOval( (20 - x) / 2 + 1, (20 - x) / 2 + 1, x - 2, x - 2);
}
}
}
