作业:按要求编写Java应用程序(希望大佬们多帮忙,紧急)

weixin_46053515 2020-05-21 11:44:16
菜单设计及事件:(1)菜单包括商品管理:商品增加、商品修改、商品删除、分隔线、商品查询;设置:红色、黄色、绿色(2)单击商品查询菜单,跳转到新的框架,单击不同的颜色,框架变色
...全文
146 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_46053515 2020-05-25
  • 打赏
  • 举报
回复
谢谢大佬的帮助
qq_39936465 2020-05-21
  • 打赏
  • 举报
回复
引用 楼主 weixin_46053515 的回复:
菜单设计及事件:(1)菜单包括商品管理:商品增加、商品修改、商品删除、分隔线、商品查询;设置:红色、黄色、绿色(2)单击商品查询菜单,跳转到新的框架,单击不同的颜色,框架变色

public class TestFrame extends JFrame implements ActionListener {
	TestFrame() {
		setSize(480, 300);
		JMenuBar jb = new JMenuBar();
		JMenu jmenu1 = new JMenu("商品管理");
		JMenuItem jitem1 = new JMenuItem("商品增加");
		JMenuItem jitem2 = new JMenuItem("商品修改");
		JMenuItem jitem3 = new JMenuItem("商品删除");
		JMenuItem jitem4 = new JMenuItem("商品查询");
		jmenu1.add(jitem1);
		jmenu1.add(jitem2);
		jmenu1.add(jitem3);
		jmenu1.addSeparator();
		jmenu1.add(jitem4);
		JMenu jmenu2 = new JMenu("设置");
		JMenuItem jitem5 = new JMenuItem("红色");
		JMenuItem jitem6 = new JMenuItem("黄色");
		JMenuItem jitem7 = new JMenuItem("绿色");
		jmenu2.add(jitem5);
		jmenu2.add(jitem6);
		jmenu2.add(jitem7);
		jb.add(jmenu1);
		jb.add(jmenu2);
		jitem4.addActionListener(this);
		jitem5.addActionListener(this);
		jitem6.addActionListener(this);
		jitem7.addActionListener(this);
		setJMenuBar(jb);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args) {
		new TestFrame();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		System.out.println(e.getActionCommand());
		if (e.getActionCommand().equals("商品查询")) {
			new GueryFrame();
		} else if (e.getActionCommand().equals("红色")) {
			getContentPane().setBackground(Color.red);
			repaint();
		} else if (e.getActionCommand().equals("黄色")) {
			getContentPane().setBackground(Color.yellow);
			repaint();
		} else if (e.getActionCommand().equals("绿色")) {
			getContentPane().setBackground(Color.green);
			repaint();
		}

	}

}


public class GueryFrame  extends JFrame {
	
	GueryFrame(){
		setSize(480, 300);
		setTitle("商品查询");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setVisible(true);
	}

}

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧