package day526;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
public class TestCardLayout
implements ActionListener{
[color=red]JPanel jp2=new JPanel();
CardLayout c1=new CardLayout();
Timer t=new Timer(800,this);[/color]
public void actionPerformed(ActionEvent ae) {
String comm =ae.getActionCommand();
if("first".equals(comm)){
c1.first(jp2);
}
else if("next".equals(comm)){
c1.next(jp2);
}
else if("previous".equals(comm)){
c1.previous(jp2);
}
else if("last".equals(comm)){
c1.last(jp2);
}
[color=red]else if("play".equals(comm)){
t.start();
}
else if("stop".equals(comm)){
t.stop();
}
else{//timer
c1.next(jp2);
}[/color] }
public TestCardLayout(){
JFrame jf=new JFrame("TestCardLayout");
String [] blabel={"first","next","previous","last","play","stop"};
JPanel jp1=new JPanel();
jp2.setLayout(c1);
for(int i=0;i<blabel.length;i++){
JButton jb=new JButton(blabel[i]);
jp1.add(jb);
jb.addActionListener(this);
}
for(int i=0;i<3;i++){
Icon ic=new ImageIcon("c:\\"+(i+1)+".jpg");
JLabel jl= new JLabel(ic);
[color=red]jp2.add(jl,""+i);[/color]
}
jf.add(jp2);
jf.add(jp1,BorderLayout.SOUTH);
jf.setSize(800,600);
jf.setLocation(100,80);//
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
TestCardLayout ren=new TestCardLayout();
}
}
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
public class TestCardLayout
implements ActionListener{
[color=red]JPanel jp2=new JPanel();
CardLayout c1=new CardLayout();
Timer t=new Timer(800,this);[/color]
public void actionPerformed(ActionEvent ae) {
String comm =ae.getActionCommand();
if("first".equals(comm)){
c1.first(jp2);
}
else if("next".equals(comm)){
c1.next(jp2);
}
else if("previous".equals(comm)){
c1.previous(jp2);
}
else if("last".equals(comm)){
c1.last(jp2);
}
[color=red]else if("play".equals(comm)){
t.start();
}
else if("stop".equals(comm)){
t.stop();
}
else{//timer
c1.next(jp2);
}[/color] }
public TestCardLayout(){
JFrame jf=new JFrame("TestCardLayout");
String [] blabel={"first","next","previous","last","play","stop"};
JPanel jp1=new JPanel();
jp2.setLayout(c1);
for(int i=0;i<blabel.length;i++){
JButton jb=new JButton(blabel[i]);
jp1.add(jb);
jb.addActionListener(this);
}
for(int i=0;i<3;i++){
Icon ic=new ImageIcon("c:\\"+(i+1)+".jpg");
JLabel jl= new JLabel(ic);
[color=red]jp2.add(jl,""+i);[/color]
}
jf.add(jp2);
jf.add(jp1,BorderLayout.SOUTH);
jf.setSize(800,600);
jf.setLocation(100,80);//
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
TestCardLayout ren=new TestCardLayout();
}
}