943,666 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1586
  • Java RSS
Nov 24th, 2008
0

Painting Applet

Expand Post »
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);
   }
   
   
   
   

   
   }
Similar Threads
Reputation Points: 4
Solved Threads: 0
Light Poster
cproud21 is offline Offline
42 posts
since Sep 2008
Nov 24th, 2008
0

Re: Painting Applet

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.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java Quiz Help plzz
Next Thread in Java Forum Timeline: Color Chooser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC