Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.FinalProject.view;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.time.LocalDate;
- import com.FinalProject.model.*;
- import javax.swing.*;
- import org.jdatepicker.impl.JDatePanelImpl;
- import org.jdatepicker.impl.JDatePickerImpl;
- import org.jdatepicker.impl.UtilDateModel;
- public class AddTaskPanel extends JFrame implements ActionListener{
- Worker w1 = new Worker();
- LocalDate date;
- String str = "";
- JLabel lblDes, lblDuration,l1,lblwname;
- JTextField tfDes, tfDur,tfwname;
- JButton btn1, btn2,btn3;
- AddTaskPanel()
- {
- setVisible(true);
- setSize(600, 300);
- setLayout(null);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setTitle("Add Task Form");
- l1 = new JLabel("Add Task Form - Type Details Below:");
- l1.setForeground(Color.blue);
- l1.setFont(new Font("Serif", Font.BOLD, 20));
- lblDes = new JLabel("Add Task:");
- lblDuration = new JLabel("Task Duration:");
- lblwname = new JLabel("Worker Name: ");
- tfDes = new JTextField();
- tfDur = new JTextField();
- tfwname = new JTextField();
- btn1 = new JButton("Submit");
- btn2 = new JButton("Clear");
- btn3 = new JButton("Back");
- btn1.addActionListener(this);
- btn2.addActionListener(this);
- btn3.addActionListener(this);
- lblDes.setBounds(100, 70, 400, 30);
- lblDuration.setBounds(100, 110, 200, 30);
- lblwname.setBounds(100, 150, 200, 30);
- l1.setBounds(100, 30, 400, 30);
- tfDes.setBounds(300, 70, 200, 30);
- tfDur.setBounds(300, 110, 200, 30);
- tfwname.setBounds(300, 150, 200, 30);
- btn1.setBounds(140, 230, 200, 30);
- btn2.setBounds(360, 230, 200, 30);
- btn3.setBounds(30, 230, 80, 30);
- add(lblDes);
- add(lblDuration);
- add(tfwname);
- add(l1);
- add(tfDur);
- add(tfDes);
- add(lblwname);
- add(btn1);
- add(btn2);
- add(btn3);
- }
- public static void main(String[] args) {
- new AddTaskPanel();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource()==btn1) {
- str = "Task: " + tfDes.getText() + " Duration: "+ tfDur.getText() +"Worker Name: " + tfwname.getText();
- File f = new File(w1.getName() + ".txt");
- try {
- PrintWriter pw = new PrintWriter(f);
- pw.println(str);
- pw.close();
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- System.out.println(str);
- if(e.getSource()==btn2)
- {
- tfDur.setText("");
- tfDes.setText("");
- }
- else if(e.getSource()==btn3)
- {
- MenuPanel mp = new MenuPanel();
- this.setVisible(false);
- mp.setVisible(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement