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

  • Home
  • SEARCH
  • 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 6824301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:53:07+00:00 2026-05-26T21:53:07+00:00

the program suppose to invoke the following URL http://www.google.com When exit is selected, all

  • 0

the program suppose to invoke the following URL http://www.google.com When exit is selected,
all the other buttons are working fine but when I click on “exit” nothing happens.
I also get:

warning: unreachable catch clause
    catch( IOException iox ) {
    ^
thrown type MalformedURLException has already been caught

Please help

import java.awt.*;
import java.lang.*;
import java.applet.*;
import java.util.Vector;
import java.io.IOException;
import java.net.*;
import java.net.MalformedURLException;
import java.applet.Applet.*;

public class Stage extends Canvas implements Runnable
{
public class Stage2 extends Applet
{

        public Stage2() {};


    }
Stage2 stage2= new Stage2();


Graphics offGraphics = null;
Image    offImage;



Thread   conductor;

Ball     balls[];
int      numBalls;
int      numBallsAllocated;

int      width;
int      height;

int      sleepy = 5;


// ----- constructor
public Stage( int width,int height )  {
this.width  = width;
this.height = height;
    setBackground( Color.black );
    numBalls = 0;
    numBallsAllocated = 10;
    balls = new Ball[numBallsAllocated];
    conductor = null;
} // end of Stage constructor



//----- methods for setting and maintaining the size of the canvas

public Dimension preferredSize() {
return( new Dimension( width,height ));
} // end of preferredSize()

public Dimension minimumSize() {
return( new Dimension( width,height ));
} // end of minimumSize()



//----- methods for the Bounce applet object to call

public void start() {
    if ( conductor == null ) {
        conductor = new Thread(this, "Stage");
        conductor.start();
    }
else {
        for ( int i = 0; i < numBalls; i++ ) {
            balls[i].start();
        }
        conductor.resume();
    }
} // end of start()

public void stop() {
    for( int i = 0; i < numBalls; i++ ) {
        balls[i].stop();
    }
    conductor.suspend();
} // end of stop()

public void addBall() {
Color color = chooseColor( numBalls );
Ball ball = new Ball( "Ball "+(numBalls+1),color,this,sleepy );
System.out.println( "here "+ball.toString() );
// enlarge ball array if necessary.
if ( numBalls == numBallsAllocated ) {
    Ball newBalls[];
    numBallsAllocated *= 2;
    newBalls = new Ball[numBallsAllocated];
    System.arraycopy( balls,0,newBalls,0,numBalls );
    balls = newBalls;

}
balls[numBalls] = ball;
numBalls++;
ball.start();

} // end of addBall()



//----- methods for conductor thread to run

public void run() {
    while ( true ) {
        repaint();
        try {
            Thread.sleep( sleepy );
        }
    catch ( InterruptedException ix ) {
            break;
        }
    }
} // end of run()

public void faster() {
if ( sleepy > 0 ) {
    sleepy--;
}
for ( int i=0; i<numBalls; i++ ) {
    balls[i].setSleepy( sleepy );
}
System.out.println( "faster... " + sleepy );
} // end of faster()

public void slower() {
sleepy++;
for ( int i=0; i<numBalls; i++ ) {
    balls[i].setSleepy( sleepy );
}
System.out.println( "slower... " + sleepy );
} // end of slower()

public void exit()
{
    try {
      URL url = new URL( "http://www.google.com" );
      stage2.getAppletContext().showDocument( url );
    }
    catch( MalformedURLException murlx ) {
    }
    catch( IOException iox ) {
    }
} // end of exit()

// we have overridden update() instead of paint() since the
// background does not need to be cleared when doing double
// buffering.
public synchronized void update( Graphics g ) {
if ( offGraphics == null ) {
    offImage = createImage( width,height );
    offGraphics = offImage.getGraphics();
}
offGraphics.setColor( getBackground() );
offGraphics.fillRect( 0,0,width,height );
for (int i = 0; i < numBalls; i++) {
    balls[i].paint( offGraphics );
}
g.drawImage( offImage, 0, 0, this );
} // end of update()



//----- private methods.

private Color chooseColor( int i ) {
    switch (i % 5) {
        case 0: return Color.white;
        case 1: return Color.red;
        case 2: return Color.blue;
        case 3: return Color.green;
        case 4: return Color.yellow;
    }
    // Not reached
    return Color.white;
} // end of chooseColor()



 } // end of Stage class
  • 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-05-26T21:53:08+00:00Added an answer on May 26, 2026 at 9:53 pm

    Others have adequately explained the cause of the compilation error.


    I’ve some comments to make first, then some suggestions on how to diagnose the remaining problem:

    1) It seems that you were running an application that had compilation errors. Some IDE’s will let you do this, but it is a somewhat dangerous thing to do. It is much safer to turn off this option and only run code that compiles.

    IDE’s (specifically Eclipse) deals with methods that don’t compile by generating method code that throws an unchecked exception saying there was a compilation error. If you call such a method from the main thread, you’ll get a stack trace. If you call it from a child thread, you may not see a stack trace … depending on whether the thread has an “uncaught exception handler”. I suspect that that was happening here!

    Morals:

    • Fix your compilation errors before you run your code.
    • Install a default uncaught exception handler so that you get a stacktrace for any Thread that dies due to an unchecked exception. (This is a bit advanced for where you are currently at, but try and remember it for later on.)

    2) Your catch block for MalformedURLException is squashing exceptions. That is, it is catching that exception, saying nothing about it, and then proceeding as if nothing bad had happened. In this case, you need to know if that exception was throw because it means that you’ve got a bug in your program; i.e. the hard-wired URL is incorrect.

    Morals:

    • Don’t squash unexpected exceptions. Any unexpected exception should at least be logged. (An unchecked exception can also be allowed to propagate. If you have a checked exception that you don’t want to handle at that point, you can either declare it in method signature, or wrap it in an unchecked exception, though the former approach is usually better.)
    • If you decide that an exception is expected and doesn’t need to be reported, put a comment in the catch block to explain what is going on.

    Here’s what I think you should do to move forward:

    1) Fix the compilation errors. (You’ve done this I gather)

    2) Add some code to the catch clause to (at a minimum) send a stacktrace to the console.

    If that doesn’t work then:

    3a) Run the code in a debugger

    or

    3b) Add some traceprints, and temporarily add catch (Throwable ex) {ex.printStackTrace();} to see if there is some other unchecked exception being thrown.

    There are a number of possible causes of your observed “nothing happens”, and you need to figure out which of the possible causes is the actual cause.

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

Sidebar

Related Questions

Suppose I've got the following program: namespace ReflectionTest { public class Example { private
I wrote the following program that is suppose to start up, show the form
Suppose I have the following situation: 9 class Program 10 { 11 public static
My program is suppose to count the occurrence of each character in a file
Suppose I write a program using immutable data structures in Java. Even though it
Say suppose I am running a java program through command line. And this program
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose you need to run a program on the world’s fastest supercomputer which will
So suppose I'm developing a chess-like program using Java's Swing. I added a MouseListener
Suppose I have a big program that consists of hundreds of methods in it.

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.