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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:56:10+00:00 2026-05-17T15:56:10+00:00

Okay, I’m creating a program from a single class, let’s call it John class.

  • 0

Okay, I’m creating a program from a single class, let’s call it “John” class. So instead of starting from scratch, I create the “John” class by copying most code from “Dave” class( this class have similar setup but differ greatly in functionality), and then modify it greatly to suit my need.

The problem is, when I hit the ‘run file’ button, the program behave as if it was “Dave”. it’s ridiculous, I have changed lots of code, there’s no way that “John” can looks like “Dave” now. So this must be netbeans doing. How to fix it?

edit:

so here’s John:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

/**
 *
 * @author PCKhoi
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

public class ImageBlink {
    static DrawingCanvas canvas;
    private BufferedImage bi;
    private int w,h;
    public ImageBlink() {
        Frame f = new Frame("Click!");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        URL imageSrc = null;
        try {
            imageSrc = new URL("what_I_think.jpg");
        } catch (MalformedURLException ex) {
            Logger.getLogger(ImageDemo.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            bi = ImageIO.read(imageSrc);
            w = bi.getWidth(null);
            h = bi.getHeight(null);
        } catch (IOException e) {
            System.out.println("Image could not be read");
            System.exit(1);
        }
        canvas = new DrawingCanvas();
        f.add(canvas, BorderLayout.CENTER);
        f.pack();
        f.setVisible(true);
    }
    public static void main(String[] args) {
        new PaintDemo();
    }
    class DrawingCanvas extends Canvas implements MouseListener, MouseMotionListener {
        private int x1=0,y1=0,x2=0,y2=0;
        public Dimension getPreferredSize() {
            return new Dimension(600,600);
        }
        public DrawingCanvas() {
            super();
            addMouseListener(this);
            addMouseMotionListener(this);
            setBackground(Color.white);
        }
        public void paint(Graphics g) {
            Graphics2D g2D = (Graphics2D) g;
            g2D.drawImage(bi,x2,y2,x2+w,y2+h,x1,y1,x1+w,y1+h,null);
        }
        public void mousePressed(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        public void mouseReleased(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        public void mouseClicked(MouseEvent e) {
            x1 = x2;
            y1 = y2;
            x2 = (int)Math.random()*400;
            y2 = (int)Math.random()*449;
            canvas.repaint();
        }
        public void mouseDragged(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseEntered(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseExited(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseMoved(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}

and here’s Dave:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

/**
 *
 * @author PCKhoi
 */
import java.awt.*;
import java.awt.event.*;

public class PaintDemo {
    static DrawingCanvas canvas;
    private Stroke lineStroke;
    public PaintDemo() {
        Frame f = new Frame("Stroke a line!");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        canvas = new DrawingCanvas();
        lineStroke = new BasicStroke(2.f);
        f.add(canvas, BorderLayout.CENTER);
        f.pack();
        f.setVisible(true);
    }
    public static void main(String[] args) {
        PaintDemo pd = new PaintDemo();
    }
    class DrawingCanvas extends Canvas implements MouseListener, MouseMotionListener {
        private int x1=0,y1=0,x2=200,y2=200;
        public Dimension getPreferredSize() {
            return new Dimension(300,300);
        }
        public DrawingCanvas() {
            super();
            addMouseListener(this);
            addMouseMotionListener(this);
            setBackground(Color.white);
        }
        public void paint(Graphics g) {
            Graphics2D g2D = (Graphics2D) g;
            g2D.setStroke(lineStroke);
            g2D.drawLine(x1, y1, x2, y2);
        }
        public void mousePressed(MouseEvent e) {
            x1 = e.getX();
            y1 = e.getY();
            x2 = x1;
            y2 = y1;
            System.out.println("x1: "+x1+"y1: "+y1);
            canvas.repaint();
        }
        public void mouseReleased(MouseEvent e) {
            x2 = e.getX();
            y2 = e.getY();
            System.out.println("x2: "+x2+"y2: "+y2);
            canvas.repaint();
        }
        public void mouseClicked(MouseEvent e) {
            canvas.repaint();
        }
        public void mouseDragged(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseEntered(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseExited(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void mouseMoved(MouseEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
}
  • 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-17T15:56:10+00:00Added an answer on May 17, 2026 at 3:56 pm

    in John’s main method you have

    new PaintDemo(); // i.e. John's and Dave's main method initiate the same code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,
Okay, so I have a snippet of code from a website containing a button:
Okay, so I'm trying to create a list of he folders, and sub-folders and
Okay, I'm trying to make a quick little class to work as a sort
Okay, I've looked all over the internet for a good solution to get PHP
Okay, so I'm running a small test webserver on my private network. I've got
Okay so im working on this php image upload system but for some reason
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

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.