Code:
import java.awt. *;
import javax.swing. *;
import java.awt.event. *;
public class Jiemian10 extends JFrame {
//menu
JMenuBar cd; // Menu panel
JMenu cd1, cd2, cd3, cd4, cd5; // Menu level button
JMenu cdx1; // Menu secondary button
JMenuItem cdx2, cdx3, cdx4, cdx5, cdx6, cdx7; // Menu Level 2 Ultimate Button
JMenuItem cdsj1, cdsj2; // Menu three-level ultimate button;
// toolbar
JToolBar gjt; // Toolbar panel
JButton an1, an2, an3, an4, an5, an6; // Toolbar buttons
// Text field
JTextArea wby; // Text field
JScrollPane gdt; // Scroll bar
public static void main (String [] args) {
// Execute the constructor
Jiemian10 MyClass = new Jiemian10 ();
}
Jiemian10 () {
// set
gjt = new JToolBar ();
an1 = new JButton ("New");
an1.setToolTipText ("New"); // Prompt message
an2 = new JButton ("Open");
an2.setToolTipText ("Open");
an3 = new JButton ("Save");
an3.setToolTipText ("Save");
an4 = new JButton ("Cut");
an4.setToolTipText ("Cut");
an5 = new JButton ("Copy");
an5.setToolTipText ("Copy");
an6 = new JButton ("Paste");
an6.setToolTipText ("Paste");
cd = new JMenuBar ();
cd1 = new JMenu ("File (F)");
cd1.setMnemonic (‘F’); // ALT + F shortcut key, single quote
cd2 = new JMenu ("Edit (E)");
cd2.setMnemonic (‘E’);
cd3 = new JMenu ("format (O)");
cd3.setMnemonic (‘O’);
cd4 = new JMenu ("View (V)");
cd4.setMnemonic (‘V’);
cd5 = new JMenu ("Help (H)");
cd5.setMnemonic (‘H’);
cdx1 = new JMenu ("New");
cdsj1 = new JMenuItem ("file");
cdsj2 = new JMenuItem ("Template");
cdx2 = new JMenuItem ("Open");
cdx3 = new JMenuItem ("Save");
cdx4 = new JMenuItem ("Save As");
cdx5 = new JMenuItem ("Page Setup");
cdx6 = new JMenuItem ("Print");
cdx7 = new JMenuItem ("Exit");
wby = new JTextArea ();
gdt = new JScrollPane (wby);
// Add the menu to the menu panel
cdx1.add (cdsj1);
cdx1.add (cdsj2);
cd1.add (cdx1);
cd1.add (cdx2);
cd1.add (cdx3);
cd1.addSeparator (); // Add horizontal line
cd1.add (cdx4);
cd1.add (cdx5);
cd1.addSeparator (); // Add horizontal line
cd1.add (cdx6);
cd1.add (cdx7);
cd.add (cd1);
cd.add (cd2);
cd.add (cd3);
cd.add (cd4);
cd.add (cd5);
// Add toolbar buttons to the toolbar panel
gjt.add (an1);
gjt.add (an2);
gjt.add (an3);
gjt.add (an4);
gjt.add (an5);
gjt.add (an6);
// Add a panel to the interface
this.setJMenuBar (cd);
this.add (gjt, BorderLayout.NORTH);
this.add (gdt);
// Set window title
this.setTitle ("Notepad");
// Set the width and height of the window
this.setSize (500,350);
// Add a title bar image
this.setIconImage ((new ImageIcon ("image / 1.jpg")). getImage ());
// Set the position where the window appears to the screen
this.setLocation (100,100);
// Prohibit pulling big and small
//this.setResizable(false);
// Release resources after closing the window
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
// output window
this.setVisible (true);
}
}
Second, run the picture
JAVA interface-Notepad