java问题请教:下面的程序我明明都在菜单中添加了菜单项,为啥只有最后一个菜单出来菜单项,前面的都没有
importjavax.swing.*;importjava.awt.*;publicclassDemo1713{publicstaticvoidmain(String[...
import javax.swing.*;
import java.awt.*;
public class Demo1713
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
BorderLayout bl = new BorderLayout();
jf.setLayout(bl);
JMenuBar jm = new JMenuBar();
jf.add(jm,BorderLayout.NORTH);
JMenu jm1 = new JMenu("文件");
JMenu jm2 = new JMenu("编辑");
JMenu jm3 = new JMenu("窗口");
JMenuItem ji1 = new JMenuItem("打开");
JMenuItem ji2 = new JMenuItem("关闭");
JMenuItem ji3 = new JMenuItem("退出");
jm1.add(ji1);
jm1.add(ji2);
jm1.add(ji3);
jm2.add(ji1);
jm2.add(ji2);
jm2.add(ji3);
jm3.add(ji1);
jm3.add(ji2);
jm3.add(ji3);
jm.add(jm1);
jm.add(jm2);
jm.add(jm3);
jf.setSize(400,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
} 展开
import java.awt.*;
public class Demo1713
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
BorderLayout bl = new BorderLayout();
jf.setLayout(bl);
JMenuBar jm = new JMenuBar();
jf.add(jm,BorderLayout.NORTH);
JMenu jm1 = new JMenu("文件");
JMenu jm2 = new JMenu("编辑");
JMenu jm3 = new JMenu("窗口");
JMenuItem ji1 = new JMenuItem("打开");
JMenuItem ji2 = new JMenuItem("关闭");
JMenuItem ji3 = new JMenuItem("退出");
jm1.add(ji1);
jm1.add(ji2);
jm1.add(ji3);
jm2.add(ji1);
jm2.add(ji2);
jm2.add(ji3);
jm3.add(ji1);
jm3.add(ji2);
jm3.add(ji3);
jm.add(jm1);
jm.add(jm2);
jm.add(jm3);
jf.setSize(400,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
}
} 展开
展开全部
这是我写的一个图形界面,事件响应还没写,一个空壳子,你看看把
package indexFrame;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.text.DateFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import java.awt.event.*;
public class IndexFrameOfSystem extends JFrame implements ActionListener {
public void launchFrame()
{
setFrameImage();
setFrameJMenu();
setFrameWindow();
this.setTitle("Student's call System");
this.setSize(450,600);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void setFrameImage()
{
ImageIcon icon =new ImageIcon("src/image/Title.jpg");//换左上角图标
this.setIconImage(icon.getImage());
}
public void setFrameJMenu()
{
mb.add(menuFile);
mb.add(menuWindow); //各自添加组件
mb.add(menuHelp);
menuFile.add(menuItemImport);
menuFile.add(menuItemExit);
menuWindow.add(menuItemshowclassInformation);
menuHelp.add(menuItemabout);
this.setJMenuBar(mb);
}
JMenuBar mb=new JMenuBar(); //菜单项的创建
JMenu menuFile=new JMenu("文件");
JMenuItem menuItemImport=new JMenuItem("导入名单");
JMenuItem menuItemExit=new JMenuItem("退出");
JMenu menuWindow =new JMenu("窗口");
JMenuItem menuItemshowclassInformation=new JMenuItem("显示班级信息");
JMenu menuHelp=new JMenu("帮助");
JMenuItem menuItemabout=new JMenuItem("关于");
public void setFrameWindow()
{
this.setLayout(null);
title.setBounds(0,0,450,20);
this.add(title);
classdianmingButton.setBounds(40,40,100,50);
this.add(classdianmingButton);
classtiwenButton.setBounds(280,40,100,50);
this.add(classtiwenButton);
txTextArea.setEditable(false);//不能在上面打字
txTextArea.setBounds(40,120,280,150);
this.add(txTextArea);
xiyiweiButton.setBounds(330,130,80,50);
this.add(xiyiweiButton);
zhantingButton.setBounds(330,210,80,50);
this.add(zhantingButton);
quexiButton.setBounds(40,280,80,30);
bGroup.add(quexiButton);
qingjiaButton.setBounds(150,280,80,30);
bGroup.add(qingjiaButton);
zaotuiButton.setBounds(260,280,80,30);
bGroup.add(zaotuiButton);
this.add(quexiButton);
this.add(qingjiaButton);
this.add(zaotuiButton);
txtArea.setEditable(false);
txtField.setBounds(40,320,280,150);//注意添加坐标的是滚动面板,而不是JTextArea
this.add( txtField);
baochunJButton.setBounds(330,480,100,40);
this.add(baochunJButton);
menuItemImport.addActionListener(this);//监听器
classdianmingButton.addActionListener(this);
classtiwenButton.addActionListener(this);
xiyiweiButton.addActionListener(this);
zhantingButton.addActionListener(this);
quexiButton.addActionListener(this);
qingjiaButton.addActionListener(this);
zaotuiButton.addActionListener(this);
menuItemExit.addActionListener(this);
baochunJButton.addActionListener(this);
menuItemshowclassInformation.addActionListener(this);
menuItemabout.addActionListener(this);
}
JLabel title=new JLabel(" 江西农业大学点名系统");
private JButton classdianmingButton=new JButton("课堂点名");
private JButton classtiwenButton=new JButton("课堂提问");
private JTextField txTextArea=new JTextField();
private JButton xiyiweiButton=new JButton("下一位");
private JButton zhantingButton=new JButton("停止");
private JRadioButton quexiButton=new JRadioButton("缺席");
private JRadioButton qingjiaButton=new JRadioButton("请假");
private JRadioButton zaotuiButton=new JRadioButton("早退");
private ButtonGroup bGroup=new ButtonGroup();
private JTextArea txtArea=new JTextArea();
private JScrollPane txtField=new JScrollPane(txtArea);
private JButton baochunJButton=new JButton("保存名单");
public static void main(String[] args) {
// TODO Auto-generated method stub
IndexFrameOfSystem ui= new IndexFrameOfSystem();
ui.launchFrame();
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
package indexFrame;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.text.DateFormat;
import java.util.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import java.awt.event.*;
public class IndexFrameOfSystem extends JFrame implements ActionListener {
public void launchFrame()
{
setFrameImage();
setFrameJMenu();
setFrameWindow();
this.setTitle("Student's call System");
this.setSize(450,600);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void setFrameImage()
{
ImageIcon icon =new ImageIcon("src/image/Title.jpg");//换左上角图标
this.setIconImage(icon.getImage());
}
public void setFrameJMenu()
{
mb.add(menuFile);
mb.add(menuWindow); //各自添加组件
mb.add(menuHelp);
menuFile.add(menuItemImport);
menuFile.add(menuItemExit);
menuWindow.add(menuItemshowclassInformation);
menuHelp.add(menuItemabout);
this.setJMenuBar(mb);
}
JMenuBar mb=new JMenuBar(); //菜单项的创建
JMenu menuFile=new JMenu("文件");
JMenuItem menuItemImport=new JMenuItem("导入名单");
JMenuItem menuItemExit=new JMenuItem("退出");
JMenu menuWindow =new JMenu("窗口");
JMenuItem menuItemshowclassInformation=new JMenuItem("显示班级信息");
JMenu menuHelp=new JMenu("帮助");
JMenuItem menuItemabout=new JMenuItem("关于");
public void setFrameWindow()
{
this.setLayout(null);
title.setBounds(0,0,450,20);
this.add(title);
classdianmingButton.setBounds(40,40,100,50);
this.add(classdianmingButton);
classtiwenButton.setBounds(280,40,100,50);
this.add(classtiwenButton);
txTextArea.setEditable(false);//不能在上面打字
txTextArea.setBounds(40,120,280,150);
this.add(txTextArea);
xiyiweiButton.setBounds(330,130,80,50);
this.add(xiyiweiButton);
zhantingButton.setBounds(330,210,80,50);
this.add(zhantingButton);
quexiButton.setBounds(40,280,80,30);
bGroup.add(quexiButton);
qingjiaButton.setBounds(150,280,80,30);
bGroup.add(qingjiaButton);
zaotuiButton.setBounds(260,280,80,30);
bGroup.add(zaotuiButton);
this.add(quexiButton);
this.add(qingjiaButton);
this.add(zaotuiButton);
txtArea.setEditable(false);
txtField.setBounds(40,320,280,150);//注意添加坐标的是滚动面板,而不是JTextArea
this.add( txtField);
baochunJButton.setBounds(330,480,100,40);
this.add(baochunJButton);
menuItemImport.addActionListener(this);//监听器
classdianmingButton.addActionListener(this);
classtiwenButton.addActionListener(this);
xiyiweiButton.addActionListener(this);
zhantingButton.addActionListener(this);
quexiButton.addActionListener(this);
qingjiaButton.addActionListener(this);
zaotuiButton.addActionListener(this);
menuItemExit.addActionListener(this);
baochunJButton.addActionListener(this);
menuItemshowclassInformation.addActionListener(this);
menuItemabout.addActionListener(this);
}
JLabel title=new JLabel(" 江西农业大学点名系统");
private JButton classdianmingButton=new JButton("课堂点名");
private JButton classtiwenButton=new JButton("课堂提问");
private JTextField txTextArea=new JTextField();
private JButton xiyiweiButton=new JButton("下一位");
private JButton zhantingButton=new JButton("停止");
private JRadioButton quexiButton=new JRadioButton("缺席");
private JRadioButton qingjiaButton=new JRadioButton("请假");
private JRadioButton zaotuiButton=new JRadioButton("早退");
private ButtonGroup bGroup=new ButtonGroup();
private JTextArea txtArea=new JTextArea();
private JScrollPane txtField=new JScrollPane(txtArea);
private JButton baochunJButton=new JButton("保存名单");
public static void main(String[] args) {
// TODO Auto-generated method stub
IndexFrameOfSystem ui= new IndexFrameOfSystem();
ui.launchFrame();
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
展开全部
就像楼上437384801说的。
多写几个,这样做就行啦:
import javax.swing.*;
import java.awt.*;
public class Demo1713
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
BorderLayout bl = new BorderLayout();
jf.setLayout(bl);
JMenuBar jm = new JMenuBar();
jf.add(jm,BorderLayout.NORTH);
JMenu jm1 = new JMenu("文件");
JMenu jm2 = new JMenu("编辑");
JMenu jm3 = new JMenu("窗口");
jm1.add(new JMenuItem("打开"));
jm1.add(new JMenuItem("关闭"));
jm1.add(new JMenuItem("退出"));
jm2.add(new JMenuItem("打开"));
jm2.add(new JMenuItem("关闭"));
jm2.add(new JMenuItem("退出"));
jm3.add(new JMenuItem("打开"));
jm3.add(new JMenuItem("关闭"));
jm3.add(new JMenuItem("退出"));
jm.add(jm1);
jm.add(jm2);
jm.add(jm3);
jf.setSize(400,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
多写几个,这样做就行啦:
import javax.swing.*;
import java.awt.*;
public class Demo1713
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
BorderLayout bl = new BorderLayout();
jf.setLayout(bl);
JMenuBar jm = new JMenuBar();
jf.add(jm,BorderLayout.NORTH);
JMenu jm1 = new JMenu("文件");
JMenu jm2 = new JMenu("编辑");
JMenu jm3 = new JMenu("窗口");
jm1.add(new JMenuItem("打开"));
jm1.add(new JMenuItem("关闭"));
jm1.add(new JMenuItem("退出"));
jm2.add(new JMenuItem("打开"));
jm2.add(new JMenuItem("关闭"));
jm2.add(new JMenuItem("退出"));
jm3.add(new JMenuItem("打开"));
jm3.add(new JMenuItem("关闭"));
jm3.add(new JMenuItem("退出"));
jm.add(jm1);
jm.add(jm2);
jm.add(jm3);
jf.setSize(400,400);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
因为他是引用,内部函数add()一直在改变
最后一次add最后才改变了确定的一个
不要怕麻烦啊。多写几个。用复制粘贴也不累啊
最后一次add最后才改变了确定的一个
不要怕麻烦啊。多写几个。用复制粘贴也不累啊
追问
我不是怕麻烦,我是不知道该怎么做,请详细指教!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询