Topic: 小弟有个程序问题 请指教! |
Print this page |
1.小弟有个程序问题 请指教! | Copy to clipboard |
Posted by: wangliang_kyle Posted on: 2004-09-01 15:00 源代码 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PopDemo extends JFrame { public PopDemo(String str) { super(str); final JPopupMenu mnuRoot=new JPopupMenu(); mnuRoot.add(new JMenuItem("new")); mnuRoot.add(new JMenuItem("save")); mnuRoot.add(new JMenuItem("print")); final JLabel label=new JLabel("press here",JLabel.CENTER); label.addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e) { mnuRoot.show(label,e.getX(),e.getY()); } }); this.getContentPane().add(label); } public Dimension getPreferredSize() { return new Dimension(400,400); } public static void main(String[] args) { PopDemo frame=new PopDemo("use PopupMenu example"); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); //frame.setSize(400,400); frame.pack(); frame.show(); } } 如果把getPreferredSize()的方法去掉 用在main中的frame.setSize(400,400) 是否可以实现同样的功能 |
2.Re:小弟有个程序问题 请指教! [Re: wangliang_kyle] | Copy to clipboard |
Posted by: bluedest Posted on: 2004-09-01 16:44 如果把frame.pack()去掉就可以了。 |
3.Re:小弟有个程序问题 请指教! [Re: wangliang_kyle] | Copy to clipboard |
Posted by: wangliang_kyle Posted on: 2004-09-01 16:52 多谢大侠指点 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |