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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:32:54+00:00 2026-06-04T22:32:54+00:00

It seems that my input boxes seem to come up twice, even though their

  • 0

It seems that my input boxes seem to come up twice, even though their not supposed too. Can’t seem to figure out why. Would be great if anyone could help 🙂

int x; //temperature input
int y; //temperature type
int z; //temperature convert
int c; //temperature celsius 
int f; //temperature fahrenheit 

public void init() 

{
    setSize(500, 500);
    Container c = getContentPane();
    c.setBackground(Color.BLUE);


}

public void paint (Graphics g)

{
    super.paint(g); 

    g.setFont(new Font("Veranda", Font.PLAIN, 20));
    g.setColor(Color.BLACK);

    String number = JOptionPane.showInputDialog("What temperature would you like to convert? (input # of degrees)");
    x = Integer.parseInt(number);   

    String number2 = JOptionPane.showInputDialog("What temperature type are you inputting? 1. Fahrenheit 2. Celsius");
    y = Integer.parseInt(number2);

    if (y==1)
    {
        c=(5/9)*(f-32);

        g.drawString("Your temperature of" + x + "is" + y + "Celsius", 250, 100); 
    }//end if   

    if (y==2)
    { 
        f=(9/5)*c+32;

        g.drawString("Your temperature of" + x + "is" +y + "Fahrenheit", 250, 100);
    }//end if


}//end paint

I understand this is an extremely basic program, but I’m more or less just trying to learn java by staring on basic stuff. So hopefully if I can understand how to get a simple program functioning, I can move on.

  • 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-04T22:32:56+00:00Added an answer on June 4, 2026 at 10:32 pm

    Don’t put in JOptionPane methods in a paint method unless you want to freeze your program to a crawl. The paint(...) method should be for painting only. The paint method is responsible for drawing everything that the component holds, and if you break up its flow unnecessarily, your gui won’t render in a timely way, or may not render at all.

    You also don’t have control over when paint is called or even if it will be called. As you can see, it is not directly called by you (nor should it be), but rather is called by the JVM either in response to a suggestion in the code (by calling repaint()) or due to request by the operating system, for instance if the OS finds a section of a window is “dirty”, it will do this. In fact you’re finding that it’s often called twice initially for these reasons. Put that code somewhere else, perhaps the in the init method.

    Also, this appears to possibly be a Swing application, not an AWT application, since you call getContentPane() in your init method. If so, don’t draw directly in the paint(...) method of a JApplet, but instead in the paintComponent(...) method of a JPanel or other JComponent derivative that the JApplet holds. There are several reasons for this, but the main one is that the applet’s paint(…) method is responsible for many things that you don’t want to take the chance on messing with, including the painting of borders and child windows, and instead you should override a method that is responsible for painting a component only.

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

Sidebar

Related Questions

It seems that flex doesn't support UTF-8 input. Whenever the scanner encounter a non-ASCII
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
Ok so i have a form that has three input boxes, at the moment
I am creating input text boxes that will set its title attribute as its
Consider that I have 10 input boxes, (using datepicker plugin Fyi) I have a
I seem to have a bit of a problem here that I can't quite
It seems that when a WPF application starts, nothing has focus. This is really
It seems that in a standard Xcode project, the default target automatically updates the
It seems that using Critical Sections quite a bit in Vista/Windows Server 2008 leads
It seems that MSMQ doesn't use any Database management system to manage messages. How

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.