-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJmenu_Example.java
More file actions
184 lines (156 loc) · 7 KB
/
Jmenu_Example.java
File metadata and controls
184 lines (156 loc) · 7 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//Main.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener{
JMenuItem New,Open,Save,Exit; //File Menu Item
JMenuItem cut,copy,paste; //Edit Menu Item
JMenuItem show,report,tips; //Help Menu Item
JMenuItem about; //About Menu Item
Main(){
//For new JFrame
JFrame x = new JFrame();
x.setSize(500,300);
x.setTitle("New JFrame");
x.getContentPane().setBackground(Color.pink);
//For About JFrame
JLabel abtlbl = new JLabel();
abtlbl.setText("This is Simple GUI Project Made by Mehedi");
abtlbl.setForeground(Color.yellow);
abtlbl.setFont(new Font("Cambria",Font.PLAIN,38));
JFrame abt = new JFrame();
abt.setSize(720,221);
abt.setTitle("About This Project");
abt.getContentPane().setBackground(Color.darkGray);
abt.add(abtlbl);
//Main JFrame
this.setTitle("<<--------------MyProject------------>>");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,270);
this.setLayout(new FlowLayout());
this.getContentPane().setBackground(Color.lightGray);
//JMenuBar
JMenuBar menuBar = new JMenuBar();
//JMenu
JMenu fileMenu = new JMenu("File");
fileMenu.setFont(new Font("Cambria", Font.BOLD, 17));
fileMenu.setForeground(Color.red);
JMenu editMenu = new JMenu("Edit");
editMenu.setFont(new Font("Cambria", Font.BOLD, 17));
editMenu.setForeground(Color.blue);
JMenu helpMenu = new JMenu("Help");
helpMenu.setFont(new Font("Cambria", Font.BOLD, 17));
helpMenu.setForeground(new Color(0xff9c00));
JMenu aboutMenu = new JMenu("About");
aboutMenu.setFont(new Font("Cambria", Font.BOLD, 17));
aboutMenu.setForeground(new Color(0x007000));
//File Menu Item......
New = new JMenuItem("New");
fileMenu.add(New);
New.setFont(new Font("Cambria", Font.BOLD, 15));
New.setForeground(new Color(0xff0075));
New.addActionListener(e -> x.setVisible(true));
Open = new JMenuItem("Open");
fileMenu.add(Open);
Open.setFont(new Font("Cambria", Font.BOLD, 15));
Open.setForeground(new Color(0x0033ff));
Open.addActionListener(e -> System.out.println("Opend a File"));
Save = new JMenuItem("Save");
fileMenu.add(Save);
Save.setFont(new Font("Cambria", Font.BOLD, 15));
Save.setForeground(new Color(0x007000));
Save.addActionListener(e -> System.out.println("File Saved Succesfully"));
Exit = new JMenuItem("Exit");
fileMenu.add(Exit);
Exit.setFont(new Font("Cambria", Font.BOLD, 15));
Exit.setForeground(Color.red);
Exit.addActionListener(e -> System.exit(0));
//Edit Menu Item......
cut = new JMenuItem("Cut");
editMenu.add(cut);
cut.setFont(new Font("Cambria", Font.BOLD, 15));
cut.setForeground(new Color(0x007000));
cut.addActionListener(e -> System.out.println("Cut"));
copy = new JMenuItem("Copy");
editMenu.add(copy);
copy.setFont(new Font("Cambria", Font.BOLD, 15));
copy.setForeground(Color.red);
copy.addActionListener(e -> System.out.println("File Copied Succesfully"));
paste = new JMenuItem("Paste");
editMenu.add(paste);
paste.setFont(new Font("Cambria", Font.BOLD, 15));
paste.setForeground(Color.blue);
paste.addActionListener(e -> System.out.println("File Pasted Succesfully"));
//Help Menu Item......
tips = new JMenuItem("Tips & Tricks");
helpMenu.add(tips);
tips.setFont(new Font("Cambria", Font.BOLD, 15));
tips.setForeground(Color.blue);
tips.addActionListener(e -> System.out.println("No Tips & Tricks Available Now"));
show = new JMenuItem("Show All Commands");
helpMenu.add(show);
show.setFont(new Font("Cambria", Font.BOLD, 15));
show.setForeground(new Color(0x007000));
show.addActionListener(e -> System.out.print("Commands:\nCtrl+F = Find & Replace\nAlt+Z = Run\nCtrl+X = Cut\nCtrl+C = Copy\nCtrl+V = Paste\n"));
report = new JMenuItem("Report Issue");
helpMenu.add(report);
report.setFont(new Font("Cambria", Font.BOLD, 15));
report.setForeground(Color.red);
report.addActionListener(e -> new Report());
//About Menu Item
about = new JMenuItem("About this Project");
aboutMenu.add(about);
about.setFont(new Font("Cambria", Font.BOLD, 15));
about.setForeground(Color.red);
about.addActionListener(e -> abt.setVisible(true));
menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); menuBar.add(aboutMenu);
this.setJMenuBar(menuBar);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e){
}
public static void main(String[] args) {
new Main();
}
}
//Report.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Report extends JFrame implements ActionListener{
JButton btn;
JTextField textField1;
JLabel label2;
Report(){
this.setTitle("Report Page");
this.getContentPane().setBackground(new Color(0x00DCFF));
this.setLayout(new FlowLayout());
this.setSize(600,250);
JLabel label1 = new JLabel();
label1.setText("Report: ");
label1.setFont(new Font("Consolas",Font.PLAIN,28));
textField1 = new JTextField();
textField1.setPreferredSize(new Dimension(380,40));
textField1.setFont(new Font("Consolas",Font.BOLD,20));
textField1.setForeground(Color.red);
label2 = new JLabel();
btn = new JButton("Submit");
btn.setForeground(new Color(0x000000));
btn.setBackground(Color.lightGray);
btn.setFont(new Font("Consolas",Font.PLAIN,33));
btn.addActionListener(this);
this.add(label1);
this.add(textField1);
this.add(btn);
this.add(label2);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn){
label2.setText("Thank You for Reporting us. We try to solve your problem..");
btn.setEnabled(false);
}
}
}