Auf Thema antworten

Ui ui   sorry das ging mir jetzt etwas zu schnell :eek:

Ich frag lieber nochmal nach.. bin wieder dabei wild drauflos zu schreiben bzw es irgendwie hinzumurksen.




[CODE]@Override

public void paintComponent(Graphics g)

{

g.fillOval (200,200,100,100);   //only to check that nothing is happening :D

}[/CODE]




[CODE]public Graphics g;[/CODE]



 

Öhm  da hörts komplett bei mir auf - wäre für einen neuen Hinweis sehr dankbar :D


 [SPOILER="MainProgram.java"]

[CODE]package game.program;


import game.logic.MouseThread;


import java.awt.Graphics;

import java.util.ArrayList;


import javax.swing.JFrame;


public class MainProgram{

 

    private JFrame mainFrame=new JFrame();   

    private ArrayList<MouseThread> mice=new ArrayList<MouseThread>();

    private MouseThread tmpThread;

   

    public Graphics g;

   

    private void addMouse()

    {

        tmpThread=new MouseThread(g);

        mice.add(tmpThread);

        tmpThread.start();   

        //Thread repaintThread=new Thread();

        //repaintThread.start();

    }

       

    MainProgram()

    {

        mainFrame.setSize(700, 700);

        mainFrame.setTitle("Simulation-Test");

        mainFrame.setVisible(true);

    }

   

    public static void main(String[] args)

    {

        MainProgram mainProg = new MainProgram();

       

        for(int i=0;i<=3;i++)

        {

            mainProg.addMouse();

           

        }

    }

   

    //@Override

    public void paintComponent(Graphics g) {

        this.g.fillOval(200, 200, 100, 100);

    }

   

    //@Override

    public void run()

    {

        while(true)

        {

            System.out.println(Thread.currentThread().getName());

            //repaint();

        }

    }

}

[/CODE]

[/SPOILER]


[SPOILER="MouseThread"]

[CODE]package game.logic;


import java.awt.Graphics;


public class MouseThread extends Thread implements Runnable {

    private int posX = RandomPositionStart.createRandom(200);

    private int posY = RandomPositionStart.createRandom(200);

   

    public MouseThread(Graphics g)

    {

        new Mouse(g);

    }

   


    public void run()

    {

        while (true)

        {

            try {

                Thread.sleep(700);

            } catch (InterruptedException ex) {

            }

            this.moveMouse();

            System.out.println("ThreadID: " + this.getId() + " | PosX: " + posX  +  "PosY: " + posY);

        }

    }

   

    public void moveMouse()

    {

        this.posX=this.posX+20;

        this.posY=this.posY+20;

    }



    public int getPosX() {

        return posX;

    }



    public int getPosY() {

        return posY;

    }

}[/CODE]


[/SPOILER]



[SPOILER="Mouse.java"]

[CODE]package game.logic;


import java.awt.Graphics;

import java.awt.Image;

import java.io.File;

import java.io.IOException;


import javax.imageio.ImageIO;

import javax.swing.JComponent;


public class Mouse extends JComponent {

    private Image mouseImg;

    private Graphics g;


    public Mouse(Graphics g) {

        this.g=g;

        try {

            mouseImg = ImageIO.read(new File("src/images/mouse.png"));

        } catch (IOException e) {

            e.printStackTrace();

        }

    }


   

    public void paintComponent(Graphics g) {

        this.g.drawImage(mouseImg, this.getX(), this.getY(), this);

        this.g.drawLine(0, 0, 10, 20);

    }

   

    public void renderMouseGui() {

        //this.g.drawImage(mouseImg, this.getX(), this.getY(), this);

        //this.g.drawLine(0, 0, 10, 20);

    }

}[/CODE][/SPOILER]


Ich hab mal meine drei Files reingestellt. 


Vielen Dank schonmal für die Hilfe ;-)



Oben