- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewTask.java
More file actions
Latest commit
172 lines (152 loc) · 7.1 KB
/
Copy pathNewTask.java
File metadata and controls
172 lines (152 loc) · 7.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
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
packagetodolistdesktopapp;
importjava.io.BufferedWriter;
importjava.io.FileWriter;
importjava.io.IOError;
importjava.io.IOException;
importjavax.swing.JOptionPane;
/**
*
* @author waqasali
*/
publicclassNewTaskextendsjavax.swing.JFrame {
/**
* Creates new form NewTask
*/
publicNewTask() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
privatevoidinitComponents() {
tfTitle = newjavax.swing.JTextField();
jScrollPane1 = newjavax.swing.JScrollPane();
taDesc = newjavax.swing.JTextArea();
jLabel1 = newjavax.swing.JLabel();
jLabel2 = newjavax.swing.JLabel();
jLabel3 = newjavax.swing.JLabel();
btnSubmit = newjavax.swing.JButton();
btnCancel = newjavax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
taDesc.setColumns(20);
taDesc.setRows(5);
jScrollPane1.setViewportView(taDesc);
jLabel1.setText("Title");
jLabel2.setText("Description");
jLabel3.setText("Adding New Todo Task");
btnSubmit.setText("Submit");
btnSubmit.addActionListener(newjava.awt.event.ActionListener() {
publicvoidactionPerformed(java.awt.event.ActionEventevt) {
btnSubmitActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(newjava.awt.event.ActionListener() {
publicvoidactionPerformed(java.awt.event.ActionEventevt) {
btnCancelActionPerformed(evt);
}
});
javax.swing.GroupLayoutlayout = newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(150, 150, 150)
.addComponent(jLabel3)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCancel)
.addGap(18, 18, 18)
.addComponent(btnSubmit))
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(43, 43, 43))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel3)
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSubmit)
.addComponent(btnCancel))
.addContainerGap(64, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
privatevoidbtnCancelActionPerformed(java.awt.event.ActionEventevt) {//GEN-FIRST:event_btnCancelActionPerformed
gotoMainMenu();
// TODO add your handling code here:
}//GEN-LAST:event_btnCancelActionPerformed
privatevoidgotoMainMenu()
{
java.awt.EventQueue.invokeLater(newRunnable() {
publicvoidrun() {
newMainMenu().setVisible(true);
}
});
dispose();
}
privatevoidbtnSubmitActionPerformed(java.awt.event.ActionEventevt) {//GEN-FIRST:event_btnSubmitActionPerformed
Stringtitle = tfTitle.getText();
Stringdesc = taDesc.getText();
if(title.isEmpty() || desc.isEmpty())
{
JOptionPane.showMessageDialog(rootPane, "Title or Desc can't be empty.");
}
else
{
try{
FileWriterfw = newFileWriter("tasks.txt", true);
BufferedWriterbw = newBufferedWriter(fw);
bw.write(title+","+desc);
bw.newLine();
bw.close();
fw.close();
JOptionPane.showMessageDialog(rootPane, "Task Added Successfully");
gotoMainMenu();
}catch(IOExceptione)
{
JOptionPane.showMessageDialog(rootPane, e.getMessage());
}
}
// TODO add your handling code here:
}//GEN-LAST:event_btnSubmitActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
privatejavax.swing.JButtonbtnCancel;
privatejavax.swing.JButtonbtnSubmit;
privatejavax.swing.JLabeljLabel1;
privatejavax.swing.JLabeljLabel2;
privatejavax.swing.JLabeljLabel3;
privatejavax.swing.JScrollPanejScrollPane1;
privatejavax.swing.JTextAreataDesc;
privatejavax.swing.JTextFieldtfTitle;
// End of variables declaration//GEN-END:variables
}