// File: sinpanel. Java
Import java. AWT .*;
Import javax. Swing .*;
Public class sinpanel extends jpanel {
Public void paintcomponent (Graphics g ){
Super. paintcomponent (g );
Dimension panelsize = This. getsize ();
LOCATION Center = new location (panelsize. width/2, panelsize. Height/2 );
Int radius = (INT) (math. Min (panelsize. Width, panelsize. Height)/2) * 0.9 );
// Determine the coordinates of each vertex
Int [] x = new int [2 * radius + 1];
Int [] Y = new int [2 * radius + 1];
For (INT I = 0; I <2 * radius + 1; I ++ ){
X [I] = center. X-radius + I;
Double Y1 = math. sin (double) (-radius + I)/radius) * 4 * Math. pi); // This is very important. Sin () must be a double value.
Int y2 = (INT) (Y2*100 );
Y [I] = center. Y-Y2;
}
G. setcolor (color. Black );
// Draw the coordinate axis
G. drawline (center. X-radius, Center. Y, Center. x + radius, Center. y );
G. drawline (center. X, Center. Y-radius, Center. X, Center. Y + radius );
G. drawline (center. x + radius, Center. Y, Center. x + radius-10, Center. Y-7 );
G. drawline (center. x + radius, Center. Y, Center. x + radius-10, Center. Y + 7 );
G. drawline (center. X, Center. Y-radius, Center. X-7, Center. Y-radius + 10 );
G. drawline (center. X, Center. Y-radius, Center. x + 7, Center. Y-radius + 10 );
G. drawpolyline (X, Y, 2 * radius + 1 );
G. setcolor (color. Red );
G. setfont (new font ("scanserif", Font. Bold, 12 ));
G. drawstring ("X", Center. x + radius, Center. Y-10 );
G. drawstring ("Y", Center. x + 10, Center. Y-radius );
}
}
========================================================== ==================================
// File: myframe. Java
Import java. AWT .*;
Import javax. Swing .*;
Public class myframe extends jframe {
Public myframe (){
Container = This. getcontentpane ();
Container. setlayout (New borderlayout ());
Sinpanel = new sinpanel ();
Container. Add (sinpanel, borderlayout. center );
This. settitle ("show sin fuction! ");
This. setsize (new dimension (400,400 ));
This. setdefaclocloseoperation (jframe. exit_on_close );
Dimension screensize = toolkit. getdefatooltoolkit (). getscreensize ();
Dimension framesize = This. getsize ();
This. setlocation (screensize. Width-framesize. width)/2,
(Screensize. Height-framesize. Height)/2 );
This. setvisible (true );
}
Public static void main (string [] ARGs ){
Myframe = new myframe ();
}
}
========================================================== ========================
// File: location. Java
Public class location {
Public int X;
Public int y;
Public location (int x, int y ){
This. x = X;
This. Y = y;
}
}