在Windows笔记本电脑上有效的代码,但由于某些原因在Mac上无效

时间:2019-03-07 13:13:37

标签: java html windows macos add

import java.awt.*;
                    // Contains the Classes for Controls

public class increment extends EasyApp          // EasyApp provides simplified commands
{                                             //  for creating controls and making
   public static void main(String[] args)     //  the actions method simpler
   {   new increment();   }

   //-------- creating CONTROLS -----------------------------------
   List nums = addList("2|4|6",160,200,50,40,this);
   TextField number     = addTextField("",50,200,100,40,this);

   public increment()                                  // Constructor
   {                                                 //  This runs at the beginning.
       setTitle("My First GUI App");                  //  You can do things like 
       setSize(400,300);                              //  changing the Window size
       number.setFont(new Font("Arial",0,20) );    //  or appearance of Controls.
   }

   public void actions(Object source,String command) // When a Button is clicked,
   {                                                 //  this method decides how
       if (nums.getSelectedItem().equals("2")){
           double num = Double.parseDouble(number.getText()) +2;
           number.setText(num + "");
       }
       if (nums.getSelectedItem().equals("4")){
           double num = Double.parseDouble(number.getText()) +4;
           number.setText(num + "");
       }
       if (nums.getSelectedItem().equals("6")){
           double num = Double.parseDouble(number.getText()) +6;
           number.setText(num + "");
       }
   }
}

上面的代码旨在在文本框旁边创建一个下拉菜单(包含数字2,4和6)。用户在文本框中输入数字,然后在下拉菜单中单击文本框中的选项。然后,该程序应将在下拉菜单中选择的数字添加到文本框中的数字。由于某种原因,该代码可在Windows计算机上运行,​​但不能在Mac上运行。谁能帮忙吗?

0 个答案:

没有答案