I have been commissioned for a tetris final project and I have no idea how to do it since I have not worked with graphical interfaces. They are asking me to use Jpanel and JFrame for the graphic part, and the logical part in a matrix.
I have to do different classes, and I only have the two most basic ones.
-class point: one to define the points of each box of the four that form each figure
Class box: where I use the class point to make a single square and draw it with .drawRect ()
This is my Point class
package Tetris;
public class Punto {
int x,y;
public void setx(int mix){
x=mix;
}
public void sety(int miy){
y=miy;
}
public int getx(){
return x;
}
public int gety(){
return y;
}
}
And this is my class box
package Tetris;
import javax.swing.*;
import java.awt.*;
public class Cuadro extends JPanel {
Punto p0,p1;
Cuadro(int a, int b, int i, int j) {
p0=new Punto();
p0.setx(a);
p0.sety(b);
p1=new Punto();
p1.setx(i);
p1.sety(j);
}
public Punto getP0()
{
return p0;
}
public Punto getP1()
{
return p1;
}
public void movex(int i)
{
p0.setx(i);
p1.setx(i);
}
public void movey(int j)
{
p0.sety(j);
p1.sety(j);
}
public Punto getp0()
{
return p0;
}
public Punto getp1()
{
return p1;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawRect(p0.getx(), p0.gety(), p1.getx()-p0.getx(), p1.gety()-p0.gety());
}
}
And then I have to create a new class to make the complete figure using four objects of the class box and that's where I have no idea what to do.
My main question is how can I inherit four frames in my figure class and draw them in the frame? What I can do is place in the frame a single direct frame of the class box, but what I need is to place four frames in my figure class and then place that figure in the frame.
and then my teacher does not understand anything (Because it is not explained). So if you help me with that doubt, it would be very helpful for me.