Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:05:48+00:00 2026-06-02T15:05:48+00:00

So I’m just starting with Applets and I am making a house with an

  • 0

So I’m just starting with Applets and I am making a house with an open door and 2 open windows when the applet loads. When you click these windows or door then they will shut. My question though is what do I need to do to re-open these windows doors. I figure I need to set the Boolean variables to False somehow and repaint. Where would I do this. I don’t need you guys to write the code for me, I just want to know what I should do.

Thanks ahead of time,

Rick

   import java.awt.*;
   import java.awt.event.*;
   import java.applet.*;

/**
Rick Armstrong
Chapter 14 - House Applet
*/

   public class HouseApplet extends Applet {    
  boolean leftWin, rightWin, door;

  public void init()      
  {      
     leftWin = false;
     rightWin = false;
     door = false;      

     setBackground(Color.white);       
     addMouseListener(new MyMouseListener());       
  }

  public void paint(Graphics g)
  {
     super.paint(g);

    // Draw the house.
     g.setColor(Color.black);
     g.drawRect(100, 100, 200, 100);

    // Draw the roof
     g.drawLine(80, 100, 320, 100);
     g.drawLine(80, 100, 200, 40);
     g.drawLine(200, 40, 320, 100);

    // Draw the left window open.
     g.fillRect(120, 130, 40, 40);

    // Draw the right window open.
     g.fillRect(240, 130, 40, 40);

    // Draw the door open.
     g.fillRect(180, 130, 40, 70);          

     if (leftWin) {
        // Draw the left window closed.
        g.setColor(Color.white);
        g.fillRect(120, 130, 40, 40);
        g.setColor(Color.black);
        g.drawRect(120, 130, 40, 40);
        g.drawLine(140, 130, 140, 170);
        g.drawLine(120, 150, 160, 150);

     }

     if (rightWin) {
        // Draw the right window closed.
        g.setColor(Color.white);
        g.fillRect(240, 130, 40, 40);
        g.setColor(Color.black);
        g.drawRect(240, 130, 40, 40);
        g.drawLine(260, 130, 260, 170);
        g.drawLine(240, 150, 280, 150);

     }

     if (door) {
        // Draw the door closed.
        g.setColor(Color.white);
        g.fillRect(180, 130, 40, 70);
        g.setColor(Color.black);
        g.drawRect(180, 130, 40, 70);
        g.fillOval(210, 165, 07, 07);

     }    
  }

  private class MyMouseListener implements MouseListener
  {
     public void mousePressed(MouseEvent e)
     {
     }

     public void mouseClicked(MouseEvent e)
     {
        int currentx = e.getX();
        int currenty = e.getY();

        boolean WindowLeft = (currentx >= 120 && currentx < 160 && currenty >= 130 && currenty <= 170);
        if (WindowLeft)
        {
           leftWin = true;
           repaint();               
        }

        boolean WindowRight = (currentx >= 240 && currentx < 280 && currenty >= 130 && currenty <= 170);
        if (WindowRight)
        {
           rightWin = true;
           repaint(); 
        }

        boolean Door = (currentx >= 180 && currentx < 220 && currenty >= 40 && currenty <= 200);
        if (Door)
        {            
           door = true;
           repaint();     
        }  

        else;  
     }

     public void mouseReleased(MouseEvent e)
     {
     }

     public void mouseEntered(MouseEvent e)
     {
     }

     public void mouseExited(MouseEvent e)
     {
     }
  }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:05:48+00:00Added an answer on June 2, 2026 at 3:05 pm

    Maybe I’m misunderstanding the question, but why are you always setting the values to true in the event handler?

    If you want a toggling behavior, you could simply write: value = !value and then repaint.
    Since you initially set your value to false, the next click would set it to true, the next to false, etc. etc.

    For example:

    if (WindowLeft)
            {
               leftWin = !leftWin;
               repaint();               
            }
    

    Note that it is possible for you to cause sort of a “race condition” by clicking faster than the framework has a chance to update the view, but this is usually not a problem for initial problem.

    BTW: In terms of readability, consider naming your variables in a way that conveys their meaning. For example, is the naming door evocative of a boolean? not really. but doorOpen is, and it helps interpret the meaning of the variable and its transitions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.