import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class BuJu7 extends JFrame implements ActionListener
{
JButton jbf=new JButton("第一个");
JButton jbl=new JButton("最后一个");
JButton jbp=new JButton("上一个");
JButton jbn=new JButton("下一个");
JButton jbs=new JButton("中间一个");
JPanel jp=new JPanel();
CardLayout cl=new CardLayout();
public BuJu7()
{
this.setTitle("使用卡片布局管理器");
this.setLayout(null);
jbf.setBounds(120,40,100,20);
jbl.setBounds(120,70,100,20);
jbp.setBounds(120,100,100,20);
jbn.setBounds(120,130,100,20);
jbs.setBounds(120,160,100,20);
this.add(jbf);
this.add(jbl);
this.add(jbp);
this.add(jbn);
this.add(jbs);
jbf.addActionListener(this);
jbl.addActionListener(this);
jbp.addActionListener(this);
jbn.addActionListener(this);
jbs.addActionListener(this);
jp.setBounds(10,40,100,100);
jp.setLayout(cl);
for(int i=0;i<50;i++)
{
JButton jb=new JButton("按钮"+i);
jp.add(jb," "+i);
}
this.add(jp);
this.setBounds(200,200,300,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbf)
{
cl.first(jp);
}
else if(e.getSource()==jbl)
{
cl.last(jp);
}
else if(e.getSource()==jbp)
{
cl.previous(jp);
}
else if(e.getSource()==jbn)
{
cl.next(jp);
}
else if(e.getSource()==jbs)
{
cl.show(jp,"25");
}
}
public static void main(String[] args)
{
BuJu7 s=new BuJu7();
}
}
这道程序,运行后,我点击右边的“中间一个”按钮,为什么不能执行相应的方法了,麻烦哪位去运行下这个简单的程序,看看哪儿出错了咯?呵呵,是不是show方法本身的问题了咯?
import java.awt.event.*;
import java.awt.*;
public class BuJu7 extends JFrame implements ActionListener
{
JButton jbf=new JButton("第一个");
JButton jbl=new JButton("最后一个");
JButton jbp=new JButton("上一个");
JButton jbn=new JButton("下一个");
JButton jbs=new JButton("中间一个");
JPanel jp=new JPanel();
CardLayout cl=new CardLayout();
public BuJu7()
{
this.setTitle("使用卡片布局管理器");
this.setLayout(null);
jbf.setBounds(120,40,100,20);
jbl.setBounds(120,70,100,20);
jbp.setBounds(120,100,100,20);
jbn.setBounds(120,130,100,20);
jbs.setBounds(120,160,100,20);
this.add(jbf);
this.add(jbl);
this.add(jbp);
this.add(jbn);
this.add(jbs);
jbf.addActionListener(this);
jbl.addActionListener(this);
jbp.addActionListener(this);
jbn.addActionListener(this);
jbs.addActionListener(this);
jp.setBounds(10,40,100,100);
jp.setLayout(cl);
for(int i=0;i<50;i++)
{
JButton jb=new JButton("按钮"+i);
jp.add(jb," "+i);
}
this.add(jp);
this.setBounds(200,200,300,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbf)
{
cl.first(jp);
}
else if(e.getSource()==jbl)
{
cl.last(jp);
}
else if(e.getSource()==jbp)
{
cl.previous(jp);
}
else if(e.getSource()==jbn)
{
cl.next(jp);
}
else if(e.getSource()==jbs)
{
cl.show(jp,"25");
}
}
public static void main(String[] args)
{
BuJu7 s=new BuJu7();
}
}
这道程序,运行后,我点击右边的“中间一个”按钮,为什么不能执行相应的方法了,麻烦哪位去运行下这个简单的程序,看看哪儿出错了咯?呵呵,是不是show方法本身的问题了咯?
import java.awt.event.*;
import java.awt.*;public class BuJu7 extends JFrame implements ActionListener {
JButton jbf = new JButton("第一个");
JButton jbl = new JButton("最后一个");
JButton jbp = new JButton("上一个");
JButton jbn = new JButton("下一个");
JButton jbs = new JButton("中间一个");
JPanel jp = new JPanel();
CardLayout cl = new CardLayout(); public BuJu7() {
this.setTitle("使用卡片布局管理器");
this.setLayout(null);
jbf.setBounds(120, 40, 100, 20);
jbl.setBounds(120, 70, 100, 20);
jbp.setBounds(120, 100, 100, 20);
jbn.setBounds(120, 130, 100, 20);
jbs.setBounds(120, 160, 100, 20);
this.add(jbf);
this.add(jbl);
this.add(jbp);
this.add(jbn);
this.add(jbs);
jbf.addActionListener(this);
jbl.addActionListener(this);
jbp.addActionListener(this);
jbn.addActionListener(this);
jbs.addActionListener(this);
jp.setBounds(10, 40, 100, 100);
jp.setLayout(cl);
for (int i = 0; i < 50; i++) {
JButton jb = new JButton("按钮" + i);
jp.add(jb, " " + i);
}
this.add(jp);
this.setBounds(200, 200, 300, 300);
this.setVisible(true);
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbf) {
cl.first(jp);
} else if (e.getSource() == jbl) {
cl.last(jp);
} else if (e.getSource() == jbp) {
cl.previous(jp);
} else if (e.getSource() == jbn) {
cl.next(jp);
} else if (e.getSource() == jbs) {
cl.show(jp, "按钮"+"25");
}
} public static void main(String[] args) {
BuJu7 s = new BuJu7();
}
}
cl.show(jp, "按钮"+"25");
cl.show(jp, " 25");
互换下,下面得那个是space+25
cl.show(jp, " "+"25");// cl.show(jp, " 25"); 两个都可以