Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JTextArea;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.awt.event.ActionEvent;
- public class mainGUI {
- private JFrame frame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- mainGUI window = new mainGUI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public mainGUI() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- ArrayList<Student> list = new ArrayList<>();
- frame = new JFrame();
- frame.setBounds(100, 100, 700, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JTextArea fioArea = new JTextArea();
- fioArea.setBounds(6, 6, 95, 16);
- frame.getContentPane().add(fioArea);
- JTextArea countryArea = new JTextArea();
- countryArea.setBounds(6, 32, 95, 16);
- frame.getContentPane().add(countryArea);
- JTextArea yearArea = new JTextArea();
- yearArea.setBounds(6, 60, 95, 16);
- frame.getContentPane().add(yearArea);
- JTextArea weigthArea = new JTextArea();
- weigthArea.setBounds(6, 88, 95, 16);
- frame.getContentPane().add(weigthArea);
- JLabel label = new JLabel("ФИО");
- label.setBounds(113, 6, 61, 16);
- frame.getContentPane().add(label);
- JLabel label_1 = new JLabel("Страна");
- label_1.setBounds(113, 32, 61, 16);
- frame.getContentPane().add(label_1);
- JLabel label_2 = new JLabel("Год");
- label_2.setBounds(113, 60, 61, 16);
- frame.getContentPane().add(label_2);
- JLabel label_3 = new JLabel("Вес");
- label_3.setBounds(113, 88, 72, 16);
- frame.getContentPane().add(label_3);
- JButton addNewStudentButton = new JButton("Добавить спортсмена");
- addNewStudentButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- list.add(new Student(fioArea.getText(), countryArea.getText(), Integer.parseInt(yearArea.getText()), weigthArea.getText()));
- }
- });
- addNewStudentButton.setBounds(6, 141, 168, 29);
- frame.getContentPane().add(addNewStudentButton);
- JTextArea showArea = new JTextArea();
- showArea.setBounds(186, 6, 459, 203);
- frame.getContentPane().add(showArea);
- JButton showAllStudents = new JButton("Вывести спортсменов");
- showAllStudents.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- StringBuilder str = new StringBuilder();
- Iterator<Student> listIterator = list.iterator();
- while(listIterator.hasNext()){
- Student index = listIterator.next();
- str.append(index.FIO + " " + index.country + " " + index.weigth + " " + index.year + "\n");
- }
- showArea.setText(str.toString());
- }
- });
- showAllStudents.setBounds(6, 167, 168, 29);
- frame.getContentPane().add(showAllStudents);
- JButton showStudentsByGroup = new JButton("Показать по весу");
- showStudentsByGroup.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- StringBuilder str = new StringBuilder();
- Iterator<Student> listIterator = list.iterator();
- while(listIterator.hasNext()){
- Student index = listIterator.next();
- if(index.country.equals("Франция") && index.weigth.equals("Полусредний")){
- str.append(index.FIO + " " + index.year + " " + index.country + " " + "\n");
- }
- }
- showArea.setText(str.toString());
- }
- });
- showStudentsByGroup.setBounds(418, 211, 233, 29);
- frame.getContentPane().add(showStudentsByGroup);
- }
- }
- public class Student {
- public String FIO;
- public String country;
- public Integer year;
- public String weigth;
- public Student(String FIO, String country, Integer year, String weigth){
- this.FIO=FIO;
- this.country=country;
- this.year=year;
- this.weigth=weigth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement