Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Assignment #: 6
- // title: Ann Nicoloff
- // StudentID: 1212585684
- // Lecture: TTh 10:30 AM
- // Description: it needs to be filled
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.util.*;
- public class CreatePanel extends JPanel
- {
- private Vector projectList;
- private JButton button1;
- private SelectPanel sPanel;
- private JTextArea projectsList;
- Project project = new Project();
- private ArrayList<Project> projects;
- private JTextField name, number, location, error;
- //Constructor initializes components and organize them using certain layouts
- public CreatePanel(Vector projectList, SelectPanel sPanel)
- {
- this.projectList = projectList;
- this.sPanel = sPanel;
- // organize components here
- // here is an example
- name = new JTextField(15);
- number = new JTextField(15);
- location = new JTextField(15);
- error = new JTextField();
- button1 = new JButton("Create a project");
- ActionListener listener = new ButtonListener();
- button1.addActionListener(listener);
- //this is the grid that takes the user input to create a project
- JPanel panel1 = new JPanel();
- panel1.setLayout(new GridLayout(5,1));
- //text area to display the list of projets created
- JTextArea projectsList = new JTextArea(15, 25);
- projectsList.setText("No Project");
- projectsList.setEditable(false);
- this.projectsList = projectsList;
- JScrollPane scroll = new JScrollPane(projectsList);
- scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- //stores the list of projects created by user
- JList listOfProjects = new JList();
- listOfProjects.setLayoutOrientation(1);
- add(panel1);
- panel1.add(new JLabel(""));
- panel1.add(error);
- panel1.add(new JLabel("Project Title"));
- panel1.add(name);
- panel1.add(new JLabel("Project Number"));
- panel1.add(number);
- panel1.add(new JLabel("Project Location"));
- panel1.add(location);
- panel1.add(button1);
- add(projectsList);
- projectsList.add(listOfProjects);
- }
- //ButtonListener is a listener class that listens to
- //see if the button "Create a project" is pushed.
- //When the event occurs, it add the project information
- //in the text fields to the text area
- //and the list of project information,
- //and it also does error checking.
- private class ButtonListener implements ActionListener
- {
- public void actionPerformed(ActionEvent event)
- {
- // if there is no error, add a project to project list
- // otherwise, show an error message
- project.setProjTitle(name.getText());
- project.setProjLocation(location.getText());
- try
- {
- Integer.parseInt(number.getText());
- error.setText(" Added: " + project.getProjTitle());
- }
- catch(NumberFormatException e)
- {
- error.setText("Please enter a valid number.");
- }
- project.setProjNumber(Integer.parseInt(number.getText()));
- //projects.add(project);
- projectsList.setText(project.toString());
- SelectPanel panel = new SelectPanel(projectList);
- panel.updateProjectList();
- } //end of actionPerformed method
- } //end of ButtonListener class
- } //end of CreatePanel class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement