Please let me state that this is for a homework assignment and any help would be appreciated.
I am am writing a program using Eclipse (Juno) that creates a frame, places a ball in the top of the frame and places a row of buttons on the ‘south’ of the border frame. The issue I am having is in the class that adds the buttons, called Btns.java, I am receiving some errors.
Error 1: add cannot be resolved to a variable
Error 2: Constructor call must be the first statement in a constructor
Error 3: Syntax error on token “.”, super expected after this token
The code looks correct to me never the less.
The code for the Btns class is below.
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Btns extends JFrame
{
public Btns()
{
JButton jbtL = new JButton("Left");
JButton jbtR = new JButton("Right");
JButton jbtU = new JButton("Up");
JButton jbtD = new JButton("Down");
JButton jbtRd = new JButton("Red");
JButton jbtG = new JButton("Green");
add.(jbtL);
add.(jbtR);
add.(jbtU);
add.(jbtD);
add.(jbtRd);
add.(jbtG);
}
}
Lab2.java Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Lab2 extends JFrame {
public Lab2()
{
setLayout(new BorderLayout());
add(new Ball(), BorderLayout.CENTER);
add(new Btns(), BorderLayout.SOUTH);
}
public static void main (String[] args) {
Lab2 frame = new Lab2();
frame.setTitle("Move The Ball");
frame.setSize(450, 700);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
You have extra dots here before the method parenthesis:
Replace:
with