请教一个题目,

ctrruby 2012-02-26 08:45:44
import javax.swing.*;import java.awt.event.*;import java.awt.*;
import java.applet.*;import java.awt.CardLayout;
public class Sb_5_7 extends Applet implements ActionListener{
//卡布局
JLabel l1=new JLabel("one");
JLabel l2=new JLabel("two");
JButton b1=new JButton("向前");
JButton b2=new JButton("向后");
CardLayout card=new CardLayout();
BorderLayout bord=new BorderLayout();
JFrame f;
JPanel p1;JPanel p2;
public void init(){
f=new JFrame();
Container con=f.getContentPane();
con.setLayout(bord);
setSize(400,150);
setVisible(true);

JPanel p1=new JPanel();
p1.setLayout(card);
p1.add(l1);p1.add(l2);

JPanel p2=new JPanel();
b1.addActionListener(this);b2.addActionListener(this);
p2.add(b1);p2.add(b2);

con.add(p1,"Center");con.add(p2,"South");

}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("向前")) card.last(p1);
else card.next(p1);

}

}

请问下大家,我这个程序可以运行,但为什么出现一个白板,我定义的东西,怎么都没显示,哪里错了,麻烦帮我改下,谢谢了
...全文
72 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱摸鱼de老邪 2012-02-26
  • 打赏
  • 举报
回复

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.awt.CardLayout;

public class Sb_5_7 extends Applet implements ActionListener {
// 卡布局
JLabel l1 = new JLabel("one");
JLabel l2 = new JLabel("two");
JButton b1 = new JButton("向前");
JButton b2 = new JButton("向后");
CardLayout card = new CardLayout(5,5);
BorderLayout bord = new BorderLayout();
JFrame f;
JPanel p1;
JPanel p2;

public void init() {
f = new JFrame();
Container con = f.getContentPane();
con.setLayout(bord);
setSize(400, 150);
setVisible(true);
p1 = new JPanel();
p1.setLayout(card);
p1.add(l1,"a");
p1.add(l2,"b");

p2 = new JPanel();
b1.addActionListener(this);
b2.addActionListener(this);
p2.add(b1);
p2.add(b2);
con.add(p1, "Center");
con.add(p2, "South");
f.pack();
f.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("向前"))
card.last(p1);
else
card.next(p1);
}

}
ctrruby 2012-02-26
  • 打赏
  • 举报
回复
就是eclipse
xtc1063665705 2012-02-26
  • 打赏
  • 举报
回复
你是学习编辑软件的?虽然以前学过c语言不过还是不会。。。。
ctrruby 2012-02-26
  • 打赏
  • 举报
回复
怎么都没人

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧