Please help this is strange.
ok here is my code i followed my instructors working example to the letter and i am getting this error
H:\Pong\src\pong\Controls.java:54: error: non-static variable frame cannot be referenced from a static context
frame.paper.draw();
1 error
i am a beginning Java student and i am not asking for anyone to do my project for me just some help solving this error thanks
Code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pong;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*<p>Pong<p>
*<p>The Game<p>
*<p>Copyright; 2012<p>
*<p>Alien Software<p>
* @author Jason Miller
* @version 0.5.1
*/
public class Controls extends JFrame implements ActionListener{
private FlowLayout flo = new FlowLayout();
private JButton btnStart,btnStop;
private Timer tmrMoveBall = new Timer(10,new BallMover());
private PongCollisions frame;
public Controls(){
btnStart = new JButton("Start");
btnStop = new JButton("Stop");
this.setLayout(flo);
add(btnStart);
add(btnStop);
btnStart.addActionListener(this);
btnStop.addActionListener(this);
}
public Controls(PongCollisions frame){
this();
this.frame = frame;
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == btnStart){
tmrMoveBall.start();
}else{
tmrMoveBall.stop();
}
}
private static class BallMover implements ActionListener {
@Override
public void actionPerformed(ActionEvent ae) {
frame.paper.draw();
}
}
}
Re: Please help this is strange
Quote:
Originally Posted by
MillerJLee79
ok here is my code i followed my instructors working example to the letter and i am getting this error
H:\Pong\src\pong\Controls.java:54: error: non-static variable frame cannot be referenced from a static context
frame.paper.draw();
1 error
You are missing something. The code that you posted does not define a PongCollisions class, and I get three errors:
Code :
Controls.java:22: cannot find symbol
symbol : class PongCollisions
location: class pong.Controls
private PongCollisions frame;
^
Controls.java:35: cannot find symbol
symbol : class PongCollisions
location: class pong.Controls
public Controls(PongCollisions frame){
^
Controls.java:54: non-static variable frame cannot be referenced from a static context
frame.paper.draw();
^
3 errors
Are you absolutely sure that you are compiling the exact code that you posted?
Cheers!
Z
Re: Please help this is strange
Re: Please help this is strange.
The class BallMover should not be static. Make it non static. That would resolve the issue