import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ChangePanelShow extends JFrame{
private JPanel p1 ;
private JPanel p2 ;
private JPanel p3 ;
private JPanel p4 ;
private JPanel p5 ;
private JTextField jtx;
private JButton jbt1 = new JButton("Next");;
private ImageIcon im;
private int count = 0;
private Timer timer;
public ChangePanelShow(){
p1 = new PanelDemo();
p1.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm10.jpg");
p1.add(jbt1);
jbt1.setBounds(280, 430,60, 30);
this.add(p1);
timer=new Timer(7000,new TimerListener());
timer.start();
jbt1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
count++;
changepanel();
}
});
}
public void changepanel(){
if(count==0){
jtx = new JTextField("NB501");
p1 = new PanelDemo();
p1.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm10.jpg");
p1.add(jbt1);
jbt1.setBounds(getWidth()-70, getHeight()-70,60, 30);
p1.add(jtx);
jtx.setBounds(0, getHeight()-70,60, 30);
this.add(p1);
this.getContentPane().removeAll();
this.getContentPane().add(p1,BorderLayout.CENTER);
this.repaint();
this.validate();
}
else if(count==1){
p2 = new PanelDemo();
jtx = new JTextField("JXUFE");
p2.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm15.jpg");
p2.add(jbt1);
jbt1.setBounds(getWidth()-70, getHeight()-70,60, 30);
p2.add(jtx);
jtx.setBounds(0, getHeight()-70,80, 30);
this.add(p2);
this.getContentPane().removeAll();
this.getContentPane().add(p2,BorderLayout.CENTER);
this.repaint();
this.validate();
}
else if(count==2){
p3 = new PanelDemo();
jtx = new JTextField("WELCOME");
p3.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm7.jpg");
p3.add(jbt1);
jbt1.setBounds(getWidth()-70, getHeight()-70,60, 30);
p3.add(jtx);
jtx.setBounds(0, getHeight()-70,80, 30);
this.add(p3);
this.getContentPane().removeAll();
this.getContentPane().add(p3,BorderLayout.CENTER);
this.repaint();
this.validate();
}
else if(count==3){
p4 = new PanelDemo();
p4.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm17.jpg");
p4.add(jbt1);
jbt1.setBounds(getWidth()-70, getHeight()-70,60, 30);
this.add(p4);
this.getContentPane().removeAll();
this.getContentPane().add(p4,BorderLayout.CENTER);
this.repaint();
this.validate();
}
else if(count==4){
p5 = new PanelDemo();
p5.setLayout(null);
im = new ImageIcon("C:\\Users\\XFL\\Pictures\\MM\\mm9.jpg");
p5.add(jbt1);
jbt1.setBounds(getWidth()-70, getHeight()-70,60, 30);
this.add(p5);
this.getContentPane().removeAll();
this.getContentPane().add(p5,BorderLayout.CENTER);
this.repaint();
this.validate();
count=-1;
}
}
pub
lic static void main(String[] args) {
ChangePanelShow frame = new ChangePanelShow();
frame.setSize(350,500);
frame.setTitle("MM");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Image image=new ImageIcon("E:\\java答案\\image\\rbs.gif").getImage();
frame.setIconImage(image);
}
class PanelDemo extends JPanel{
public void paintComponent(Graphics g) {
super.paintComponent(g);
im.setImage(im.getImage().getScaledInstance(getWidth(),getHeight(),Image.SCALE_DEFAULT));
g.drawImage(im.getImage(), 0,0,this);
this.setToolTipText("每隔7秒播放一张图片");
}
}
class TimerListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
count++;
changepanel();
}
}
}