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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:17:45+00:00 2026-06-10T06:17:45+00:00

I want two different images to appear in two different frames. The problem is

  • 0

I want two different images to appear in two different frames. The problem is that this code doesn’t show this two images (circles) but only the last one. Any help would be appreciate! Thank you.

public class MyCanvas extends JPanel {


private static final long serialVersionUID = 1L;
static int paint=0;

public MyCanvas(){              
}

public void paintComponent(Graphics graphics){  


    System.out.println("mpika!!!"); 
    //  super.paintComponent(graphics);
        if(paint==0){
            graphics.setColor(Color.blue);
            graphics.drawOval(250,250,250,250);                        
        }
        else{       
            graphics.setColor(Color.red);       
            graphics.drawOval(150,150,150,150);                        
        }
}


public static void other(){
    JFrame frame2 = new JFrame();
    MyCanvas canvas2 = new MyCanvas();
    frame2.setSize(700, 700);
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame2.add(canvas2);
    frame2.setVisible(true);
    Graphics graph2 = canvas2.getGraphics();
    canvas2.paintComponent(graph2); 

}
public static void main(String[] args){
    double t;
    JFrame frame = new JFrame();
    MyCanvas canvas = new MyCanvas();
    frame.setSize(700, 700);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(canvas);
    frame.setVisible(true);
    Scanner input = new Scanner(System.in);
    Graphics graph = canvas.getGraphics();
    canvas.paintComponent(graph);   
//      t = input.nextInt();

    paint=1;
    other();

}
}
  • 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-10T06:17:46+00:00Added an answer on June 10, 2026 at 6:17 am

    You never call setVisible on frame2.

    Also as paint is static:

    static int paint = 0;

    You will only ever see one color painted.

    The solution is to make this into a member variable in MyCanvas, something like:

    public void setColorFlag(int color)
    

    or better still pass in the circle color(!).

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

Sidebar

Related Questions

I want to open two different links images in one window on one click.
Having loaded two different images I want to do the following operation and obtain
Okay, I have two different background .jpgs that I want to used as the
I want to display images using different color maps in different figures. Following code
I want to create a combined image with two different images by overlapping. For
I want to compare the pixel of the two different images. I am comparing
I want to support two different appln icon images, One is 57x57 and other
I have to show two different images for the corresponding orientations. I have added
We have two websites which only difference is in the design (different images, styles,
I have an image map with two different area shape attributes. I want to

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.