import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Ex01 extends JFrame
{
JTabbedPane pane=new JTabbedPane(JTabbedPane.TOP);
JScrollPane sp;
public Ex01()
{
JLabel lb[]=new JLabel[6];
//Icon pic;
String title;
for (int i = 0; i<lb.length; i++)
{
//pic=new ImageIcon("00"+i+".jpg");
lb[i]=new JLabel("第"+(String.valueOf(i)+1)+"个");
title="第"+String.valueOf(i)+"页";
pane.add(title,lb[i]);
}
getContentPane().add(pane);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
sp=new JScrollPane(pane,v,h);
addWindowListener(new WinLis());
}
public static void main(String [] args)
{
Ex01 f=new Ex01();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("JTabbedPane 对象的应用");
f.setSize(300,300);
f.setVisible(true);
}
class WinLis extends WindowAdapter
{
public void windowsClosing(WindowEvent e)
{
System.exit(0);
}
}
}
这段代码的原意是:创建一个标签机制,点哪个标签跳出那个页面的图片,我把图片的功能省略了,结果运行出来这么个结果
标签为什么不见了?