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

The Archive Base Latest Questions

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

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class twobuttons { int x=70; int y=70;

  • 0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class twobuttons
{
    int x=70;
    int y=70;

    public static void main(String args[])
    {
        twobuttons gui =new twobuttons();
        gui.go();
    }

    public void go()
    {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        mydraw drawpanel = new mydraw();

        frame.getContentPane().add(drawpanel);
        frame.setSize(300,300);
        frame.setVisible(true);

        for(int i=0;i<130;i++)
        {
            x++;
            y++;

            drawpanel.repaint();
            try
            {
                Thread.sleep(50);
            }
            catch(Exception ex)
            {

            }
        }

    }
    class mydraw extends JPanel
    {

        public void paintconponent(Graphics g)
        {
            g.setColor(Color.green);
            g.fillOval(x, y, 40, 40);
        }
    }
}

this is a code from the Head First Java,chapter 12,p384(I am reading the Chinese edition ,maybe it’s not in the same page in the English edition.)If successful,there should be a dot running from the left corner to the right corner,however,I can’t see anything in the window.

  • 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-31T07:26:48+00:00Added an answer on May 31, 2026 at 7:26 am

    You have a typo in the painting class (paintconponent => paintComponent). So you were not overriding the behavior of the JComponent super class. Try this:

    class mydraw extends JPanel
    {
    
        @Override
        public void paintComponent(Graphics g)
        {
            g.setColor(Color.green);
            g.fillOval(x, y, 40, 40);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestSwingListeners1 { private static int cnt1;
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
import java.awt.*; import java.awt.image.ImageObserver; import javax.swing.*; public class CharacterMove { CharacterCollision CharacterCollision; public static
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class Sheet extends JFrame{ private String[] line
import java.awt.event.*; import java.io.File; import javax.swing.*; public class Launch extends JFrame implements ActionListener {
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Stuff extends Applet implements
import java.awt.*; import javax.swing.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.border.*; public class ChangeButtonShape {

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.