似乎我的输入框似乎出现了两次,即使它们也不应该出现。似乎无法弄清楚为什么。如果有人可以提供帮助会很棒:)
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
我知道这是一个非常基本的程序,但我或多或少只是试图通过盯着基本的东西来学习 java。所以希望如果我能理解如何让一个简单的程序运行起来,我就可以继续前进。