| 
 package nicholas.swing; 
import javax.swing.*; import java.awt.*; import java.awt.event.*; 
public class GuideFrame extends JFrame implements ActionListener {    private CheckPanel panel[];  private JButton nextButton;  private JButton prevButton;  private JButton exitButton;    private JLabel titleLabel;  private JLabel detailLabel;  private JLabel imageLabel;    private int current;    public GuideFrame() {   super();   current = 0;   getContentPane().setLayout(null);   setupUI();   setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);   setResizable(false);   setSize(500,360);   Dimension screen = getToolkit().getScreenSize();   setLocation((screen.width-getSize().width)/2, (screen.height-getSize().height)/2);   show();  }    public void setPanel(CheckPanel p[]) {   panel = p;      for(int i=0;i<panel.length;i++) {    panel[i].setBounds(-2,53,504,235);    getContentPane().add(panel[i]);   }   panel[0].setVisible(true);  }    private void setupUI() {   titleLabel = new JLabel("标题");   titleLabel.setBounds(10,5,200,20);   detailLabel = new JLabel("详细");   detailLabel.setBounds(20,20,300,20);   //enable this sentence will greatly slow down the speed. //  detailLabel.setFont(new Font("宋体",Font.PLAIN,12));   imageLabel = new JLabel();   imageLabel.setBounds(445,7,40,40);   imageLabel.setBorder(BorderFactory.createEtchedBorder());      JPanel panel = new JPanel(null);   panel.setBounds(0,0,500,53);   panel.setBackground(Color.white);   panel.add(titleLabel);   panel.add(detailLabel);   panel.add(imageLabel);   getContentPane().add(panel);      prevButton = new JButton("上一步");   prevButton.setBounds(245,298,75,21);   prevButton.addActionListener(this);   prevButton.setVisible(false);   nextButton = new JButton("下一步");   nextButton.setBounds(325,298,75,21);   nextButton.addActionListener(this);   exitButton = new JButton("取消");   exitButton.setBounds(413,298,65,21);   exitButton.addActionListener(this);   getContentPane().add(prevButton);   getContentPane().add(nextButton);   getContentPane().add(exitButton);  }    private void quit() {  }    public void actionPerformed(ActionEvent ae) {   if(ae.getSource()==exitButton) {    int result = JOptionPane.showConfirmDialog(this,"您是否确认要退出本向导?\n所有信息将丢失.",        "退出",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);    if(result==JOptionPane.YES_OPTION) {     System.exit(0);    }    } else if(ae.getSource()==nextButton) {    if(panel[current].check()) {     //can do next job     panel[current].setVisible(false);     current++;     if(current==1) {      prevButton.setVisible(true);     }     if(current==(panel.length-1)) {      prevButton.setVisible(false);      nextButton.setText("完成");     } else if(current==panel.length) {      quit();      return;     }     panel[current].setVisible(true);     repaint();    } else {     //cannot continue     JOptionPane.showMessageDialog(this,panel[current].getErrorMessage(),       "警告",JOptionPane.ERROR_MESSAGE);     return;    }   } else {    panel[current].setVisible(false);    current--;    panel[current].setVisible(true);    if(current==0) {     prevButton.setVisible(false);    }    repaint();   }  } }  |