java awt 弹出框_java用awt 点击菜单或按钮弹出一个对话框 对话框dialog我创建了 为什么就是点了后没反应...

packageChinesePoker;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classDialogsextendsJDialog{//制作对话框publicDialogs(JFrameparent){super(parent,"Mydialog"...

package ChinesePoker;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Dialogs extends JDialog{//制作对话框

public Dialogs(JFrame parent){

super(parent,"My dialog",true);

Container cp=getContentPane();

cp.setLayout(new FlowLayout());

cp.add(new JLabel("Here is my dialog"));

JButton ok=new JButton("OK");

ok.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

dispose();

}

});

cp.add(ok);

setSize(150,125);

}

}

class PokerFrame extends JFrame implements ActionListener{

private Dialogs dlg=new Dialogs (null);

private MenuItem openMI, exitMI;

private Button b1=new Button("洗 牌");

private Button b2=new Button("发 牌");

private Button b3=new Button("猜大");

private Button b4=new Button("猜小");

private MenuBar mbar =new MenuBar();

private Menu fileMenu =new Menu("菜单");

private Menu fileMenu1 =new Menu("帮助");

PokerFrame()

{

Panel pan= new Panel();

pan.add(b1);

pan.add(b2);

pan.add(b3);

b3.setLocation(900, 56);

b3.setLocation(940, 56);

pan.add(b4);

TextField tf=new TextField("12");

Font font =new Font("Monospaced",Font.PLAIN,15);

tf.setFont(font);

Label lb= new Label("分 数:");

pan.add(lb);

lb.setFont(font);

pan.add(tf,"North");

add(pan,"East");

openMI=new MenuItem("开始");

openMI.addActionListener(this);

fileMenu.add(openMI);

exitMI=new MenuItem("退出");

exitMI.addActionListener(this);

fileMenu.add(exitMI);

mbar.add(fileMenu);

mbar.add(fileMenu1);

setMenuBar(mbar);

setSize(1024,730);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

setVisible(true);

}

public void init(){

fileMenu1.addActionListener(new ActionListener(){//这里增加事件

public void actionPerformed(ActionEvent e){

dlg.setVisible(true);//显示对话框

}

});

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==exitMI)

System.exit(0);

if(e.getSource()==openMI)

System.out.println("open menu item");

}

public static void main(String[] args)

{

new PokerFrame();

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值