请完成下列Java程序:用一个边框布局来安排一个工具栏和一个卡片布局。工具栏可浮动,包括2个按钮,一个向前一个向后控制卡片的显示;卡片布局包括3张卡片,分别标识为card1,card2,card3。注意;请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border. LineBorder;public class ex24_2{private static CardLayout cl=new CardLayout();private static JPanel cp=new JPanel();public static void main(String[] args){JFrame. if=new JFrame();jf.setTitle("ex24_2");Container c=jf.getContentPane();JToolBar jtb=new JToolBar();JButton btnNext=new JButton(new ImageIcon("next.gif"));JButton btnPre=new JButton(new ImageIcon("back.gif"));jtb.add(btnPre);jtb.add(btnNext);cp.setLayout(cl);Dimension dim=new Dimension(150,80);cp.setPreferredSize(dim);cp.setBorder(new LineBorder(Color. BLACK));cp.add(new JLabel("cardl",JLabel.CENTER),"card1");cp.add(new JLabel("card2",JLabel.CENTER),"card2");cp.add(new JLabel("card3",JLabel.CENTER),"card3");c.add(jtb,BorderLayout.NORTH);c.add(cp,BorderLayout.CENTER);ActionListener al=new ActionResponse();____________________________________;____________________________________;jf.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});jf.pack();jf.setVisible(true);}static class ActionResponse implements ActionListener{public void actionPerformed(ActionEvent ae){if(ae.getActionCommand().equals("next"))cl.next(cp);elsecl.previous(cp);}}}
请完成下列Java程序:用一个边框布局来安排一个工具栏和一个卡片布局。工具栏可浮动,包括2个按钮,一个向前一个向后控制卡片的显示;卡片布局包括3张卡片,分别标识为card1,card2,card3。
注意;请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border. LineBorder;
public class ex24_2{
private static CardLayout cl=new CardLayout();
private static JPanel cp=new JPanel();
public static void main(String[] args){
JFrame. if=new JFrame();
jf.setTitle("ex24_2");
Container c=jf.getContentPane();
JToolBar jtb=new JToolBar();
JButton btnNext=new JButton(new ImageIcon("next.gif"));
JButton btnPre=new JButton(new ImageIcon("back.gif"));
jtb.add(btnPre);
jtb.add(btnNext);
cp.setLayout(cl);
Dimension dim=new Dimension(150,80);
cp.setPreferredSize(dim);
cp.setBorder(new LineBorder(Color. BLACK));
cp.add(new JLabel("cardl",JLabel.CENTER),"card1");
cp.add(new JLabel("card2",JLabel.CENTER),"card2");
cp.add(new JLabel("card3",JLabel.CENTER),"card3");
c.add(jtb,BorderLayout.NORTH);
c.add(cp,BorderLayout.CENTER);
ActionListener al=new ActionResponse();
____________________________________;
____________________________________;
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
jf.pack();
jf.setVisible(true);
}
static class ActionResponse implements ActionListener{
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand().equals("next"))
cl.next(cp);
else
cl.previous(cp);
}
}
}