i am trying to draw an array of lines where the user will be able to draw multiple lines
here is the code but it is not working well and i don't know why - import java.applet.Applet;
-
import java.awt.Graphics;
-
import java.awt.event.MouseAdapter;
-
import java.awt.Color;
-
import java.awt.event.MouseMotionListener;
-
import java.awt.event.MouseEvent;
-
import java.awt.event.MouseListener;
-
-
-
public class MultipleLineClass extends Applet{
-
int x1,y1,x2,y2;
-
MyLine[] obj = new MyLine[5];
-
int i=0;
-
public void init(){
-
addMouseListener(new MyButtonListener());
-
addMouseMotionListener(new MyButtonListener());
-
-
}
-
public void paint(Graphics g){
-
for(int j=0 ; j<i ; j++){
-
g.setColor(Color.red);
-
g.drawLine(x1,y1,x2,y2);
-
}
-
}
-
class MyButtonListener extends MouseAdapter implements MouseMotionListener,MouseListener{
-
public void mousePressed(MouseEvent e){
-
x1 = e.getX();
-
y1 = e.getY();
-
}
-
public void mouseDragged(MouseEvent e){
-
x2 = e.getX();
-
y2 = e.getY();
-
obj[i] = new MyLine(x1,y1,x2,y2);
-
i+=1;
-
repaint();
-
}
-
public void mouseMoved(MouseEvent e){}
-
}
-
-
class MyLine{
-
-
MyLine(int xx1, int yy1, int xx2, int yy2){
-
x1=xx1;
-
x2=xx2;
-
y1=yy1;
-
y2=yy2;
-
}
-
-
}
-
-
}
1 4175
i have modified the code but still not working and i want to know the solution! - import java.applet.Applet;
-
import java.awt.Graphics;
-
import java.awt.event.MouseAdapter;
-
import java.awt.Color;
-
import java.awt.event.MouseMotionListener;
-
import java.awt.event.MouseEvent;
-
import java.awt.event.MouseListener;
-
-
-
public class MultipleLineClass extends Applet{
-
int x1,y1,x2,y2;;
-
MyLine[] obj = new MyLine[10];
-
-
int i=0;
-
public void init(){
-
addMouseListener(new MyButtonListener());
-
addMouseMotionListener(new MyButtonListener());
-
-
}
-
public void paint(Graphics g){
-
if(i<10){
-
for(int j=0 ; j<i ; j++){
-
g.setColor(Color.red);
-
g.drawLine(obj[j].getX1(),obj[j].getY1(),obj[j].getX2(),obj[j].getY2());
-
}
-
}
-
}
-
class MyButtonListener extends MouseAdapter implements MouseMotionListener,MouseListener{
-
public void mousePressed(MouseEvent e){
-
x1 = e.getX();
-
y1 = e.getY();
-
-
}
-
public void mouseDragged(MouseEvent e){
-
x2 = e.getX();
-
y2 = e.getY();
-
obj[i] = new MyLine(x1,y1,x2,y2);
-
-
repaint();
-
}
-
-
public void mouseMoved(MouseEvent e){}
-
}
-
-
class MyLine{
-
-
MyLine(int xx1, int yy1, int xx2, int yy2){
-
x1=xx1;
-
x2=xx2;
-
y1=yy1;
-
y2=yy2;
-
}
-
public int getX1(){return x1;}
-
public int getX2(){return x2;}
-
public int getY1(){return y1;}
-
public int getY2(){return y2;}
-
-
-
}
-
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Stefan Burger |
last post by:
Those of you who are in need for drawing vector lines might be interested in
the following code.
DrawLine( x1, y1, x2, y2, color ) draws a vector line from any Point x1,y1
to any Point x2,y2 in...
|
by: John Baro |
last post by:
I wish to draw a line say 10px wide at a 45 degree angle (or any other
angle) and have it shaded say from gray to red to gray again (or any other
color).
I can get the line by using a...
|
by: peshrad |
last post by:
Hi !
I'm using ASP.NET 1.1 and C# .
For Microsoft Internet Explorer 6.0,
the following code suppresses the drawing of horizontal and vertical lines
in the web page:
|
by: Eric Sabine |
last post by:
Below is a sub I have which contains 4 lines of code. I would like to
reduce it to 1. My problem is that it takes 3 lines to create the array to
hold the sql parameter and since there's only one...
|
by: Manuel Daponte |
last post by:
I found this code in this newsgroup and used it, but the lines drawn
are composed of point too separated when the mouse moves at medium or
fast speed. How can I fix it?
Thanks in advance !!!
...
| |
by: Galen Somerville |
last post by:
In my opinion, one of the worst failures of Net (VB2005 Pro) was not
providing an XOR line draw feature, as in VB6.
A major feature of my app is allowing the user to draw Markers (vertical...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |