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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:08:53+00:00 2026-05-23T07:08:53+00:00

I am starting to learn Java a little after long time. And learning Netbeans

  • 0

I am starting to learn Java a little after long time. And learning Netbeans 7.0.

I just want to make sure I am doing this ok.

I basically need to make an applet, but not having it AWT based, but instead Swing based.

So I need to extend JApplet, not Applet. I understand in swing draws on a Jpanel instead of awt canvas (or Panel). And so I read on a web site that one needs to override PaintComponent() instead of overrriding paint() as the case with awt applet?

I need to make a very simple applet, say with one button, when I click on it, I want to draw a graphics, say a line or circle, and have the output go to an area below the button.

This is what I did

  1. File->New Project
  2. Select Java and from Projects, select “Java Application”
  3. make sure to Un-check the “create Main class”, and click Finish
  4. File->New file
  5. Select “Swing GUI Forms” from under the catagories panel
  6. From the “File types”, Select Japplet Form,Next and Finish
  7. From the palette, from Swing Controls, select Button and lay it on the from
  8. Now the tricky part. I need an area to draw on, right? So I from palette, I select, from Swing containers, a “Panel”, and lay it on the form, resize it as needed. Do, now I have this:

enter image description here

Am I on the right track so far? Now I open the source file, and I see the init() method.

Now is where I need little help. Not sure what the code I need to insert to just draw a line to the JPanel I just added. I know I need to insert it here:

enter image description here

I tried the “insert Code” feature, and select override, but do not see PaintComponent()?

I know how to do it in swt applet, just add a paint(Graphics g) method. But when I do this, the graphics do not draw inside the Jpanel area. Basically, how do I tell it to draw something to a specific JPanel area?

If someone just tell me what code I need to insert there to draw a line or any graphics2D object to display on that JPanel I added below the bottom, that will great.

thanks,
–Nasser

EDIT 1:

Just a clarrification: If I add this function to paint on the Jpanel:

public void paint(Graphics g)
{
super.paint(g);
g.drawString(….);
}

Then the output does show ok, but it over the main Japnel. And can hide the button and any other UI components are there.

I need the paint output to go to a specific Jpanel which I added earlier below the button. To this one

private javax.swing.JPanel jPanel1;

So, my question is, how to draw/paint to the above object and not to the main Jpanel?

EDIT 2:

I tried just to change the JPanel background color, and it is not working. Here is the code.
I also tried JpanelForm instead of JApplet Form. Can one use JFrame form to make an applet? Since that requires a main() it does not seem possible.

import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;    
public class NewJApplet extends javax.swing.JApplet
{     
    /** Initializes the applet NewJApplet */
    public void init()
    {                
        jPanel1 = new JPanel();        
        try
        {
            java.awt.EventQueue.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    initComponents();
                }
            });
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }        
    private void initComponents() {...}
    //---------  ADDED THIS
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
    {
        // TODO add your handling code here:        
        Rectangle rect=new Rectangle(4,4);
        jPanel1.setBackground(Color.RED);                     
    }
    //---------------

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
    }
  • 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-23T07:08:53+00:00Added an answer on May 23, 2026 at 7:08 am

    netbeans does not support making JApplets, only applets. Use standard text editor to design the JApplet interface then compile the source code using javac.

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

Sidebar

Related Questions

Im starting to learn RoR and i want to make my personal blog in
i am starting to learn Java using Netbeans 6.8 IDE. i am wondering if
A friend is just starting to learn Java, using IntelliJ. He asks how can
I'm just starting to learn the C programming language. I've written this simple piece
just starting to learn Dojo, and I am having a heck of a time
I am just starting to learn javascript, so I don't have the skills to
im just starting to learn flex and im trying to understand how Flex does
I'm starting to learn ASP.Net MVC (the release candidate), and I'm having a little
I'm starting to learn Excel Programming and have been doing the development in Excel
I am just starting to learn F#. In several F# coding examples I see

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.