java 问题:怎样把这个卡片布局中的的第二张图片,显示出来???求大哥快点解决?
importjava.awt.*;importjavax.swing.*;publicclassBuJu14extendsJFrame{JLabeljl1,jl2,jl3...
import java.awt.*;
import javax.swing.*;
public class BuJu14 extends JFrame{
JLabel jl1,jl2,jl3;
public static void main(String[] args) {
// TODO Auto-generated method stub
BuJu14 shi=new BuJu14();
}
BuJu14(){
jl1=new JLabel(new ImageIcon("src/firstprogram/first/zhang11.jpg"));
jl2=new JLabel((new ImageIcon("src/firstprogram/first/min11.jpg")));
jl3=new JLabel(new ImageIcon("src/Image/QQ.jpg") );
CardLayout cc=new CardLayout();
this.setLayout(cc);
this.add("1",jl1);
this.add("2",jl2);
this.add("3",jl3);
cc.next(this);//为什么显示不出来家里上的图片内???
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
import javax.swing.*;
public class BuJu14 extends JFrame{
JLabel jl1,jl2,jl3;
public static void main(String[] args) {
// TODO Auto-generated method stub
BuJu14 shi=new BuJu14();
}
BuJu14(){
jl1=new JLabel(new ImageIcon("src/firstprogram/first/zhang11.jpg"));
jl2=new JLabel((new ImageIcon("src/firstprogram/first/min11.jpg")));
jl3=new JLabel(new ImageIcon("src/Image/QQ.jpg") );
CardLayout cc=new CardLayout();
this.setLayout(cc);
this.add("1",jl1);
this.add("2",jl2);
this.add("3",jl3);
cc.next(this);//为什么显示不出来家里上的图片内???
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} 展开
1个回答
展开全部
给你改好了,自己看看吧
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
JLabel jl1, jl2, jl3;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test shi = new Test();
}
Test(){
jl1=new JLabel(new ImageIcon("src/ActionListen/1.jpg"));
jl2=new JLabel(new ImageIcon("src/ActionListen/2.jpg"));
jl3=new JLabel(new ImageIcon("src/ActionListen/3.jpg") );
CardLayout cc=new CardLayout();
this.setLayout(cc);
getContentPane().add("1",jl1);
getContentPane().add("2",jl2);
getContentPane().add("3",jl3);
cc.next(getContentPane());
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
JLabel jl1, jl2, jl3;
public static void main(String[] args) {
// TODO Auto-generated method stub
Test shi = new Test();
}
Test(){
jl1=new JLabel(new ImageIcon("src/ActionListen/1.jpg"));
jl2=new JLabel(new ImageIcon("src/ActionListen/2.jpg"));
jl3=new JLabel(new ImageIcon("src/ActionListen/3.jpg") );
CardLayout cc=new CardLayout();
this.setLayout(cc);
getContentPane().add("1",jl1);
getContentPane().add("2",jl2);
getContentPane().add("3",jl3);
cc.next(getContentPane());
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
更多追问追答
追问
为什么不能用this代替getContentPane() ,小弟是个新手?
追答
this代表的是jframe,组件不能直接加到jframe上,getContentPane()就得到了这个jframe的面板了,组件都应该放到面板上的...
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询