| | |
Painting Applet
![]() |
•
•
Join Date: Sep 2008
Posts: 38
Reputation:
Solved Threads: 0
The following applet that I have displays a house with two windows and a door that are colored in black. I want to display these items with window panes in them to show that they are open when the user clicks on them. I know that I need to use a MouseListener that repaints to do so, but do not understand how to set the right coordinates to make that possible...
package hw13;
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
/**
* This class is an applet that demonstrates how
* rectangles can be drawn.
*/
public class Main extends JApplet
{
public void init()
{
// Set the background color to white.
getContentPane().setBackground(Color.WHITE);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.BLUE);
g.fillRect(5, 5 , 200, 150);
g.setColor(Color.BLACK);
g.fillRect(20,40,35,35);
g.setColor(Color.BLACK);
g.fillRect(140,40,35,35);
g.setColor(Color.BLACK);
g.fillRect(75,75,50,80);
}
} Here some links, that can solve your problem:
http://www.hostitwise.com/java/japplet.html
http://www.roseindia.net/java/example/java/applet/
and here is alternative decision (if you interested):
http://www.jython.org/applets/coordinates.html
http://www.hostitwise.com/java/japplet.html
http://www.roseindia.net/java/example/java/applet/
and here is alternative decision (if you interested):
http://www.jython.org/applets/coordinates.html
Last edited by Antenka; Nov 24th, 2008 at 3:11 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
![]() |
Similar Threads
- HTML file can't find my applet!!! (Java)
- Questions about Applet and JFrame (Java)
- moving objects at the same time? (Java)
- drawStripes (Java)
- Applet Help (Java)
Other Threads in the Java Forum
- Previous Thread: Java Quiz Help plzz
- Next Thread: Color Chooser
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php problem program programming project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows





