one more thing i want to know i want to generate fishes at random positions
speed is distance and time, try increasing the distance each fish/bubble travels each time the timer fires.
more likely to be a random starting position for each fish/bubble.
in this case, all bubbles start at the same 'y', so its a matter or generating a random 'x'
similarly for fish, they have the same 'x' (unless you want them to randomly swim
left-to-right as well as right-to-left, then you have 2 * 'x's to factor in).
public void actionPerformed(ActionEvent e) {
Cfish fish = new Cfish();
if(e.getActionCommand().equals("button"))
{
fish.x = 0;
fish.y = 0;
fish.dx = 0;
fish.dy = 0;
}
}
but you should stop the timer - pointless repainting 0-size fishes at a new x,y
Cfish fish = new Cfish();
Cpoint c = new Cpoint();
if(e.getActionCommand().equals("button"))
{
fish.dx = 0;
fish.dy = 0;
c.timer.stop();
c.repaint();
c.timer.stop();
ImageIcon image = new ImageIcon("c:\\Fish.jpg");
public JLabel label=new JLabel(image);
radius = fishImg.getWidth(null)/2;
class Cair extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawString("Hello", 20, 20);
}
}
Cair ca= new Cair();
c.add(ca, BorderLayout.EAST);
We can walk to school together. And we can both read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|