Get User Input From a JTextField and Validate it Using Java (GUI JFrame)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 3

  • @santamak
    @santamak 10 หลายเดือนก่อน

    i couldnt focus on learning because of all the screeming

  • @kmow_illonesotho916
    @kmow_illonesotho916 ปีที่แล้ว

    Mr max o sir
    Please do a video about this code .
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class EasyKanban {
    private static final String WELCOME_MESSAGE = "Welcome to EasyKanban";
    private static final String[] TASK_STATUS_OPTIONS = {"To Do", "Done", "Doing"};
    private static int numTasks;
    public static void main(String[] args) {
    JOptionPane.showMessageDialog(null, WELCOME_MESSAGE);
    login();
    numTasks = readNumTasks();
    Task[] tasks = new Task[numTasks];
    for (int i = 0; i < numTasks; i++) {
    tasks[i] = readTask(i);
    JOptionPane.showMessageDialog(null, tasks[i].printTaskDetails());
    }
    JOptionPane.showMessageDialog(null, "Total hours: " + getTotalHours(tasks));
    }
    private static void login() {
    boolean success = false;
    while (!success) {
    String username = JOptionPane.showInputDialog(null, "Enter username:");
    String password = JOptionPane.showInputDialog(null, "Enter password:");
    if (username.equals("admin") && password.equals("password")) {
    success = true;
    } else {
    JOptionPane.showMessageDialog(null, "Invalid login, please try again.");
    }
    }
    }
    private static int readNumTasks() {
    String input = JOptionPane.showInputDialog(null, "Enter number of tasks:");
    return Integer.parseInt(input);
    }
    private static Task readTask(int taskNumber) {
    String taskName = JOptionPane.showInputDialog(null, "Enter task name for Task " + taskNumber + ":");
    String taskDescription = "";
    boolean valid = false;
    while (!valid) {
    taskDescription = JOptionPane.showInputDialog(null, "Enter task description for Task " + taskNumber + ":");
    valid = Task.checkTaskDescription(taskDescription);
    if (!valid) {
    JOptionPane.showMessageDialog(null, "Please enter a task description of less than 50 characters");
    }
    }
    String developerDetails = JOptionPane.showInputDialog(null, "Enter developer details for Task " + taskNumber + ":");
    String taskDuration = JOptionPane.showInputDialog(null, "Enter task duration (hours) for Task " + taskNumber + ":");
    Task task = new Task(taskName, taskDescription, developerDetails, Integer.parseInt(taskDuration));
    return task;
    }
    private static int getTotalHours(Task[] tasks) {
    int totalHours = 0;
    for (Task task : tasks) {
    totalHours += task.getTaskDuration();
    }
    return totalHours;
    }
    private static class Task {
    private static int nextTaskNumber = 0;
    private String taskName;
    private int taskNumber;
    private String taskDescription;
    private String developerDetails;
    private int taskDuration;
    private String taskID;
    private String taskStatus;
    public Task(String taskName, String taskDescription, String developerDetails, int taskDuration) {
    this.taskName = taskName;
    this.taskNumber = nextTaskNumber++;
    this.taskDescription = taskDescription;
    this.developerDetails = developerDetails;
    this.taskDuration = taskDuration;
    this.taskID = createTaskID();
    this.taskStatus = TASK_STATUS_OPTIONS[0];
    }
    public static boolean checkTaskDescription(String taskDescription) {
    return taskDescription.length()