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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:15:46+00:00 2026-05-26T23:15:46+00:00

I’m working on a game and for the menus I’m using Canvas es to

  • 0

I’m working on a game and for the menus I’m using Canvases to draw the stuff for that menu.

For options and buttons I’m using Graphics on the canvas to draw a string. How to detect the mouse clicking the string?

options canvas:

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class OptionsScreen extends Canvas{

private static final long serialVersionUID = 1L;
private Mouse ms = new Mouse();
private int optionPos = 275;
private int volLev = 100;
private int screenX = 800;
private int screenY = 600;
private JFrame mainWindow;

public OptionsScreen(JFrame f)
{
    mainWindow = f;
}

public void paint(Graphics g) {
    g.setFont(new Font("JI-Pelter", Font.PLAIN, 24));
    g.setColor(Color.lightGray);

    //Draw strings
    //Music and Sound
    g.drawString("Music:", optionPos, 150); g.setColor(Color.yellow); g.drawString("On", optionPos + 100, 150); g.setColor(Color.white); g.drawString("Off", optionPos + 175, 150); g.setColor(Color.lightGray);
    g.drawString("Sound:", optionPos, 200); g.setColor(Color.yellow); g.drawString("On", optionPos + 100, 200); g.setColor(Color.white); g.drawString("Off", optionPos + 175, 200); g.setColor(Color.lightGray);
    g.drawString("Volume Level:", optionPos, 250); g.setColor(Color.white); g.drawString(volLev + "%", optionPos + 175, 250); g.setColor(Color.lightGray);
    //OpenGL Settings
    g.drawString("Advanced OpenGL:", optionPos, 300); g.setColor(Color.white); g.drawString("On", optionPos + 225, 300); g.setColor(Color.yellow); g.drawString("Off", optionPos + 300, 300); g.setColor(Color.lightGray);
    //Screen Settings
    g.drawString("Game Resolution:", optionPos, 350); g.setColor(Color.white); g.drawString(screenX + "x" + screenY, optionPos + 200, 350); g.setColor(Color.lightGray);
    this.addMouseListener(ms);
}
}

class Mouse implements MouseListener
{
@Override
public void mouseClicked(MouseEvent arg0) {
}

@Override
public void mouseEntered(MouseEvent arg0) {
    // TODO Auto-generated method stub
}

@Override
public void mouseExited(MouseEvent arg0) {
    // TODO Auto-generated method stub
}

@Override
public void mousePressed(MouseEvent arg0) {
    // TODO Auto-generated method stub
}

@Override
public void mouseReleased(MouseEvent arg0) {
    // TODO Auto-generated method stub
}
}
  • 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-26T23:15:46+00:00Added an answer on May 26, 2026 at 11:15 pm

    Just use a JLabel for the strings. Then you can add a MouseListener to the label.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And

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.