Painting Applet

Reply

Join Date: Sep 2008
Posts: 38
Reputation: cproud21 has a little shameless behaviour in the past 
Solved Threads: 0
cproud21 cproud21 is offline Offline
Light Poster

Painting Applet

 
0
  #1
Nov 24th, 2008
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);
   }
   
   
   
   

   
   }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Painting Applet

 
0
  #2
Nov 24th, 2008
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
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC