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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:35+00:00 2026-05-28T00:26:35+00:00

I wanted to change the displayed string from start to keyup or keydown but

  • 0

I wanted to change the displayed string from “start” to “keyup” or “keydown” but the string doesnt seem to change..

import java.awt.Event;
import java.awt.Graphics;
import javax.swing.JApplet;

public class Applet extends JApplet {
    String str = "start..";
    public void init() {
    }
    public void paint(Graphics g) {
        g.drawString(str, 200, 200);
    }
    public boolean keyDown(Event evt , int key) {
        str = "keyDown";
        repaint();

        return true;
    }
    public boolean keyUp(Event evt , int key) {
        str = "keyUp";

        return true;
    }
}
  • 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-28T00:26:36+00:00Added an answer on May 28, 2026 at 12:26 am
    1. Don’t use methods that were deprecated in Java 1.1. Instead implement a KeyListener or use key bindings.
    2. Ensure the applet is focusable & has the input focus.

    E.G. using KeyListener

    KeyApplet

    // <applet code='KeyApplet' width=200 height=40></applet>
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.JApplet;
    
    public class KeyApplet extends JApplet implements KeyListener {
    
        String str = "start..";
    
        public void init() {
            setFocusable(true);
            requestFocusInWindow();
            addKeyListener(this);
            setBackground(Color.yellow);
        }
    
        public void paint(Graphics g) {
            super.paint(g);
            g.setColor(getBackground());
            g.fillRect(0,0,getWidth(),getHeight());
            g.setColor(Color.black);
            g.drawString(str, 20, 20);
        }
    
        public void keyTyped(KeyEvent evt) {}
    
        public void keyPressed(KeyEvent evt) {
            str = "keyDown";
            repaint();
        }
    
        public void keyReleased(KeyEvent evt) {
            str = "keyUp";
            repaint();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to change the resolution of a image,this image I am getting from
i 'm trying the hibernate tutorials from their main site and wanted to change
I have a ListView inside of an Update Panel and wanted to change the
I have a JSP which has jQuery and wanted to change the action message
I'm working on a quick setup program in Visual Studio and wanted to change
I wanted to see what happened if you change the reference of an object
i was trying to use a MKMapView, and i wanted to show/change the kind
I wanted to scroll the background image that is displayed on the panel. I
Just wanted to know if there is a big chance to inject SQL While
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>

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.