packagewindows;importjava.awt.*;importjava.awt.event.*;publicclassAWTTestextendsFrameimplementsActionListener{Panelpanel;ButtonchangeButton;Buttonbutton;Labellabel;TextFi...
package windows;
import java.awt.*;
import java.awt.event.*;
public class AWTTest extends Frame implements ActionListener {
Panel panel;
Button changeButton;
Button button;
Label label;
TextField text;
int i=1;
public AWTTest(){
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
this.setLayout(new GridLayout(2,1));
changeButton=new Button("下一层");
changeButton.addActionListener(this);
this.add(changeButton);
panel=new Panel();
panel.setLayout(new CardLayout());
label=new Label("第一层");
panel.add("first",label);
text=new TextField("第二层");
panel.add("second", text);
button=new Button("返回");
button.addActionListener(this);
panel.add("third", button);
this.add(panel);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String args[]){
new AWTTest();
}
public void actionPerfromed(ActionEvent e){
if(e.getActionCommand().equals("下一层")){
switch(i){
case 1:((CardLayout)panel.getLayout()).show(panel,"second");
break;
case 2:((CardLayout)panel.getLayout()).show(panel,"third");
break;
case 3:((CardLayout)panel.getLayout()).show(panel,"first");
break;
}
i++;
if(i==4){
i=1;
}
}
if(e.getActionCommand().equals("返回")){
i=1;
((CardLayout)panel.getLayout()).show(panel,"first");
}
}
public void actionPerformed(ActionEvent e) {
}
}
就比如这段代码中的this,求大神解答
展开