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 4180
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 any color (string format #RRGGBB) by using div-tags.
regards
Stefan
###############code starts here#########################
|
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 GraphicsPath object but cannot work out the
shading part.
Is this also possible for say a circle with an outside line width of 10px to
be shaded from red...
|
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 dimension in the array,
I'd like to do something more like what's at the bottom of this post, but a
lack of understanding prevents me from doing it...
|
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 !!!
Dim bTracking As Boolean
Dim blackPen As Pen
Dim g As Graphics
| |
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
lines) on a trace so they can measure the time difference between markers.
Once they click on a desired location, on a trace, arrow buttons are...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |