I'm a starter at Java. I'd like to create a Form class that extends JFrame to use. Everything works ok, it sizes and centers well on the screen. I just can't add components to it. What am I missing. Googled every class up, couldn't find anything.
Main.java:
package pongLib;
import pongUI.*;
public class Main {
public static void main(String[] args) {
Form frm = new Form(600,500,"Pong");
}
}
Form.java:
package pongUI;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Form extends JFrame {
private int width;
private int height;
private int posx;
private int posy;
private String title;
public Form(int width, int height, String title) {
//call parent constructor
super();
//set size
this.width=width;
this.height=height;
//set title
this.title=title;
//get position(x,y)
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Double x = (screen.getWidth()-this.width)/2;
Double y = (screen.getHeight()-this.height)/2;
posx = x.intValue();
posy = y.intValue();
//add components
JLabel points1Label = new JLabel("The Rookie (aka You)");
this.addComponent(points1Label, 10, 50);
//set form properties
this.setLayout(null);
this.setSize(width, height);
this.setLocation(posx, posy);
this.setResizable(false);
this.setTitle(title);
this.setVisible(true);
public void addComponent(Component c, int posx, int posy) {
c.setLocation(posx, posy);
this.getContentPane().add(c,BorderLayout.CENTER);
}
}