package cardlayout;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class UseTabbedPane {
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyTabbedPane();
}
}
class MyTabbedPane extends JFrame implements ChangeListener{
JTabbedPane jtab;
JPanel jp1,jp2,jp3;
int currentIndex =0;
MyTabbedPane(){
super("使用标签容器");
jp1 =new JPanel();
jp1.add(new JLabel("JPanel #1"));
jp2 =new JPanel();
jp2.add(new JLabel("JPanel #2"));
jp3 =new JPanel();
jp3.add(new JLabel("JPanel #3"));
jtab =new JTabbedPane();
jtab.addTab("Tab 1", new ImageIcon("book.gif"),jp1);
jtab.addTab("Tab 2", new ImageIcon("book.gif"),jp2);
jtab.addTab("Tab 3", new ImageIcon("book.gif"),jp3);
jtab.addChangeListener(this);
add(jtab,BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,200);
setVisible(true);
}
@Override
public void stateChanged(ChangeEvent e) {
// TODO Auto-generated method stub
int i=((JTabbedPane)e.getSource()).getSelectedIndex()+1;
setTitle("你选择了标签Tab"+i);
}
}
JTabbedPane标签容器练习
最新推荐文章于 2021-02-20 18:08:49 发布