The Artima Developer Community
Sponsored Link

Java Answers Forum
Java applets

2 replies on 1 page. Most recent reply: Aug 24, 2004 4:55 AM by kavitha

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
kavitha

Posts: 2
Nickname: kavi
Registered: Jul, 2004

Java applets Posted: Jul 16, 2004 9:32 PM
Reply to this message Reply
Advertisement
I want to write an applet that will draw a wide rectangle on which two small rectagles which act as sliders will slide on the wider rectangle as i drag the mouse. I have written the applet for one slider to work perfectly alright i want the other rectangle also to work so can anybody help me please. The code is as follows which is saved in Events1.java.




importjava.awt.*;java.awt.event.*;
import java.applet.*;
public class Events1 extends
Applet implements MouseMotionListener {

int mouseX =100,mouseY=100,mouseX2=496,mouseY2=100;
public void init() {

addMouseMotionListener(this);<br>
}

public void mouseDragged(MouseEvent me) {

if((me.getX() >= 100) && (me.getX() <= 500)) {

if(me.getY() == 100) {
mouseX = me.getX();
mouseY = me.getY();

repaint();
}
}

}
public void mouseMoved(MouseEvent me) {
showStatus("Moving mouse at " + me.getX() + "," + me.getY());
}
public void paint(Graphics g) {
g.drawRect(100,99,401,16);
g.setColor(Color.red);
g.fillRect(100,100,400,15);
g.setColor(Color.green);
g.fillRect(100,100,mouseX-100,15);
g.setColor(Color.yellow);
g.fillRect(mouseX2,mouseY,5,15);
g.setColor(Color.blue);
g.fillRect(mouseX,mouseY,5,15);
}

}



The corresponding HTML code is saved in k1.html:



<html><br>&lt;applet code=Events1.class width=400 height=300&gt;<br>&lt;/applet&gt;<br>


QiSoftware

Posts: 3
Nickname: qisoftware
Registered: Jul, 2004

Re: Java applets Posted: Aug 1, 2004 10:03 AM
Reply to this message Reply
You have specified only one rectangle....

www.qisoftware.com

kavitha

Posts: 1
Nickname: kavina
Registered: Aug, 2004

Re: Java applets Posted: Aug 24, 2004 4:55 AM
Reply to this message Reply
thank you kavi for ur valubale post
all the best

Flat View: This topic has 2 replies on 1 page
Topic: Java Files Previous Topic   Next Topic Topic: JVM INSTR monitorenter;?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use