in this programm , you will drow line , then it will be reflicted in four qurtares,..
i hope you will like it ,
and as usual , if there is any question ... just post it.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class GUITest extends JFrame
implements MouseListener, MouseMotionListener {
private JLabel statuse;
private Point point = new Point();
private Point FrameSize = new Point();
private int MaxX, MaxY;
boolean Refresh;
//constuctor
public GUITest()
{
super("Drow in mirror shape");
statuse = new JLabel();
getContentPane().add(statuse , BorderLayout.SOUTH);
getContentPane().setBackground(Color.WHITE);
setBackground(Color.WHITE);// the back ground color
addMouseListener(this);
addMouseMotionListener(this);
MaxX = 600;
MaxY = 400;
setSize(MaxX,MaxY);
setVisible(true);
}// end constructo
// print the status---------------------------------------------------------
private void setText(String string)
{
statuse.setText(string);
}
//
//the Mouse Listen Values **
//mouseClicked--------------------------------------------------------------
public void mouseClicked (MouseEvent event)
{
}
//mousePressed--------------------------------------------------------------
public void mousePressed(MouseEvent event)
{
}
//mouseReleased-------------------------------------------------------------
public void mouseReleased(MouseEvent event)
{
}
//mouseEntered--------------------------------------------------------------
public void mouseEntered(MouseEvent event)
{
}
//mouseExited---------------------------------------------------------------
public void mouseExited(MouseEvent event)
{
}
//mouseDragged--------------------------------------------------------------
public void mouseDragged(MouseEvent event)
{
point.x = event.getX();
point.y = event.getY();
repaint();
}
//mouseMoved----------------------------------------------------------------
public void mouseMoved(MouseEvent event )
{
}
//the drawing---------------------------------------------------------------
public void paint(Graphics g)
{
//super.paint(g);
// if any change in the size of the frame
FrameSize.x = getContentPane().getWidth();
FrameSize.y = getContentPane().getHeight();
g.setColor(Color.RED); // the drowing line color
g.fillRect(point.x, point.y,3,3);
// to avoid doing mirror at the beggining of the program
if(!((point.x == 0) && (point.y == 0)))
{printMirror(g);}
}// end paint method
// print in mirror formate--------------------------------------------------
private void printMirror (Graphics g)
{
int Qurater;
int Xsign =1, Ysign=1;
int DiffrentX, DiffrentY;
Point point1, point2 , point3;
if ((point.x >= FrameSize.x/2) && ((point.y >= FrameSize.y/2))){Qurater = 1;}
else if ((point.x >= FrameSize.x/2) && ((point.y <= FrameSize.y/2))){Qurater = 4;}
else if ((point.x <= FrameSize.x/2) && ((point.y <= FrameSize.y/2))){Qurater = 2;}
else {Qurater = 3;} //((point.x <= FrameSize.x) && ((point.y >= FrameSize.y)))
// find the deffrent
DiffrentX = (Math.max((FrameSize.x)/2,point.x)- Math.min((FrameSize.x)/2,point.x));
DiffrentY = (Math.max((FrameSize.y)/2,point.y)- Math.min((FrameSize.y)/2,point.y));
// the sign of the regon
switch(Qurater)
{
case 1:
Xsign = -1;
Ysign = -1;
break;
case 2:
Xsign = 1;
Ysign = 1;
break;
case 3:
Xsign = 1;
Ysign = -1;
break;
case 4:
Xsign = -1;
Ysign = 1;
break;
default:
break;
}// end switch
//set the new points
// diagnola
point1 = new Point();
point1.x = (point.x + (2*Xsign * DiffrentX));
point1.y = (point.y + (2*Ysign * DiffrentY));
//g.setColor(Color.black); //<- if you wish to change the refliction color
g.fillRect(point1.x, point1.y,3,3);
// Vertical refliction
point2 = new Point();
point2.x = point.x;
point2.y = (point.y + (2*Ysign * DiffrentY));
g.fillRect(point2.x, point2.y,3,3);
// horizantel refliction
point3 = new Point();
point3.x = (point.x + (2*Xsign * DiffrentX));;
point3.y = point.y;
g.fillRect(point3.x, point3.y,3,3);
}
public static void main(String[] args) {
System.out.println("\n\n\tStart the main Method:\n");
// the call for the classes start from hear ---VV--V--Vv ----vV-------------
//GUITest test = new GUITest();
GUITest test = new GUITest();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// the call for the classes end hear ------------^^-^^^---^-^^^^^-----------
}//end the main method
}// end class