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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:00:39+00:00 2026-06-05T09:00:39+00:00

I need help because I am trying to code a game in Java. I

  • 0

I need help because I am trying to code a game in Java.
I was stopped in my tracks when I found out that it would not draw a string to the JFrame.
I have tried several methods of getting around this and done lots of research but found nothing.
This is the code:-
Oregon (Main Class):

package com.lojana.oregon.client;

import java.awt.*;

import javax.swing.*;

import com.lojana.oregon.src.Desktop;
import com.lojana.oregon.src.Keyboard;
import com.lojana.oregon.src.Mouse;
import com.lojana.oregon.src.Paint;

public class Oregon extends JFrame {
    private static final long serialVersionUID = 1L;

    // Currently unused but there will be a use for it in the future
    public Desktop desktop;

    public String TITLE = "Oregon";

    public Oregon() {
        /* Window code */
        setTitle(TITLE);
        setSize(640, 640);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        /* Extra code for Window */
        addKeyListener(new Keyboard());
        addMouseListener(new Mouse());
    }

    public void paint(Graphics g) {
        Paint.paint(g);
    }
}

GuiButton (Painting Class):

package com.lojana.oregon.src;

import java.awt.*;

public class GuiButton {
    public GuiButton(Graphics g, String text, Font font, int coordX, int coordY,
            int textX, int textY, int width, int height) {
        Color border = Color.gray;
        Color fill = Color.white;
        Color textColor = Color.black;

        Stroke borderSize = new BasicStroke(8);

        g.setColor(border);
        ((Graphics2D) g).setStroke(borderSize);
        g.drawRect(coordX, coordY, width, height);
        g.setColor(fill);
        g.fillRect(coordX, coordY, width, height);
        g.setColor(textColor);
        g.setFont(font);
        g.drawString(text, textX, textY);
    }
}

GuiMainMenu (The file that uses the GuiButton file):

package com.lojana.oregon.src;

import java.awt.*;

public class GuiMainMenu {
    public static void paint(Graphics g) {
        new GuiButton(g, "Start Game", new Font("Arial", Font.BOLD, 20), 60, 80, 20, 20, 240, 40);
    }
}

If you know how to fix it, please comment.
Thank you so much 🙂

  • 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-05T09:00:41+00:00Added an answer on June 5, 2026 at 9:00 am

    Swing programs are supposed to override paintComponent(Graphics g) instead of paint(Graphics g) and directly to the JFrame. See this article for details:
    http://java.sun.com/products/jfc/tsc/articles/painting/

    In addition it would be better to override the paintComponent of a JPanel that is added to the (content pane of) JFrame instead of the JFrame itself, because you want to draw into this content pane. See this tutorial for details:
    http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html

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

Sidebar

Related Questions

I need help on regex or preg_match because I am not that experienced yet
Ok well I need some help because I am plain stuck. I am trying
I need some help trying to figure out how to format dates in perl.
I need some help about optimisation. I am trying to improve this open-source game
I'm fairly new to Java, and I need some help figuring out a good
I need a regexp help, because for me it will take a lot of
I need help finishing this statement. It is frustrating that two of the PHP
I need help with trying to bypass/ignor a self signing certificate.. I have looked
I need some help wrapping my head around this. I am trying to develop
Im new at tkinter so im a begginer.. I need help because i was

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.