Advertisement
Osher15151

TaskPanel

Jul 1st, 2020
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1. package com.FinalProject.view;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.io.PrintWriter;
  10. import java.time.LocalDate;
  11.  
  12. import com.FinalProject.model.*;
  13. import javax.swing.*;
  14.  
  15. import org.jdatepicker.impl.JDatePanelImpl;
  16. import org.jdatepicker.impl.JDatePickerImpl;
  17. import org.jdatepicker.impl.UtilDateModel;
  18.  
  19.  
  20. public class AddTaskPanel extends JFrame implements ActionListener{
  21.    
  22.     Worker w1 = new Worker();
  23.     LocalDate date;
  24.     String str = "";
  25.     JLabel lblDes, lblDuration,l1,lblwname;
  26.     JTextField tfDes, tfDur,tfwname;
  27.     JButton btn1, btn2,btn3;  
  28.    
  29.     AddTaskPanel()
  30.     {
  31.        
  32.         setVisible(true);  
  33.         setSize(600, 300);  
  34.         setLayout(null);  
  35.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  36.         setTitle("Add Task Form");
  37.         l1 = new JLabel("Add Task Form - Type Details Below:");  
  38.         l1.setForeground(Color.blue);  
  39.         l1.setFont(new Font("Serif", Font.BOLD, 20));  
  40.         lblDes = new JLabel("Add Task:");    
  41.         lblDuration = new JLabel("Task Duration:");  
  42.         lblwname = new JLabel("Worker Name: ");
  43.        
  44.         tfDes = new JTextField();  
  45.         tfDur = new JTextField();
  46.         tfwname = new JTextField();
  47.        
  48.        
  49.         btn1 = new JButton("Submit");  
  50.         btn2 = new JButton("Clear");  
  51.         btn3 = new JButton("Back");  
  52.         btn1.addActionListener(this);  
  53.         btn2.addActionListener(this);  
  54.         btn3.addActionListener(this);
  55.         lblDes.setBounds(100, 70, 400, 30);  
  56.         lblDuration.setBounds(100, 110, 200, 30);
  57.         lblwname.setBounds(100, 150, 200, 30);
  58.         l1.setBounds(100, 30, 400, 30);  
  59.        
  60.         tfDes.setBounds(300, 70, 200, 30);  
  61.         tfDur.setBounds(300, 110, 200, 30);
  62.         tfwname.setBounds(300, 150, 200, 30);
  63.        
  64.         btn1.setBounds(140, 230, 200, 30);
  65.         btn2.setBounds(360, 230, 200, 30);  
  66.         btn3.setBounds(30, 230, 80, 30);
  67.        
  68.         add(lblDes);  
  69.         add(lblDuration);
  70.         add(tfwname);
  71.         add(l1);
  72.         add(tfDur);  
  73.         add(tfDes);  
  74.         add(lblwname);  
  75.        
  76.        
  77.         add(btn1);  
  78.         add(btn2);
  79.         add(btn3);
  80.     }
  81.    
  82. public static void main(String[] args) {
  83.        
  84.         new AddTaskPanel();
  85.     }
  86.  
  87.     @Override
  88.     public void actionPerformed(ActionEvent e) {
  89.  
  90.         if(e.getSource()==btn1) {
  91.             str = "Task: " + tfDes.getText() + " Duration: "+ tfDur.getText() +"Worker Name: " + tfwname.getText();
  92.                File f = new File(w1.getName() + ".txt");
  93.                try {
  94.                    PrintWriter pw = new PrintWriter(f);
  95.                    pw.println(str);
  96.                    pw.close();
  97.                } catch (FileNotFoundException e1) {
  98.                    // TODO Auto-generated catch block
  99.                    e1.printStackTrace();
  100.                }  
  101.        }
  102.      
  103.        System.out.println(str);
  104.        
  105.         if(e.getSource()==btn2)
  106.         {
  107.             tfDur.setText("");  
  108.             tfDes.setText("");  
  109.  
  110.         }
  111.        
  112.         else if(e.getSource()==btn3)
  113.         {
  114.             MenuPanel mp = new MenuPanel();
  115.             this.setVisible(false);
  116.             mp.setVisible(true);
  117.         }
  118.        
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement