java dilini bilənlər məndə java dilində yazılmış proqramda sintaksis sərfi var xaiş mənə köməklik göstərin kim bilirsə kodu yolluyum sintaksis sərfini düzəltsin, tələbəyəm javanı təzə keçirəm sərfi tapammıram
java dilini bilənlər məndə java dilində yazılmış proqramda sintaksis sərfi var xaiş mənə köməklik göstərin kim bilirsə kodu yolluyum sintaksis sərfini düzəltsin, tələbəyəm javanı təzə keçirəm sərfi tapammıram
Verilmiş cavablar və yazılan şərhlər (3 cavab var)
0
burda paylaşın, bəlkə kömək eləyə bildik.
p.s. yazı dilinizdə də xeyli sintaksis səhvləri var![🙂](https://s.w.org/images/core/emoji/15.0.3/svg/1f642.svg)
0
1
/*
2
*@author William_Wilson
3
*@version 1.0
4
*Created May 12, 2007
5
*/
6
7
/*
8
*Import List
9
*/
10
import java.io.File;
11
12
import java.awt.Container;
13
import java.awt.event.ActionEvent;
14
import java.awt.image.BufferedImage;
15
import java.awt.event.ActionListener;
16
17
import javax.swing.JPanel;
18
import javax.swing.JLabel;
19
import javax.swing.JButton;
20
import javax.swing.ImageIcon;
21
import javax.swing.JMenuItem;
22
import javax.swing.JTextArea;
23
import javax.imageio.ImageIO;
24
import javax.swing.JOptionPane;
25
import javax.swing.JFileChooser;
26
27
/*
28
*Steganography_Controller Class
29
*/
30
public class Steganography_Controller
31
{
32
//Program Variables
33
private Steganography_View view;
34
private Steganography model;
35
36
//Panel Displays
37
private JPanel decode_panel;
38
private JPanel encode_panel;
39
//Panel Variables
40
private JTextArea input;
41
private JButton encodeButton,decodeButton;
42
private JLabel image_input;
43
//Menu Variables
44
private JMenuItem encode;
45
private JMenuItem decode;
46
private JMenuItem exit;
47
48
//action event classes
49
private Encode enc;
50
private Decode dec;
51
private EncodeButton encButton;
52
private DecodeButton decButton;
53
54
//decode variable
55
private String stat_path = "";
56
private String stat_name = "";
57
58
/*
59
*Constructor to initialize view, model and environment variables
60
*@param aView A GUI class, to be saved as view
61
*@param aModel A model class, to be saved as model
62
*/
63
public Steganography_Controller(Steganography_View aView, Steganography aModel)
64
{
65
//program variables
66
view = aView;
67
model = aModel;
68
69
//assign View Variables
70
//2 views
71
encode_panel = view.getTextPanel();
72
decode_panel = view.getImagePanel();
73
//2 data options
74
input = view.getText();
75
image_input = view.getImageInput();
76
//2 buttons
77
encodeButton = view.getEButton();
78
decodeButton = view.getDButton();
79
//menu
80
encode = view.getEncode();
81
decode = view.getDecode();
82
exit = view.getExit();
83
84
//assign action events
85
enc = new Encode();
86
encode.addActionListener(enc);
87
dec = new Decode();
88
decode.addActionListener(dec);
89
exit.addActionListener(new Exit());
90
encButton = new EncodeButton();
91
encodeButton.addActionListener(encButton);
92
decButton = new DecodeButton();
93
decodeButton.addActionListener(decButton);
94
95
//encode view as default
96
encode_view();
97
}
98
99
/*
100
*Updates the single panel to display the Encode View.
101
*/
102
private void encode_view()
103
{
104
update();
105
view.setContentPane(encode_panel);
106
view.setVisible(true);
107
}
108
109
/*
110
*Updates the single panel to display the Decode View.
111
*/
112
private void decode_view()
113
{
114
update();
115
view.setContentPane(decode_panel);
116
view.setVisible(true);
117
}
118
119
/*
120
*Encode Class - handles the Encode menu item
121
*/
122
private class Encode implements ActionListener
123
{
124
/*
125
*handles the click event
126
*@param e The ActionEvent Object
127
*/
128
public void actionPerformed(ActionEvent e)
129
{
130
encode_view(); //show the encode view
131
}
132
}
133
134
/*
135
*Decode Class - handles the Decode menu item
136
*/
137
private class Decode implements ActionListener
138
{
139
/*
140
*handles the click event
141
*@param e The ActionEvent Object
142
*/
143
public void actionPerformed(ActionEvent e)
144
{
145
decode_view(); //show the decode view
146
147
//start path of displayed File Chooser
148
JFileChooser chooser = new JFileChooser("./");
149
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
150
chooser.setFileFilter(new Image_Filter());
151
int returnVal = chooser.showOpenDialog(view);
152
if (returnVal == JFileChooser.APPROVE_OPTION){
153
File directory = chooser.getSelectedFile();
154
try{
155
String image = directory.getPath();
156
stat_name = directory.getName();
157
stat_path = directory.getPath();
158
stat_path = stat_path.substring(0,stat_path.length()-stat_name.length()-1);
159
stat_name = stat_name.substring(0, stat_name.length()-4);
160
image_input.setIcon(new ImageIcon(ImageIO.read(new File(image))));
161
}
162
catch(Exception except) {
163
//msg if opening fails
164
JOptionPane.showMessageDialog(view, "The File cannot be opened!",
165
"Error!", JOptionPane.INFORMATION_MESSAGE);
166
}
167
}
168
}
169
}
170
171
/*
172
*Exit Class - handles the Exit menu item
173
*/
174
private class Exit implements ActionListener
175
{
176
/*
177
*handles the click event
178
*@param e The ActionEvent Object
179
*/
180
public void actionPerformed(ActionEvent e)
181
{
182
System.exit(0); //exit the program
183
}
184
}
185
186
/*
187
*Encode Button Class - handles the Encode Button item
188
*/
189
private class EncodeButton implements ActionListener
190
{
191
/*
192
*handles the click event
193
*@param e The ActionEvent Object
194
*/
195
public void actionPerformed(ActionEvent e)
196
{
197
//start path of displayed File Chooser
198
JFileChooser chooser = new JFileChooser("./");
199
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
200
chooser.setFileFilter(new Image_Filter());
201
int returnVal = chooser.showOpenDialog(view);
202
if (returnVal == JFileChooser.APPROVE_OPTION){
203
File directory = chooser.getSelectedFile();
204
try{
205
String text = input.getText();
206
String ext = Image_Filter.getExtension(directory);
207
String name = directory.getName();
208
String path = directory.getPath();
209
path = path.substring(0,path.length()-name.length()-1);
210
name = name.substring(0, name.length()-4);
211
212
String stegan = JOptionPane.showInputDialog(view,
213
"Enter output file name:", "File name",
214
JOptionPane.PLAIN_MESSAGE);
215
216
if(model.encode(path,name,ext,stegan,text))
217
{
218
JOptionPane.showMessageDialog(view, "The Image was encoded Successfully!",
219
"Success!", JOptionPane.INFORMATION_MESSAGE);
220
}
221
else
222
{
223
JOptionPane.showMessageDialog(view, "The Image could not be encoded!",
224
"Error!", JOptionPane.INFORMATION_MESSAGE);
225
}
226
//display the new image
227
decode_view();
228
image_input.setIcon(new ImageIcon(ImageIO.read(new File(path + "/" + stegan + ".png"))));
229
}
230
catch(Exception except) {
231
//msg if opening fails
232
JOptionPane.showMessageDialog(view, "The File cannot be opened!",
233
"Error!", JOptionPane.INFORMATION_MESSAGE);
234
}
235
}
236
}
237
238
}
239
240
/*
241
*Decode Button Class - handles the Decode Button item
242
*/
243
private class DecodeButton implements ActionListener
244
{
245
/*
246
*handles the click event
247
*@param e The ActionEvent Object
248
*/
249
public void actionPerformed(ActionEvent e)
250
{
251
String message = model.decode(stat_path, stat_name);
252
System.out.println(stat_path + ", " + stat_name);
253
if(message != "")
254
{
255
encode_view();
256
JOptionPane.showMessageDialog(view, "The Image was decoded Successfully!",
257
"Success!", JOptionPane.INFORMATION_MESSAGE);
258
input.setText(message);
259
}
260
else
261
{
262
JOptionPane.showMessageDialog(view, "The Image could not be decoded!",
263
"Error!", JOptionPane.INFORMATION_MESSAGE);
264
}
265
}
266
}
267
268
/*
269
*Updates the variables to an initial state
270
*/
271
public void update()
272
{
273
input.setText(""); //clear textarea
274
image_input.setIcon(null); //clear image
275
stat_path = ""; //clear path
276
stat_name = ""; //clear name
277
}
278
279
/*
280
*Main Method for testing
281
*/
282
public static void main(String args[])
283
{
284
new Steganography_Controller(
285
new Steganography_View("Steganography"),
286
new Steganography()
287
);
288
}
289
}
0
Siz hansı univeristetde oxuyursunuz? Bilmey isdiyirem ki, hansı univeristetde java keçiller.![](https://cavablar.net/wp-content/uploads/2012/09/Smartphone-48.png)
Sual verin
Cavab verin