龙空技术网

java开发仿windows记事本

投资老王 108

前言:

此刻看官们对“java在记事本中怎么运行”大约比较重视,兄弟们都想要学习一些“java在记事本中怎么运行”的相关文章。那么小编也在网摘上汇集了一些关于“java在记事本中怎么运行””的相关资讯,希望各位老铁们能喜欢,你们一起来了解一下吧!

java swing开发的仿windows记事本程序,界面已经画好,菜单功能后续完善。。

java版记事本程序

附源代码:

import java.awt.BorderLayout;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JToolBar;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

public class Jishiben extends JFrame {

JMenuBar cd;// 菜单面板

JMenu cd1, cd2, cd3, cd4, cd5;// 菜单

JMenuItem cdx2, cdx3, cdx4, cdx5, cdx6, cdx7;

JMenu ej;

JMenuItem ej1, ej2;

// JMenuItem是最终的,不可以有下一级菜单。直接响应应用

// JMenu 不是最最终的,点击后出现下一级

JToolBar jtb;// 工具条

JButton jb1, jb2, jb3, jb4, jb5, jb6;

JTextArea jta;

JScrollPane jsp;

public static void main(String[] args) {

String windows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

try {

UIManager.setLookAndFeel(windows);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UnsupportedLookAndFeelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Jishiben js1 = new Jishiben();

}

public Jishiben() {

// 工具条

jtb = new JToolBar();

jb1 = new JButton(new ImageIcon("image/264.jpg"));

jb1.setToolTipText("新建");

jb2 = new JButton(new ImageIcon("image/264.jpg"));

jb2.setToolTipText("打开");

jb3 = new JButton(new ImageIcon("image/264.jpg"));

jb3.setToolTipText("保存");

jb4 = new JButton(new ImageIcon("image/264.jpg"));

jb4.setToolTipText("剪切");

jb5 = new JButton(new ImageIcon("image/264.jpg"));

jb5.setToolTipText("复制");

jb6 = new JButton(new ImageIcon("image/264.jpg"));

jb6.setToolTipText("粘贴");

// 菜单

cd = new JMenuBar();

cd1 = new JMenu("文件(F)");

cd1.setMnemonic('F');

cd2 = new JMenu("编辑(E)");

cd2.setMnemonic('E');

cd3 = new JMenu("格式(O)");

cd3.setMnemonic('O');

cd4 = new JMenu("查看(V)");

cd4.setMnemonic('V');

cd5 = new JMenu("帮助(H)");

cd5.setMnemonic('H');

// 菜单项

ej = new JMenu("新建");

ej1 = new JMenuItem("文件", new ImageIcon("image/263.jpg"));

ej2 = new JMenuItem("模板");

cdx2 = new JMenuItem("打开", new ImageIcon("image/263.jpg"));

cdx3 = new JMenuItem("保存", new ImageIcon("image/263.jpg"));

cdx4 = new JMenuItem("另存为", new ImageIcon("image/263.jpg"));

cdx5 = new JMenuItem("页面设置", new ImageIcon("image/263.jpg"));

cdx6 = new JMenuItem("打印", new ImageIcon("image/263.jpg"));

cdx7 = new JMenuItem("退出", new ImageIcon("image/263.jpg"));

jta = new JTextArea();

jsp = new JScrollPane(jta);

ej.add(ej1);

ej.add(ej2);

cd1.add(ej);

cd1.add(cdx2);

cd1.add(cdx3);

cd1.add(cdx4);

cd1.addSeparator();

cd1.add(cdx5);

cd1.add(cdx6);

cd1.addSeparator();// 添加分割线

cd1.add(cdx7);

jtb.add(jb1);

jtb.add(jb2);

jtb.add(jb3);

jtb.add(jb4);

jtb.add(jb5);

jtb.add(jb6);

cd.add(cd1);

cd.add(cd2);

cd.add(cd3);

cd.add(cd4);

cd.add(cd5);

this.setJMenuBar(cd);// 菜单栏不计入布局

this.add(jtb, BorderLayout.NORTH);

this.add(jsp);// 默认添加到中间

this.setTitle("记事本");

this.setSize(400, 320);

this.setLocation(100, 180);

this.setIconImage((new ImageIcon("image/23.jpg")).getImage());// (new

// ImageIcon("")).getImage()

this.setResizable(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

}

标签: #java在记事本中怎么运行