入力ボックスが 2 回表示されるようです。理由がわからないようです。誰かが助けることができれば素晴らしいだろう:)
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 を学ぼうとしているだけです。簡単なプログラムを機能させる方法を理解できれば、次に進むことができます。