我刚学习java。。。在编辑卡片管理器布局的程序。。。但不知道哪里出错。。。求大神帮忙。。。
importjava.awt.*;importjava.awt.event.*;publicclassCardLayoutDemoextendsFrameimplemen...
import java.awt.*;
import java.awt.event.*;
public class CardLayoutDemo extends Frame implements MouseListener
{
public CardLayoutDemo(String string)
{
super(string);
init();
}
public static void main(String[] args)
{
new CardLayoutDemo("CardLayout1");
}
public void init()
{
setLayout(new BorderLayout());
setSize(400,300);
Panel p = new Panel();
p.setLayout(new FlowLayout());
first.addMouseListener(this);
second.addMouseListener(this);
third.addMouseListener(this);
p.add(first);
p.add(second);
p.add(third);
add("North",p);
cards.setLayout(cl);//设置panel为卡片布局器
cards.add("First card",new Button("赵文杰..."));
cards.add("second card",new Button("涂静敏..."));
cards.add("third card",new Button("赵涂涂..."));
add("Center",cards);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
setVisible(true);
}
//实现监听器方法
public void mouseClicked(MouseEvent evt)
{
if(evt.getSource()==first)
{ cl.first(cards);}
else if(evt.getSource()==second)
{
cl.first(cards);
cl.next(cards);
}
else if(evt.getSource()==third)
{
cl.last(cards);
}
}
public void mouseEntered(MouseEvent arg[ ]){ }
public void mouseExited(MouseEvent arg[ ]){ }
public void mousePressed(MouseEvent arg[ ]){ }
public void mouseReleased(MouseEvent arg[ ]){ }
private Button first = new Button("第一页");
private Button second = new Button("第二页");
private Button third = new Button("第三页");
private Panel cards = new Panel();
private CardLayout cl = new CardLayout();
private Frame f =new Frame();
} 展开
import java.awt.event.*;
public class CardLayoutDemo extends Frame implements MouseListener
{
public CardLayoutDemo(String string)
{
super(string);
init();
}
public static void main(String[] args)
{
new CardLayoutDemo("CardLayout1");
}
public void init()
{
setLayout(new BorderLayout());
setSize(400,300);
Panel p = new Panel();
p.setLayout(new FlowLayout());
first.addMouseListener(this);
second.addMouseListener(this);
third.addMouseListener(this);
p.add(first);
p.add(second);
p.add(third);
add("North",p);
cards.setLayout(cl);//设置panel为卡片布局器
cards.add("First card",new Button("赵文杰..."));
cards.add("second card",new Button("涂静敏..."));
cards.add("third card",new Button("赵涂涂..."));
add("Center",cards);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
setVisible(true);
}
//实现监听器方法
public void mouseClicked(MouseEvent evt)
{
if(evt.getSource()==first)
{ cl.first(cards);}
else if(evt.getSource()==second)
{
cl.first(cards);
cl.next(cards);
}
else if(evt.getSource()==third)
{
cl.last(cards);
}
}
public void mouseEntered(MouseEvent arg[ ]){ }
public void mouseExited(MouseEvent arg[ ]){ }
public void mousePressed(MouseEvent arg[ ]){ }
public void mouseReleased(MouseEvent arg[ ]){ }
private Button first = new Button("第一页");
private Button second = new Button("第二页");
private Button third = new Button("第三页");
private Panel cards = new Panel();
private CardLayout cl = new CardLayout();
private Frame f =new Frame();
} 展开
3个回答
展开全部
你少实现了几个方法 如下租没:
@Override
public void mousePressed(MouseEvent e) {
/弯型行/ TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
/埋哗/ TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
/弯型行/ TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
/埋哗/ TODO Auto-generated method stub
}
展开全部
你是遇到什么错误了?乱码?还是程序有错或昌?
楼上说的对,你没有衫改扒实现接口中的四个方法。你可以用Eclipse自动提示功能帮你实现。
另外如果是乱码的问题话,你可以更改elipse的编码,现在要想程序显示出你要的结果,你可以把中文改成英文。歼派
楼上说的对,你没有衫改扒实现接口中的四个方法。你可以用Eclipse自动提示功能帮你实现。
另外如果是乱码的问题话,你可以更改elipse的编码,现在要想程序显示出你要的结果,你可以把中文改成英文。歼派
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不能一口一个胖子啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询