发布网友 发布时间:2022-05-11 09:40
共3个回答
热心网友 时间:2023-10-10 12:13
自己写的望采纳
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Txt extends JFrame implements ActionListener{
BorderLayout borderLayout = new BorderLayout();
public Txt() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{
String [] file1 ={"新建(N)" ,"打开(O)..." ,"保存 (S)","另存为(A)...","页面设置(U)...","打印(P)...","退出(X)"};
char [] filemc ={'N','O','S','A','U','P','X'};
String [] edit1 ={"撤销(U)","剪切(T)","复制 (C)","粘贴(P)","删除(L)","查找(F)...","查找下一个(N)","替换(R)","转到(G)","全选(A)","时间 /日期(D)"};
char [] editmc ={'U','T','C','P','L','F','N','R','G','A','D'};
String [] form1 = { " 自动换行(W)","字体(F)..."};
char [] formmc = {'W','F'};
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
this.setTitle(" 记事本");
Image im=this.getToolkit().getImage("text1.png");//指定一张图片
this.setIconImage(im);
JMenuBar jmb = new JMenuBar();
jmb.setVisible(true);
this.setJMenuBar(jmb);
JMenu file = new JMenu("文件(F)");
JMenu edit = new JMenu("编辑(E)");
JMenu form = new JMenu("格式(O)");
JMenu view = new JMenu("查看(V)");
JMenu help = new JMenu("帮助(H)");
Font font1 = new Font("newFot",Font.LAYOUT_NO_LIMIT_CONTEXT,12);
file.setMnemonic('F');
file.setFont(font1);
edit.setMnemonic('E');
edit.setFont(font1);
form.setMnemonic('O');
form.setFont(font1);
view.setMnemonic('V');
view.setFont(font1);
help.setMnemonic('H');
help.setFont(font1);
jmb.add(file);
jmb.add(edit);
jmb.add(form);
jmb.add(view);
jmb.add(help);
for (int i=0;i<file1.length;i++){
JMenuItem fileItem= new JMenuItem(file1[i]);
fileItem.setBackground(Color.WHITE);
fileItem.setMnemonic(filemc[i]);
fileItem.setFont(font1);
file.add(fileItem);
if(i==3|i==5){
file.addSeparator();
}
}
for (int i=0;i<edit1.length;i++){
JMenuItem editItem= new JMenuItem(edit1[i]);
editItem.setBackground(Color.WHITE);
editItem.setMnemonic(editmc[i]);
editItem.setFont(font1);
edit.add(editItem);
if(i==0|i==4|i==8){
edit.addSeparator();
}
}
for(int i=0;i<form1.length;i++){
JMenuItem formItem= new JMenuItem(form1[i]);
formItem.setBackground(Color.WHITE);
formItem.setMnemonic(formmc[i]);
formItem.setFont(font1);
form.add(formItem);
}
JMenuItem view1 = new JMenuItem("状态栏(S)");
view1.setMnemonic('S');//设置助记符
view1.setBackground(Color.WHITE);
view1.setFont(font1);
view.add(view1);
JMenuItem helpItem1 =new JMenuItem("帮助主题 (H)");
helpItem1.setFont(font1);
helpItem1.setMnemonic('H');
JMenuItem helpItem2 =new JMenuItem("关于记事本(M)");
helpItem2.setFont(font1);
helpItem2.setMnemonic('M');
helpItem1.setBackground(Color.WHITE);
helpItem2.setBackground(Color.WHITE);
help.add(helpItem1);
help.addSeparator();
help.add(helpItem2);
JTextArea textArea = new JTextArea();
textArea.setFont(new Font("textArea",Font.TRUETYPE_FONT,20));
this.add(textArea,borderLayout.CENTER);
JScrollPane jsb1 = new JScrollPane();
jsb1.getViewport().add(textArea);
this.add(jsb1);
this.setBounds(200, 300,600, 400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* @param args
* @throws UnsupportedLookAndFeelException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
// TODO Auto-generated method stub
Txt txt= new Txt();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
热心网友 时间:2023-10-10 12:13
你说的画,就不是用swing组件来组成的了。画的话要用java.awt.Graphicsh的draw()方法。不过这个一般都是继承JPanel然后再覆盖paint(Graphics g)方法。只要画图形,那么的有一个记事本的图形才行(当然,如果不怕麻烦,也可以先画标题栏再画什么的,一步一步的来)。可以截图windows自带的notepad记事本,然后将这张图片用上面所说的方式画出来。热心网友 时间:2023-10-10 12:14
发布到你的百度HI了.