利用java编程编写代码,实现如下功能:
3个回答
展开全部
package example;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class demo extends JFrame{
private JMenuBar menu = new JMenuBar();
private JPanel contentPane = new JPanel();
public demo()
{
setTitle("compiler");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menu);
//JMenu correct = new JMenu("正确用例");
//JMenu wrong = new JMenu("错误用例");
////JMenuItem WP = wrong.add("语法错误");
//JMenuItem WL = wrong.add("词法错误");
JMenu edit = new JMenu("编辑");
JMenu help = new JMenu("帮助");
JMenu document = new JMenu("文件");
JMenuItem copy = edit.add("复制");
JMenu color = new JMenu("颜色");
JMenuItem p = color.add("前景色");
p.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"该项目正在建设中", "信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
JMenuItem b = color.add("背景色");
b.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"该项目正在建设中", "信息",
JOptionPane.INFORMATION_MESSAGE);
}
});
edit.add(color);
JMenuItem select = edit.add("全选");
menu.add(document);
menu.add(edit);
menu.add(help);
setLocation(400,200);
setSize(300, 300);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
}
public static void main(String[]args)
{
demo browser = new demo();
browser.setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
public class MenuTester extends JFrame
{
private static final long serialVersionUID = 1L;
public MenuTester ()
{
setTitle ("MenuTester");
JMenuBar menuBar = new JMenuBar ();
JMenu[] menu = new JMenu[] { new JMenu ("文件"), new JMenu ("编辑"), new JMenu ("帮助") };
JMenuItem[] menuItem =
new JMenuItem[] { new JMenuItem ("打开"), new JMenuItem ("保存"), new JMenuItem ("退出"),
new JMenuItem ("复制"), new JMenu ("颜色"), new JMenuItem ("全选"), new JMenuItem ("关于") };
for ( int i = 0; i < 3; i++ )
{
menuBar.add (menu[i]);
}
for ( int i = 0; i < 7; i++ )
{
if (i == 2)
{
menuItem[i].addActionListener (new ActionListener ()
{
public void actionPerformed ( ActionEvent e )
{
System.exit (0);
}
});
}
else
{
menuItem[i].addActionListener (new ActionListener ()
{
public void actionPerformed ( ActionEvent e )
{
JOptionPane.showMessageDialog (null, "该项目正在建设中……", "友情提示", JOptionPane.INFORMATION_MESSAGE);
}
});
}
if (i < 3)
{
menu[0].add (menuItem[i]);
}
else if (i > 2 && i < 6)
{
menu[1].add (menuItem[i]);
if (i == 4)
{
menuItem[i].add (new JMenuItem ("前景色"));
menuItem[i].add (new JMenuItem ("背景色"));
}
}
else
{
menu[2].add (menuItem[i]);
}
}
setJMenuBar (menuBar);
setResizable (false);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setSize (300, 200);
setLocationRelativeTo (null);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
new MenuTester ().setVisible (true);
}
});
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-11-19
展开全部
这是很简单的文本编辑器嘛,你去上csdn搜一下一大把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询