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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:14:14+00:00 2026-05-27T21:14:14+00:00

I have 2 class files called PaintMe.java and Starter.java. PaintMe.java contains: import java.applet.Applet; import

  • 0

I have 2 class files called PaintMe.java and Starter.java.
PaintMe.java contains:

import java.applet.Applet;
import java.awt.*;

public class PaintMe extends Applet {
    public void paint(Graphics g) {
        g.setColor(Color.red);
        g.drawString("HELLOOO", 15, 25);
    }
}

Starter.java contains:

import java.applet.Applet;
import java.awt.Graphics;


public class Starter {
    public static void main(String[] args) {
        PaintMe ring = new PaintMe();
        ring.paint();
    }
}

So question is, how can I paint my string with calling a paint method from Starter.java?

  • 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-27T21:14:14+00:00Added an answer on May 27, 2026 at 9:14 pm

    To get it to compile, change

    ring.paint();
    

    ..to..

    ring.repaint();
    

    Notes

    1. Don’t code using AWT in this millennium. Use Swing (which offers a JApplet).
    2. Don’t start an applet from the main(String[]). An applet is started by the JRE when it is embedded in a web page (or launched using JWS). A GUI can be designed in a panel, that is then put in a free-floating application or applet. That is known as a hybrid. But both frame and applet separately add the GUI, which is (most often) a different class to either.
    3. The main as it exists is useless. Unless the applet is added to a container and made visible, the code will run successfully but end in a few moments without displaying anything.

    Update 1

    ..tried that, but it still doesn’t draw my string in the applet window.

    Try this.

    Source

    // <applet code='PaintMe' width=300 height=50></applet>
    import java.applet.Applet;
    import java.awt.*;
    
    public class PaintMe extends Applet {
        public void paint(Graphics g) {
            g.setColor(Color.red);
            g.drawString("HELLOOO", 15, 25);
        }
    }
    

    Prompt

    > javac PaintMe.java
    > appletviewer PaintMe.java
    

    Screenshot

    PaintMe


    Update 2

    ..I need to have it started from Starter.java class.

    I think that is a silly requirement, and it seems like JWS (as mentioned & linked in comments) launching a JFrame is the best way to view this GUI. OTOH, here is a (very) naive implementation of the Starter class that will show that applet on-screen.

    It mixes AWT and Swing (bad), it does not attempt to implement any sort of applet context, and does not call the applet init/start/stop/destroy methods, but is enough to get the applet on-screen from another class.

    Starter

    import java.awt.Dimension;
    import javax.swing.JOptionPane;
    
    public class Starter {
        public static void main(String[] args) {
            PaintMe ring = new PaintMe();
            ring.setPreferredSize(new Dimension(250,30));
            JOptionPane.showMessageDialog(null, ring);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have three files: one called sql.php witch has a class db that I
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have a Java program that loads thirdparty class files (classes I did not
Have there been incompatibilities between Java releases where Java source code/Java class files targeting
I have a class called MODEL in which public static int theMaxFrames resides. The
Suppose I have a class called Poem. class Poem{ virtual void recite() = 0;
I have class name called Address in two namespaces. Its been two EDMX files,
I have a function in a class file called auth_user and its in App_code
i have a module (a single .py file, actually), with a class called HashedDir.

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.