توضح هذه المقالة مفكرة بسيطة تم تنفيذها في Java. شاركها مع الجميع لتكون مرجعا لك. التفاصيل هي كما يلي:
أشعر أن هذا ليس جميل المظهر مثل الذي كتبته باستخدام Windows API من قبل. . .
إصدار JDK: 1.7.0
التأثير كما هو موضح أدناه:
كود المصدر هو كما يلي:
import java.io.*; import java.awt.*; import java.awt.event.*; قائمة القائمة الخاصة تحرير؛ Private MenuItem[] miFile; Private TextArea ta; ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0 } } class SystemExit Extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0 } } class EventMenuClose المنفذة ActionListener { public void actionPerformed( ActionEvent e) { ta.setText(null } } class EventOpenFile Implements ActionListener { public void actionPerformed(ActionEvent e) { // إنشاء مربع حوار OpenFile FileDialog dlg = new FileDialog(frame,"Open Files",FileDialog.LOAD(); String strPath if((strPath = dlg.getDirectory()); ) != null) { // احصل على المسار الكامل للملف المحدد strPath += dlg.getFile(); // افتح الملف حاول { FileInputStream fis = new FileInputStream(strPath); BufferedInputStream bis = new BufferedInputStream(fis); byte[] buf = new byte[3000]; (buf ); ta.append(new String(buf,0,len)); ex) { ex.printStackTrace(); } } } } /** * طريقة البناء * إضافة مكونات القائمة ومنطقة النص * @param strTitle */ public PadFrame(String strTitle) { super(strTitle(this.setLocation(400,200); this.setSize(900, 630); // إنشاء شريط القوائم mb = new MenuBar(); Menu("File"); MenuEdit = new Menu("Edit"); miFile = new MenuItem[]{new MenuItem("Open"),new MenuItem("Close"),new MenuItem("Exit"}); .setMenuBar(mb); mb.add(menuFile); mb.add(menuEdit); miFile.length ; ++i) { MenuFile.add(miFile[i]); 0); setMenuEventHandle(new EventMenuClose(),"File",1); SystemExit()); // أضف مكون TextArea ta = new TextArea(30,30); this.add(ta } public void setMenuEventHandle(ActionListener al,String strMenu,int Index) { if(strMenu == "File ") { miFile[index].addActionListener(al); } } public int getMenuItemAmount(String strMenu) { if("File" == strMenu) { return miFile. length } return -1 } public static void main(String[] args) { PadFrame f = new PadFrame("NotePad" }); }آمل أن تكون هذه المقالة مفيدة لبرمجة جافا للجميع.