Advertisement
Guest User

Untitled

a guest
May 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JTextArea;
  5. import javax.swing.JLabel;
  6. import javax.swing.JButton;
  7. import java.awt.event.ActionListener;
  8. import java.util.ArrayList;
  9. import java.util.Iterator;
  10. import java.awt.event.ActionEvent;
  11.  
  12. public class mainGUI {
  13.  
  14. private JFrame frame;
  15.  
  16. /**
  17. * Launch the application.
  18. */
  19. public static void main(String[] args) {
  20. EventQueue.invokeLater(new Runnable() {
  21. public void run() {
  22. try {
  23. mainGUI window = new mainGUI();
  24. window.frame.setVisible(true);
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. });
  30. }
  31.  
  32. /**
  33. * Create the application.
  34. */
  35. public mainGUI() {
  36. initialize();
  37. }
  38.  
  39. /**
  40. * Initialize the contents of the frame.
  41. */
  42. private void initialize() {
  43. ArrayList<Student> list = new ArrayList<>();
  44. frame = new JFrame();
  45. frame.setBounds(100, 100, 700, 300);
  46. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47. frame.getContentPane().setLayout(null);
  48.  
  49. JTextArea fioArea = new JTextArea();
  50. fioArea.setBounds(6, 6, 95, 16);
  51. frame.getContentPane().add(fioArea);
  52.  
  53. JTextArea countryArea = new JTextArea();
  54. countryArea.setBounds(6, 32, 95, 16);
  55. frame.getContentPane().add(countryArea);
  56.  
  57. JTextArea yearArea = new JTextArea();
  58. yearArea.setBounds(6, 60, 95, 16);
  59. frame.getContentPane().add(yearArea);
  60.  
  61. JTextArea weigthArea = new JTextArea();
  62. weigthArea.setBounds(6, 88, 95, 16);
  63. frame.getContentPane().add(weigthArea);
  64.  
  65. JLabel label = new JLabel("ФИО");
  66. label.setBounds(113, 6, 61, 16);
  67. frame.getContentPane().add(label);
  68.  
  69. JLabel label_1 = new JLabel("Страна");
  70. label_1.setBounds(113, 32, 61, 16);
  71. frame.getContentPane().add(label_1);
  72.  
  73. JLabel label_2 = new JLabel("Год");
  74. label_2.setBounds(113, 60, 61, 16);
  75. frame.getContentPane().add(label_2);
  76.  
  77. JLabel label_3 = new JLabel("Вес");
  78. label_3.setBounds(113, 88, 72, 16);
  79. frame.getContentPane().add(label_3);
  80.  
  81. JButton addNewStudentButton = new JButton("Добавить спортсмена");
  82. addNewStudentButton.addActionListener(new ActionListener() {
  83. public void actionPerformed(ActionEvent e) {
  84. list.add(new Student(fioArea.getText(), countryArea.getText(), Integer.parseInt(yearArea.getText()), weigthArea.getText()));
  85. }
  86. });
  87. addNewStudentButton.setBounds(6, 141, 168, 29);
  88. frame.getContentPane().add(addNewStudentButton);
  89.  
  90.  
  91. JTextArea showArea = new JTextArea();
  92. showArea.setBounds(186, 6, 459, 203);
  93. frame.getContentPane().add(showArea);
  94.  
  95. JButton showAllStudents = new JButton("Вывести спортсменов");
  96. showAllStudents.addActionListener(new ActionListener() {
  97. public void actionPerformed(ActionEvent e) {
  98. StringBuilder str = new StringBuilder();
  99. Iterator<Student> listIterator = list.iterator();
  100. while(listIterator.hasNext()){
  101. Student index = listIterator.next();
  102. str.append(index.FIO + " " + index.country + " " + index.weigth + " " + index.year + "\n");
  103. }
  104. showArea.setText(str.toString());
  105.  
  106. }
  107. });
  108. showAllStudents.setBounds(6, 167, 168, 29);
  109. frame.getContentPane().add(showAllStudents);
  110.  
  111. JButton showStudentsByGroup = new JButton("Показать по весу");
  112. showStudentsByGroup.addActionListener(new ActionListener() {
  113. public void actionPerformed(ActionEvent e) {
  114. StringBuilder str = new StringBuilder();
  115. Iterator<Student> listIterator = list.iterator();
  116. while(listIterator.hasNext()){
  117. Student index = listIterator.next();
  118. if(index.country.equals("Франция") && index.weigth.equals("Полусредний")){
  119. str.append(index.FIO + " " + index.year + " " + index.country + " " + "\n");
  120. }
  121. }
  122. showArea.setText(str.toString());
  123. }
  124. });
  125. showStudentsByGroup.setBounds(418, 211, 233, 29);
  126. frame.getContentPane().add(showStudentsByGroup);
  127. }
  128. }
  129.  
  130. public class Student {
  131. public String FIO;
  132. public String country;
  133. public Integer year;
  134. public String weigth;
  135.  
  136. public Student(String FIO, String country, Integer year, String weigth){
  137. this.FIO=FIO;
  138. this.country=country;
  139. this.year=year;
  140. this.weigth=weigth;
  141. }
  142.  
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement