こんにちはGuys月の名前を月の数字に変換したいのですが、コードフォームを使用していますが、子供のようです。JComboboxを使って月の名前を月の数字に変換する方法
私は月に
例を選択したときに、私は数に月に変換するためのコードを書かれている月の数を取得したいので、ここでJComboBoxの中で12月
JCombobox month_sands = new JComboBox();
month_sands.addItem("January");
month_sands.addItem("February");
month_sands.addItem("March");
month_sands.addItem("April");
month_sands.addItem("May");
month_sands.addItem("June");
month_sands.addItem("July");
month_sands.addItem("August");
month_sands.addItem("September");
month_sands.addItem("October");
month_sands.addItem("November");
month_sands.addItem("December");
を持って
String month=null;
if(month_sands.getSelectedItem().equals("January"))
{
month="01";
}
if(month_sands.getSelectedItem().equals("February"))
{
month="02";
}
if(month_sands.getSelectedItem().equals("March"))
{
month="03";
}
if(month_sands.getSelectedItem().equals("April"))
{
month="04";
}
if(month_sands.getSelectedItem().equals("May"))
{
month="05";
}
if(month_sands.getSelectedItem().equals("June"))
{
month="06";
}
if(month_sands.getSelectedItem().equals("July"))
{
month="07";
}
if(month_sands.getSelectedItem().equals("August"))
{
month="08";
}
if(month_sands.getSelectedItem().equals("September"))
{
month="09";
}
if(month_sands.getSelectedItem().equals("October"))
{
month="10";
}
if(month_sands.getSelectedItem().equals("November"))
{
month="11";
}
if(month_sands.getSelectedItem().equals("December"))
{
month="12";
}
が、このコードで満足していない、それは短い形式にする他の方法はあり
はい:はるかに良い –
それは私のために働いてくれてありがとう –