java 怎么在卡片布局里头放置菜单栏啊?

已举报 回答
java 怎么在卡片布局里头放置菜单栏啊?
问在线客服
扫码问在线客服
  • 回答数

    3

  • 浏览数

    10,035

3个回答 默认排序
  • 默认排序
  • 按时间排序

已采纳
自己弄呗。
取消 评论
你这个程序就是卡片布局了,有2个小错误就是没有对p,c1定义为final.我帮你修改好了
import java.awt.*;
import java.awt.event.*;
public class XtLcb extends Frame
{
public static void main(String args[])
{
Frame frame = new Frame();
frame.setBackground(Color.lightGray);
frame.setSize(400,400);
frame.setVisible(true);
final CardLayout cl = new CardLayout();

MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
MenuItem menuFileOpen = new MenuItem();
MenuItem menuFileOn = new MenuItem();

menuFile.setLabel(File);
menuFileExit.setLabel(Exit);
menuFileOpen.setLabel(Open);
menuFileOn.setLabel(On);

final Panel p = new Panel();
p.setLayout(cl);
Panel p1 = new Panel();
Panel p2 = new Panel();
p1.add(new Label(Open));
p2.add(new Label(On));
p.add(p1,1);
p.add(p2,2);
frame.add(p);

// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
menuFileOpen.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
cl.show(p,1);
}
}

);
menuFileOn.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
cl.show(p,2);
}
}
);
menuFile.add(menuFileOpen);
menuFile.add(menuFileOn);
menuFile.add(menuFileExit);
menuBar.add(menuFile);

frame.setMenuBar(menuBar);

// Add window listener.
frame.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);

}
}
);
}

/**
* Shutdown procedure when run as an application.
*/
/*void windowClosed()
{

// TODO: Check if it is safe to close the application

// Exit application.
System.exit(0);
}*/
}
取消 评论
  import java.awt.*;
import java.awt.event.*;

public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 (WindowAdapter);
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}
取消 评论
ZOL问答 > java 怎么在卡片布局里头放置菜单栏啊?

举报

感谢您为社区的和谐贡献力量请选择举报类型

举报成功

经过核实后将会做出处理
感谢您为社区和谐做出贡献

扫码参与新品0元试用
晒单、顶楼豪礼等你拿

扫一扫,关注我们
提示

确定要取消此次报名,退出该活动?