我是新手,有一小段代码我看不懂,请问有什么用

来源:百度知道 编辑:UC知道 时间:2024/05/14 14:57:20
看不懂的代码是:
if ("Show".equals(arg)) {
cardLayout.show(cardCont, (String)arg);
return true;
}

此代码来自课本的卡片布局例子,请看源程序:
***********************************

import java.awt.*;

class Main extends Frame
{
CardLayout cardLayout = new CardLayout();
Panel cardCont = new Panel();

Main()
{
super("CardLayout Example");

cardCont.setLayout(cardLayout);
cardCont.add("First",new Button("First"));
cardCont.add("Second",new Button("Second"));
cardCont.add("Third",new Button("Third"));
cardCont.add("Show",new Button("Show"));
cardCont.add("Last",new Button("Last"));
add("Center", cardCont);

Panel p = new Panel();
p.setLayout(new GridLayout(1, 0));

if ("Show".equals(arg))
代表 字符串 SHOW 是不是等于 ARG变量的值
AA.EQUALS(BB); 就是比较AA 和 BB 的值的意思`用于 String 类型的比较
如果是整形 就直接用 ==

如果arg参数的内容等于show,那么卡片显示show ,楼上说对了

arg是action方法的参数,这段代码的意思是如果arg参数的内容等于show,那么就显示卡片上的内容为show