为什么我做的这个窗口中File这个下拉菜单没有显示啊??是不是要把他放到Panel里啊?
import java.awt.*;
import javax.swing.*;
public class JFrametest {
public static void main(String[] args) {
JFrame jf=new JFrame();
JMenuBar jmb=new JMenuBar();
JMenu jm=new JMenu();
jf.setTitle("窗口");
jm.setText("File");
jf.setJMenuBar(jmb);
jf.setSize(400,300);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.show();
}
}
[此贴子已经被作者于2006-8-21 22:29:43编辑过]
----------------解决方案--------------------------------------------------------
问题自己解决了!!!呵呵
----------------解决方案--------------------------------------------------------
问题又有了为什么我做的下拉菜单中在New和Exit这2个选项的旁边都有个向右的箭头啊?如果我不要这些箭头该怎么改代码啊??
import java.awt.*;
import javax.swing.*;
public class JFrametest {
public static void main(String[] args) {
JFrame jf=new JFrame();
JMenuBar jmb=new JMenuBar();
JMenu jm=new JMenu("File");
JMenu jm1=new JMenu("New");
JMenu jm2=new JMenu("Exit");
jmb.add(jm);
jm.add(jm1);
jm.add(jm2);
jf.setTitle("窗口");
jf.setJMenuBar(jmb);
jf.setSize(400,300);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.show();
}
}
----------------解决方案--------------------------------------------------------
JMenuItem jm1=new JMenuItem("New");
JMenuItem jm2=new JMenuItem("Exit");
----------------解决方案--------------------------------------------------------
解决 呵呵 不会用API还真麻烦!!
----------------解决方案--------------------------------------------------------
[CODE]
package SimpleProgram;
import javax.swing.*;
import java.awt.Container;
import java.awt.event.*;
public class MenuTest extends JFrame
{
/**
* @param args
*/
private JMenuBar mb;
private JMenu file;
private JMenuItem open;
private JMenuItem exit;
private JMenu help;
private JMenuItem about;
public MenuTest(){
super("JAVA爱好者,苦中乐");
Container contentPane=getContentPane();
mb=new JMenuBar();
file=new JMenu("文件");
help=new JMenu("帮助");
open=new JMenuItem("打开");
exit=new JMenuItem("退出");
about=new JMenuItem("关于");
setJMenuBar(mb);
mb.add(file);
file.add(open);
file.addSeparator();
file.add(exit);
mb.add(help);
help.add(about);
this.setSize(200,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
about.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"苦中乐,一个java痴迷者!北京");
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MenuTest();
}
}
----------------解决方案--------------------------------------------------------