Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class Apl extends JFrame{
  6. protected JButton ad;
  7. protected JTextField tf[]= new JTextField[2];
  8. protected List lst;
  9.  
  10. protected JPanel contr, plst;
  11.  
  12. protected AdSt adSt;
  13. protected Student prs[]=new Student[0];
  14.  
  15. Apl(int x, int y, int ln, int ht){
  16. this.setLayout(new BorderLayout());
  17. this.setBounds(x, y, ln, ht);
  18. this.setVisible(true);
  19. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. this.setTitle("Student's directory - version 1");
  21.  
  22. contr = new JPanel(new FlowLayout());
  23. plst = new JPanel(new FlowLayout());
  24.  
  25. ad = new JButton("add");
  26. contr.add(ad);
  27. tf[0]= new JTextField("name?",10);
  28. tf[1]= new JTextField("note?",3);
  29. contr.add(tf[0]);
  30. contr.add(tf[1]);
  31. ad.addActionListener(adSt=new AdSt());
  32. add("North",contr);
  33.  
  34. lst = new List(10);
  35. plst.add(lst);
  36. add("Center",plst);
  37. revalidate();
  38. }
  39. class AdSt implements ActionListener{
  40. public void actionPerformed(ActionEvent e ){
  41. Student s;
  42. int nt;
  43. String n=tf[0].getText();
  44. try{
  45. nt=Integer.parseInt(tf[1].getText());
  46. }
  47. catch(NumberFormatException ex){
  48. tf[1].setText("note?");
  49. return;
  50. }
  51. Student help[]= new Student[prs.length+1];
  52. System.arraycopy(prs, 0, help, 0, prs.length);
  53. help[help.length-1]= s=new Student(n,nt);
  54. prs=help; tf[0].setText("name?");tf[1].setText("note?");
  55. lst.add(""+s);
  56. revalidate();
  57. }
  58. }
  59. public static void main(String [] arg){
  60. Apl apl=new Apl(20,20,400,300);
  61. }
  62.  
  63. public static List<Student> sort(Student[] students) {
  64. List<Student> studentsList = new ArrayList();
  65.  
  66. for (int i = 0; i < students.length; i++) {
  67. studentsList.add(students[i]);
  68. }
  69. Collections.sort(studentsList);
  70. return studentsList;
  71. }
  72.  
  73. public static Student getStudentByName(Student[] students, String nameOfStudent){
  74. for (int i = 0; i < students.length; i++) {
  75. if(students[i].Name = nameOfStudent){
  76. return students[i];
  77. }
  78. }
  79. return null;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement