编写一个程序?电脑高手请进

2024-12-25 07:02:13
推荐回答(1个)
回答1:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.text.*;
public class Homework3 extends JFrame
{
JMenu menu1,menu2;
JMenuBar bar;
JTextPane textPane;
JScrollPane scrollPane;

Homework3()
{

setTitle("记事本");
setSize(300,300);
menu1=new JMenu("File");
menu2=new JMenu("Edit");

bar=new JMenuBar();
textPane=new JTextPane();
scrollPane=new JScrollPane(textPane);
Action[] actions=textPane.getActions();
Container contentPane=getContentPane();
contentPane.add(scrollPane);
bar.add(menu1);
bar.add(menu2);

menu2.add(actions[26]);//Creates a new menu item attached to the specified Action object
menu2.add(actions[14]);//appends it to the end of this menu
menu2.add(actions[65]);
menu2.add(actions[63]);

setJMenuBar(bar);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
这是简单的一个记事本程序,大体能够实现你所说的功能.