aspose file tools*
The moose likes Applets and the fly likes How to shrink/grow lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How to shrink/grow lines " Watch "How to shrink/grow lines " New topic
Author

How to shrink/grow lines

Giri Regu
Greenhorn

Joined: Apr 03, 2006
Posts: 15
Hi To all

i am developing a paint application in applet.
i am very strange for this applications.
i am facing lot of problems in that.
that is listed below.
1.how to select a particular from morethan one line.
2.how to move line around panel easily
3.how to grow and shrink the selected lines.

please give a solution for the above my questions.

i am developing some initial code for this application thst is below


using this code we can draw lines and gow also but its not full furnished
.
please help me.

thanks in advance

regards
Giri

[ UD: added code tags ]
[ March 09, 2007: Message edited by: Ulf Dittmer ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
What does the code do now, and what do you want it to do? Where are you stuck implementing the changes?


Ping & DNS - my free Android networking tools app
Giri Regu
Greenhorn

Joined: Apr 03, 2006
Posts: 15
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**
* <applet code="DrawLine.class" height=500 width=500>
* </applet>
*/

public class DrawLine extends Applet implements ActionListener, MouseListener, MouseMotionListener
{
int width, height;
int x, y; // the coordinates of the upper-left corner of the box
int mx, my; // the most recently recorded mouse coordinates
boolean isMouseDragging = false;
Graphics g;
int flag=0;

public void init() {
width = getSize().width;
height = getSize().height;

setBackground( Color.black );

x = width/2 - 40 ;
y = height/2 - 40;

Button crt_btn = new Button("Create Line");
add(crt_btn);
crt_btn.addActionListener(this);
addMouseListener( this );
addMouseMotionListener( this );
}


public void actionPerformed(ActionEvent e)
{

if(e.getActionCommand()== "Create Line")
{
flag=1;
System.out.println("btn clicked");
repaint();
}
}

public void mouseEntered( MouseEvent e ) { }
public void mouseExited( MouseEvent e ) { }
public void mouseClicked( MouseEvent e ){}
public void mousePressed( MouseEvent e ) {
mx = e.getX();
my = e.getY();
if ( mx > x && mx < x+80 && my == y) {
isMouseDragging = true;
}
e.consume();
}
public void mouseReleased( MouseEvent e ) {
isMouseDragging = false;
e.consume();
}
public void mouseMoved( MouseEvent e ) { }
public void mouseDragged( MouseEvent e ) {
if ( isMouseDragging ) {
// get the latest mouse position
int new_mx = e.getX();
int new_my = e.getY();

// displace the box by the distance the mouse moved since the last event
// Note that "x += ...;" is just shorthand for "x = x + ...;"
x += new_mx - mx;
y += new_my - my;

// update our data
mx = new_mx;
my = new_my;

repaint();
e.consume();
}
}

public void paint( Graphics g ) {
g.setColor( Color.blue );
if(flag==1)
{
g.drawLine( x, y, x+80, y );
}
}
public void update(Graphics g ) {

paint(g);
}
}

this is my program .
in this program i can draw line when click the createline button.
wnen i try to move the line so many lines created in th emoving path.
this is
my first problem
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Your applet contains antique event code. Here is a link into the java tutorial where you
can learn how to write modern event handling code for your applet: Lesson: Writing Event Listeners.
1.how to select a particular from morethan one line.
2.how to move line around panel easily

I modified your code to demonstrate one (of many possible) way(s) to do these two things.
For the resizing of lines you will have to decide what kind of resizing behavior you want
and how you want the user to interact with your applet to get the desired behavior.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
if(e.getActionCommand()== "Create Line")

Don't ever compare Strings with "==" - use the "equals" method.
Giri Regu
Greenhorn

Joined: Apr 03, 2006
Posts: 15
hi
thanks craig thanks a lot.
your code is working properly.but i am using jdk1.18 version so the graphics2d and methods in Rectangle class insersectLine() ans setFrameCenter() is not available.
its my mistake to notice about version which i am working. anyway i am trying to convert in lower version . i am unable to understand the usage of rectangle class methods(mentioned above).
if you dont mine please tell me the logic of your program.
sorry for the inconvenence.

thanks and regards
Giridaran.r
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
Oi am unable to understand the usage of rectangle class methods


Well, put a little effort into it. Learning how to read and understand code is an important part of learning to program.

Are you familiar with the Rectangle class? Take a look at the 4 points used to define it - what do those stand for in the code? Why does that area need to be repainted (which is all that happens with the Rectangle)?
 
wood burning stoves
 
subject: How to shrink/grow lines