Home arrow static arrow Java Programming [Archive] - Java applets
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Java applets
This topic has 1 reply on 1 page.

Posts:7
Registered: 7/18/04
Java applets  
Jul 18, 2004 9:43 PM



 
I want to write an applet to draw two sliders on a rectangle.I shold be able two drag tthe sliders on the rectangle.I have allready written the code to draw the rectangle and one slider works perfectly fine. I want the other slider to also work. Can anybody please help me. The code is as follows which is saved in Events.java:




[java]

import java.awt.;
importjava.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);
}

}

</pre>

The corresponding HTML code is saved in k1.html:

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

Posts:2,909
Registered: 13.8.2003
Re: Java applets  
Jul 18, 2004 10:38 PM (reply 1 of 1)



 
Uh, do you have those
and other html codes inside your Java code? Or are you just trying to use them for formatting....

Anyway, please post your error messages if any and/or a clear description of your problem (i.e. what you're doing and what you're expecting will happen).

If you are trying to mix html markup with Java, please refer to "My First Cup Of Java" tutorial which will show you how to write and compile Java code.
 
This topic has 1 reply on 1 page.