proper rotation of 3d object

Hi guys

I have a problem with my 3d rotation function. Basically, I want to rotate an object that I get from a txt file (I already know how to read the file and store the coordinates in an array) on the center x-axis (meaning from the screen). Right now, it's rotating on it's own axis instead on the axis of the screen. I eventually want to make a bunch of these cubes and connect them together and get them all to rotate together how you would normally rotate a cube.

Another problem is I do not not know how to use the drawPolygon function because When I rotate the cubes i want them to be colored on their front side and the only way to do that is to make it as a polygon.

And finally, I can't seem to fix the problem where when I rotate the object, it slowly gets smaller and deforms its shape.

I will provide all the code I have for rotating and scaling the lines:

__Rotation__

x = (x * cos(angle) - z * sin(angle))

z = (x * sin(angle) + z * cos(angle))

__Scaling__

double con = 20;

double scale = (con/(con - z)); // z + in

double scale1 = (con / (con - z1)); //z1 + in

double b1 = ((x * scale) * (10)) + 500;

double b2 = ((y * scale) * (10)) + 500;

double b3 = ((x1 * scale1) * (10)) + 500;

double b4 = ((y1 * scale1) * (10)) + 500;

__Drawing__

g.drawLine((int)b1 + r ,(int)b2 +u ,(int)b3 +r ,(int)b4+u )

the r's and u's are just for moving the lines horizontally or vertically altogether

If anyone is able to assist me, I would really appreciate it