|
import java.awt.*;
import java.awt.event.*; import javax.swing.*; import javax.swing.event.*;
public class Noname2 {
public static void main(String args[]) { new MyTabbedPane(); } } class MyTabbedPane extends Frame implements ChangeListener { JTabbedPane jtp; int currentIndex = 0; int systemtype = 1; ///////////////////////////////////////////////////////////////////////////// JPanel[] pn;//= new JPanel(new GridLayout(10, 1));//定义面板
///////////////////////界面一////////////////////////////////////////////////
Label[] Label;
/////////////////////end of 界面一///////////////////////////////////////////// ///////////////////////界面二//////////////////////////////////////////////////
// Label meansLabel = new Label("这是第二页");
/////////////////////end of 界面二////////////////////////////////////////////
MyTabbedPane() {
super("使用卡片容器"); jtp = new JTabbedPane(); pn = new JPanel[9]; Label=new Label[9]; //初始化
for (int i = 0; i < 9; i++) {
pn[i] = new JPanel(new GridLayout(10, 1)); ////初始化,加入布局;
pn[i].setBackground(Color.lightGray); jtp.addTab("第" + (++i) + "步", pn[--i]); Label[i]=new Label("第"+Integer.toString(i+1)+"页"); // Label[i].setText(Integer.toString(i));
}
jtp.addChangeListener(this); add(jtp, BorderLayout.CENTER); addWindowListener(new WindAdpt()); setSize(640, 480); interface1(); //interface2();
show();
} //end of MyTabbedPane()
public void stateChanged(ChangeEvent e) { if (e.getSource() == jtp) { int i = ((JTabbedPane) e.getSource()).getSelectedIndex(); pn[currentIndex].setVisible(false); pn[i].setVisible(true); currentIndex = i; interface1(); }
} //end of public void stateChanged(ChangeEvent e)
/////////////////////////////初始化 界面/////////////////////////////////// public void interface1() { pn[currentIndex].add(Label[currentIndex]); pn[currentIndex].setVisible(true); if(currentIndex>=1){ pn[currentIndex-1].setVisible(false); }
} //end of interface1()
/////////////////////////////end of 界面///////////////////////////////////////
} //end of class
class WindAdpt extends WindowAdapter { public void windowClosing(WindowEvent e) { (e.getWindow()).dispose(); System.exit(0); } } |