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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:41:03+00:00 2026-06-08T09:41:03+00:00

I am creating an object of another class from my main class using the

  • 0

I am creating an object of another class from my main class using the following call:

JSplash splash = new JSplash();

However, when I create this object it performs the constructor of the JSplash class and gives my window and my button. But it does not paint on the frame. Can you please assist me with this?

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 *
 * @author Curtis
 */
public class JSplash extends DFrame implements ActionListener {
//declaration of variable objects
    Font myFont = new Font("Arial", Font.BOLD, 20);
    JButton myButton = new JButton("Click Me!");
    Color bgColor = new Color(0, 0, 255);
    Color firstColor = new Color(255, 255, 255);
    String first = "Welcome to DaemoDynamics!";
    String last = "Click the Button";
    String middle = "";
    String middle2 = "";
    private static int count = 1;
    DFrame splash = new DFrame();
//Constructor
    public JSplash() {
        setDefaultLookAndFeelDecorated(true);
        System.out.println("Hello");
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        splash.add(myButton);
        getContentPane().setBackground(bgColor);
        //adds action listener
        myButton.addActionListener(this);
        splash.setVisible(true);
    }
//Paint method
    @Override
    public void paint(Graphics e) {
        System.out.println("paint is being reached");
        super.paint(e);
        e.setFont(myFont);
        e.setColor(firstColor);
        e.drawString(first, 14, 80);
        e.drawString(last, 70, 240);
        e.drawString(middle, 75, 150);
        e.drawString(middle2, 60, 175);
    }

//Listener Method
    @Override
    public void actionPerformed(ActionEvent e) {
        //First Time button hit
        if (count == 1) {
            middle = "Brighter Business";
            middle2 = "for A Brighter Future";
            last = "Click Again to Begin";
            repaint();
            //increases button count
            count++;
        } else//if button count is not 1
        {
            splash.setVisible(false);
            FinalProject app = new FinalProject();
        }
    }
}
  • 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-08T09:41:07+00:00Added an answer on June 8, 2026 at 9:41 am

    You’ve create a NEW DFrame inside you JSplash constructor and then ADDED your components to IT. This is simply not required. Remove the reference’s to splash and simply use the DFrame you’ve extended. And while i’m looking at, splash has no layout manager, which isn’t going to help. The paint method is never going to be called, because the window that’s displayed on the screen is never the JSplash, but the DFrame you created (called splash)

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

Sidebar

Related Questions

I am creating a model object like this: $object1 = new Object1(); There is
I am calling a class's member function from another class. So,I am creating an
I'm creating a base class Node that essentially wraps instances of another class from
I'm trying to change an Object's properties from another class, like so. abilities.cs (class)
Hi I am creating a List View in another List View using this code
I am creating an object like this: markers[name] = {}; markers[name].id = id; markers[name].lat
I am creating an object in python. I have a numpy array from an
Firefox 3.5 does not allow creating java OBJECT tag with Javascript (document.write)? this technique
I've a tableviewController in a class which I need to present modally from another
I have a factory that is supposed to create objects that inherit from class

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.