import java.applet.*; import java.awt.*; import java.awt.event.*; public class Laineline2 extends Applet implements MouseListener { int mitmes=0; int x1,y1,x2,y2,x; public void init(){ clearMe(); addMouseListener(this); } void clearMe() { getGraphics().clearRect(0, 0, getSize().width, getSize().height); } private void drawSine() { Graphics g = getGraphics(); int juppe = 10; double d = (Math.abs(x1-x2) + Math.abs(y1-y2)); int dist = 2; double ddy = (x2-x1) / (dist*juppe); double ddx = (y2-y1) / (dist*juppe); int oldx = x1; int oldy = y1; for (int i = 0; i < d; i++) { int x = (int)(x1 + (i/d) * (x2-x1)); int y = (int)(y1 + (i/d) * (y2-y1)); double diff = Math.sin(2 * juppe * 3.14159264 * i / d); int dx = -(int)(ddx * diff); int dy = (int)(ddy * diff); g.setColor(Color.green); g.drawLine(oldx, oldy, x+dx, y+dy); oldx = x+dx; oldy = y+dy; } } private void setPoint(MouseEvent e) { Graphics g=getGraphics(); g.setColor(Color.red); mitmes %= 2; if ((mitmes%2) == 0) { clearMe(); } g.drawString(mitmes+" ",e.getX(),e.getY()); mitmes++; if (mitmes==1) { x1=e.getX(); y1=e.getY(); } if (mitmes==2) { x2=e.getX(); y2=e.getY(); drawSine(); } } public void mousePressed (MouseEvent e) { setPoint(e); } public void mouseReleased(MouseEvent e) { setPoint(e); } public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseClicked(MouseEvent e){} }