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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:49:06+00:00 2026-06-01T06:49:06+00:00

I have a small template that ive built for the purpose of implementing an

  • 0

I have a small template that ive built for the purpose of implementing an applet through a simple java application via netbeans 7.1 (as in not using Javacard, Netbeans Platform etc ..just a simple java application with applet initialized when application runs)

I have managed to make it invoke the applet when i press the run button in netbeans and i ahve functionality inside the applet but, i cant seem to get it to close and i have a horrible feeling people are gonna tell me to have used jFrame and implement the EXIT_ON_CLOSE method.

This is NOT something I would like to know how to do , my mission is to implement it using Frames != jFrames.
I hope someone can help as its bugged me for a bit now and i have to get on with Java assignment that involves its use.

Enclosed is the code/classes for A: the appletframe and B:the applet

    * 1.4   Write an applet to display a line of text. 
    * The text should then change its font size and style (bold, italic, underline) 
    * depending on where the mouse is clicked on the screen.
    */
   package appletframe;
   import java.awt.Graphics;
  import java.awt.Frame;
 import java.applet.Applet;

  /**
  * @author MuthaLoad aka Gruffy2012
  */

  import java.awt.*;

  public class AppletFrame extends Applet{

 public static void main(String[] args) {

/*construct needs object instances*/
MrApplet mrApplet = new MrApplet(); // create instance/obj of MrApplet 
Frame myFrame = new Frame("Applet"); // create frame "title optional"
//setDefaultCloseOperation(myFrame.EXIT_ON_CLOSE);(jFrame- not wanted)

/* add applet to the frame*/
//myFrame.addWindowListener();
myFrame.add(mrApplet, BorderLayout.CENTER);
myFrame.setBounds(10,10,500,500);
myFrame.setVisible(true); // step to make frame visible

/*initialize instance of mrApplet*/
mrApplet.init();
} // end main
} // end class

B: applet

   package appletframe;

import java.awt.*; //for buttons
import java.awt.event.*; //for events
import java.applet.*; //main applet api`s
import java.awt.Graphics; //graphics

public class MrApplet extends Applet implements ActionListener
{

private static final long serialVersionUID = 1L;
Button btnClick;
String msg = "";

public void init() 
{
    // TODO start asynchronous download of heavy resources
    setSize(500, 500);
    Button btnClick = new Button("Press Me ");
    btnClick.addActionListener(this);
    add(btnClick);
}
public void actionPerformed(ActionEvent e) 
{
    //throw new UnsupportedOperationException("Not supported yet.");
    msg = "Yay, the button works";
            repaint();
}     
public void paint (Graphics g)
{
    g.setFont(new Font("Serif", Font.ITALIC, 30)); //new font obj, font , font style, font size
    g.setColor(new Color(0,255,0)); //new color obj, r,g,b
    g.drawString(msg, 40, 80); 

}  
// TODO overwrite start(), stop() and destroy() methods
}

Once again thanks for reading, and to clarify any confusions..
I am looking for a pointer as to the solution of closing my applet and frame window upon exit , without reimplementing it all using jFrame, though i know this would be easier in the first instance.
Thankyou and as always, indebted to all your advice.
gruffy321

  • 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-01T06:49:07+00:00Added an answer on June 1, 2026 at 6:49 am

    add this line at the end of ApplicationFrame class.

    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    

    You want to do it with Frame not with JFrame, then you have to add the WindowListener event to the frame and have to override windowClosing() method.

    myFrame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we){
       System.exit(0);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
I have created a small SIFT application that grabs the keypoints and saves it
I have an XSL template that is a small section of an HTML email.
I have a small problem with Smarty... I have two different template files in
I have small web app that generate PDF files as a report. I'm trying
i have small function that running on condintion, if text box value is not
I have several small classes that are all peers of each other declared and
I wrote a small PHP application that I'd like to distribute. I'm looking for
I've created a small utility function for string conversion so that I don't have
have small problem, and would very much appreciate help :) I should convert byte

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.