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 8721997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:54+00:00 2026-06-13T07:18:54+00:00

For my CS11 class, I have to write a small applet that draws a

  • 0

For my CS11 class, I have to write a small applet that draws a horizontal and vertical line on the screen that intersect in the middle of the canvas. One part of the assignment is to be able to move one or both lines when the user clicks on a line and performs a drag. That part is working.

The second part involves handling window resizing. If the window gets resized, the two lines need to be adjusted so they extend from edge to edge of the window.

Our instructions want us to use the Java appletviewer instead of a web browser to launch the program so that the window can be resized while the program is running. We are told to use the following .html file.

ResizableBallController.html

<html>
  <body>
    <applet
      code="ResizableBallController.class"
      archive="objectdraw.jar"
      width="500"
      height="500">
    </applet>
  </body>
</html>

When I run the program and resize the window the canvas area stays fixed at 500×500 pixels, even as I make the window bigger, and the enlarged area is filled with gray. According to my instructor, the canvas should automatically adjust to extend from edge to edge of the newly resized window.

To test the issue, I am overloading the paint method to add a System.out.println message so I can see how often it is being called and it appears the only time the method is invoked is when the program is launched.

I’m wondering if this could have something to do with Awesome Window Manager or perhaps something else. I say this because the instructor said when you resize the window, the canvas should automatically resize as well.

Here is a portion of the code so you can see what I’m doing:

import objectdraw.*;
import java.awt.*;

public class ResizableBallController extends WindowController
{
  // Canvas separators
  private Line xAxis,
               yAxis;

 boolean xAxisGrabbed,
          yAxisGrabbed;

  public void begin()
  {
    int canvasWidth              = canvas.getWidth(),
        canvasHeight             = canvas.getHeight(),
        canvasHorizontalMidPoint = canvasWidth / 2,
        canvasVerticalMidpoint   = canvasHeight / 2;

    xAxis = new Line(0, canvasVerticalMidpoint,
                     canvasWidth, canvasVerticalMidpoint,
                     canvas);

    yAxis = new Line(canvasHorizontalMidPoint, 0,
                     canvasHorizontalMidPoint, canvasHeight,
                     canvas);
  }

  public void onMousePress(Location p)
  {
    xAxisGrabbed = xAxis.contains(p);
    yAxisGrabbed = yAxis.contains(p);
  }

  public void onMouseDrag(Location p)
  {
    if (xAxisGrabbed)
    {
      xAxis.moveTo(0, p.getY());
    }

    if (yAxisGrabbed)
    {
      yAxis.moveTo(p.getX(), 0);
    }
  }

  public void paint(java.awt.Graphics g)
  {
    super.paint(g);
    System.out.println("paint called");
  }
} // End of public class ResizableBallController extends WindowController
  • 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-13T07:18:55+00:00Added an answer on June 13, 2026 at 7:18 am

    Very strange, but the Java JDK seems to have problems with some window managers. A solution was accidentally found. JFrame's position and pack() in Awesome WM

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

Sidebar

Related Questions

I have the following powershell script: # C-Sharp source for taking our screenshot $Source
have everything working fine with mvc.razor generator. Views from my library project show up
I use C# and Entity Framework 4. I'm trying to use a test Class
Why does this code return Specified method is not supported. using System; using System.IO;
I'm trying to use PWM for an LED on an ATmega8, any pin of
I am having trouble with the pro asp.net mvc 3 framework book. On page
Hi I'm trying to run the Racing Game starter kit windows version when the
I'm trying to compile the code ( More iterator fun with the producer/consumer pattern
I want to create a simple C# GUI with a textbox in it for
I've got a bunch of Warnings in a Visual Studio 2005 project, most of

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.