-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenu.java
More file actions
53 lines (34 loc) · 1.1 KB
/
Menu.java
File metadata and controls
53 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package learn;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Menu extends JFrame {
public Menu(){
setTitle("Swing-menu");
JMenuBar menubar = new JMenuBar();
ImageIcon icon= new ImageIcon("/home/john/Desktop/exit.png");
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenuItem fileClose = new JMenuItem("close",icon);
fileClose.setMnemonic(KeyEvent.VK_C);
fileClose.setToolTipText("Exit application");
fileClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
file.add(fileClose);
menubar.add(file);
setJMenuBar(menubar);
setSize(250,200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new Menu();
// write your code here
}
}