JTabbedPane中使用组件,

xingyun21 2004-12-10 04:08:58
程序刚打开的时候,应显示第一个panel中的Label"这是第一页",却显示出了第二个panel中的"这是第二页", 这是为什么?
将第二个panel设为不可见,依旧如此,为何?
请教高手

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 systemLabel=new Label("这是第一页");
/////////////////////end of 界面一/////////////////////////////////////////////
///////////////////////界面二//////////////////////////////////////////////////

Label meansLabel=new Label("这是第二页");
/////////////////////end of 界面二////////////////////////////////////////////

MyTabbedPane()
{
super("使用卡片容器");
jtp=new JTabbedPane();
pn=new JPanel[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]);

}

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;
}

}//end of public void stateChanged(ChangeEvent e)

/////////////////////////////初始化 界面一///////////////////////////////////
public void interface1()
{
pn[0].add(systemLabel);
pn[0].setVisible(true);

}//end of interface1()
/////////////////////////////end of 界面一///////////////////////////////////////

/////////////////////////////初始化 界面二///////////////////////////////////
public void interface2()
{
pn[1].add(meansLabel);
pn[1].setVisible(false);

}//end of interface2

/////////////////////////////end of 界面二///////////////////////////////////////

}//end of class

class WindAdpt extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
(e.getWindow()).dispose();
System.exit(0);
}
}
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingyun21 2004-12-10
  • 打赏
  • 举报
回复
up

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧