-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1.java
79 lines (76 loc) · 2.34 KB
/
Q1.java
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
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Q1 extends Dialog implements ActionListener, WindowListener
{
Label l1;
Button b1,b2,b3;
MainMenu k;
Q1(MainMenu p,String tt,boolean rr)
{
super(p,tt,rr);
k=p;
l1= new Label("Do You want to save the Changes");
b1= new Button("Yes Save");
b2=new Button("Dont Save");
b3= new Button("Cancel");
setLayout(new FlowLayout());
add(l1);
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
addWindowListener(this);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
dispose();
}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent arg0) {}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("Yes Save"))
{
try{
k.count=0;
FileDialog f1= new FileDialog(this,"Save",FileDialog.SAVE);
f1.setVisible(true);
FileOutputStream f= new FileOutputStream(f1.getDirectory()+f1.getFile());
str= k.t1.getText();
byte b[]=str.getBytes();
int i;
for(i=0;i<b.length;i++)
{
f.write(b[i]);
}
f.close();
//String name=f1.getFile();//----gets name of the file the user is going to save----
//k.setTitle(name);//--sets title of the name given in save dialog to our file.
this.dispose();//--disposes the Current dialog of New Button---
this.setTitle("Untitled");
k.t1.setText("");
}
catch(Exception e1)
{
}
}
else if(str.equals("Dont Save"))
{
this.setTitle("Untitled");
k.t1.setText(" ");
k.count=0;
this.dispose();
}
else if(str.equals("Cancel"))
{
this.dispose();
}
}
}