Advertisement
Guest User

tasd

a guest
Feb 20th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. // Assignment #: 6
  2. // title: Ann Nicoloff
  3. // StudentID: 1212585684
  4. // Lecture: TTh 10:30 AM
  5. // Description: it needs to be filled
  6.  
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import javax.swing.*;
  10. import java.util.*;
  11.  
  12. public class CreatePanel extends JPanel
  13. {
  14. private Vector projectList;
  15. private JButton button1;
  16. private SelectPanel sPanel;
  17. private JTextArea projectsList;
  18. Project project = new Project();
  19. private ArrayList<Project> projects;
  20.  
  21. private JTextField name, number, location, error;
  22.  
  23. //Constructor initializes components and organize them using certain layouts
  24. public CreatePanel(Vector projectList, SelectPanel sPanel)
  25. {
  26. this.projectList = projectList;
  27. this.sPanel = sPanel;
  28.  
  29. // organize components here
  30. // here is an example
  31.  
  32. name = new JTextField(15);
  33. number = new JTextField(15);
  34. location = new JTextField(15);
  35. error = new JTextField();
  36. button1 = new JButton("Create a project");
  37.  
  38. ActionListener listener = new ButtonListener();
  39. button1.addActionListener(listener);
  40.  
  41. //this is the grid that takes the user input to create a project
  42. JPanel panel1 = new JPanel();
  43. panel1.setLayout(new GridLayout(5,1));
  44.  
  45. //text area to display the list of projets created
  46. JTextArea projectsList = new JTextArea(15, 25);
  47. projectsList.setText("No Project");
  48. projectsList.setEditable(false);
  49. this.projectsList = projectsList;
  50. JScrollPane scroll = new JScrollPane(projectsList);
  51. scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  52.  
  53. //stores the list of projects created by user
  54. JList listOfProjects = new JList();
  55. listOfProjects.setLayoutOrientation(1);
  56.  
  57. add(panel1);
  58. panel1.add(new JLabel(""));
  59. panel1.add(error);
  60.  
  61. panel1.add(new JLabel("Project Title"));
  62. panel1.add(name);
  63.  
  64. panel1.add(new JLabel("Project Number"));
  65. panel1.add(number);
  66.  
  67. panel1.add(new JLabel("Project Location"));
  68. panel1.add(location);
  69.  
  70. panel1.add(button1);
  71.  
  72. add(projectsList);
  73. projectsList.add(listOfProjects);
  74. }
  75.  
  76.  
  77. //ButtonListener is a listener class that listens to
  78. //see if the button "Create a project" is pushed.
  79. //When the event occurs, it add the project information
  80. //in the text fields to the text area
  81. //and the list of project information,
  82. //and it also does error checking.
  83. private class ButtonListener implements ActionListener
  84. {
  85. public void actionPerformed(ActionEvent event)
  86. {
  87. // if there is no error, add a project to project list
  88. // otherwise, show an error message
  89. project.setProjTitle(name.getText());
  90. project.setProjLocation(location.getText());
  91. try
  92. {
  93. Integer.parseInt(number.getText());
  94. error.setText(" Added: " + project.getProjTitle());
  95. }
  96. catch(NumberFormatException e)
  97. {
  98. error.setText("Please enter a valid number.");
  99. }
  100. project.setProjNumber(Integer.parseInt(number.getText()));
  101. //projects.add(project);
  102. projectsList.setText(project.toString());
  103. SelectPanel panel = new SelectPanel(projectList);
  104. panel.updateProjectList();
  105. } //end of actionPerformed method
  106. } //end of ButtonListener class
  107.  
  108. } //end of CreatePanel class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement