1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| import java.awt.Graphics;
import java.awt.Color;
import java.awt.Point;
import java.applet.AudioClip;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class mouse1 extends java.applet.Applet
implements MouseListener, MouseMotionListener {
public mouse1() {
}
private final int MAXLINES = 100;
private Point[] starts;
private Point[] ends;
private Point anchor;
private Point currentpoint;
private int currlines;
private AudioClip tooMany;
// allocate the array of Points, set the background color, load the error sound
public void init() {
starts = new Point[MAXLINES];
ends = new Point[MAXLINES];
setBackground(Color.white);
currlines = 1;
// tooMany = getAudioClip(getCodeBase(),"bong.au");
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
// start a new line when the user depresses the mouse
public void mousePressed(MouseEvent e)
{
anchor = new Point(e.getX(),e.getY());
repaint();
;
}
// draw the potential line as the user drags the mouse around
public void mouseDragged(MouseEvent e)
{
currentpoint = new Point(e.getX(),e.getY());
repaint();
}
public void mouseMoved(MouseEvent e) { }
// add the new line when the user releases the mouse button
public void mouseReleased(MouseEvent e)
{
if (currlines < MAXLINES)
{addline(e.getX(),e.getY());
}
else {
tooMany.play();
currentpoint = null;
repaint();
}
}
public void mouseClicked(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
void addline(int x, int y) {
starts[currlines] = anchor;
ends[currlines] = currentpoint;
currlines++;
currentpoint = null;
repaint();
}
// the existing lines, then draw the potential line in blue
public void paint(Graphics g) {
int ystart=50;
int marg=10;
//premier
g.drawRect(25, 30, 50, 20);
g.drawString("UE", 42, 45);
for(int i=1;i<=20;i++)
{g.drawLine(50,marg*(i-1)+i*ystart, 50, marg*(i-1)+(i+1)*ystart);}
//deuxieme
g.drawRect(175, 30, 50, 20);
g.drawString("NodeB", 182, 45);
for(int i=1;i<=20;i++)
{g.drawLine(200,marg*(i-1)+i*ystart, 200, marg*(i-1)+(i+1)*ystart);}
//troisieme
g.drawRect(325, 30, 50, 20);
for(int i=1;i<=20;i++)
{g.drawLine(350,marg*(i-1)+i*ystart, 350, marg*(i-1)+(i+1)*ystart);}
g.drawString("SRNC", 333, 45);
//quatrieme
g.drawRect(475, 30, 50, 20);
for(int i=1;i<=20;i++)
{g.drawLine(500,marg*(i-1)+i*ystart, 500, marg*(i-1)+(i+1)*ystart);}
g.drawString("DRNC", 483, 45);
//cinquieme
g.drawRect(625, 30, 50, 20);
for(int i=1;i<=20;i++)
{g.drawLine(650,marg*(i-1)+i*ystart, 650, marg*(i-1)+(i+1)*ystart);}
g.drawString("CN", 640, 45);
g.setColor(Color.blue);
for (int i = 0 ; i < currlines ; i++)
{ //g.drawLine(starts[i].x,starts[i].y,ends[i].x,ends[i].y);
int y=55;
if (anchor.x>40 && anchor.x<60 && (currentpoint.x>340 && currentpoint.x<360)){
g.setColor(Color.blue);
new jliste();
y=y+60;
g.drawLine(50, y, 350, y);
}
else if (anchor.x>190 && anchor.x<200 && (currentpoint.x>340 && currentpoint.x<360)){
g.setColor(Color.blue);
new jliste();
y=y+60;
g.drawLine(200,y, 350, y);
}
else if (anchor.x>340 && anchor.x<360 && (currentpoint.x>490 && currentpoint.x<510)){
g.setColor(Color.blue);
new jliste();
y=y+60;
g.drawLine(350,y, 500, y);
}
else if (anchor.x>340 && anchor.x<360 && (currentpoint.x>640 && currentpoint.x<660)){
g.setColor(Color.blue);
new jliste();
y=y+60;
g.drawLine(350,y, 650, y);
}
g.drawLine(anchor.x,anchor.y,currentpoint.x,currentpoint.y);
} }
} |
Partager