bin schwerer anfänger und will mal eine kleine animation programmieren. ich hab hier ein buch vor mir, das mir sagt, wie ich sowas bei einem applet machen müsste. ich hab das gleiche bei einer applikation versucht, nur das geht bei mir einfach nicht. kann mir hier jemand helfen? ich kriege die ganze zeit die meldung: "dreide.java:73: non-static variable ani cannot be referenced from a static context
ani=new mAnimation();
^
dreide.java:73: non-static variable this cannot be referenced from a static context
ani=new mAnimation();
^
dreide.java:74: non-static variable ani cannot be referenced from a static context
ani.start();"
bei dem code:
Alles anzeigen
danke im voraus, dominik.
ani=new mAnimation();
^
dreide.java:73: non-static variable this cannot be referenced from a static context
ani=new mAnimation();
^
dreide.java:74: non-static variable ani cannot be referenced from a static context
ani.start();"
bei dem code:
Java-Quellcode
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- public class dreide extends JFrame {
- mCanvas spielfeld;
- int x=0;
- int y=0;
- mAnimation ani;
- dreide(String title) {
- super(title);
- getContentPane().setLayout(new FlowLayout());
- spielfeld=new mCanvas();
- getContentPane().add(spielfeld);
- class mWindowAdapter extends WindowAdapter {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- }
- addWindowListener(new mWindowAdapter());
- }
- class mCanvas extends Canvas {
- mCanvas() {
- setBackground(Color.black);
- setForeground(Color.white);
- }
- public void paint(Graphics g) {
- g.translate(150,150);
- g.fillOval(x,y,3,3);
- }
- public Dimension getMinimumSize() {
- return new Dimension(300,300);
- }
- public Dimension getPreferredSize() {
- return getMinimumSize();
- }
- }
- class mAnimation extends Thread {
- public void run() {
- while(isInterrupted()==false) {
- x++;
- repaint();
- try {
- sleep(40);
- }
- catch(InterruptedException e) {
- return;
- }
- }
- }
- }
- public static void main(String[] args) {
- dreide fenster=new dreide("test");
- fenster.pack();
- fenster.setSize(300,300);
- fenster.setResizable(false);
- fenster.show();
- ani=new mAnimation();
- ani.start();
- }
- public void start() {
- if(ani==null) {
- ani=new mAnimation();
- ani.start();
- }
- }
- public void stop() {
- if(ani==null) {
- ani.interrupt();
- ani=null;
- }
- }
- public void destroy() {
- if(ani==null) {
- ani.interrupt();
- ani=null;
- }
- }
- }
danke im voraus, dominik.
Gruss Dominik.
*g*
ich werd vielleicht in einer woche nochmals mit dem problem auftauchen. thx