title: I tried making my 2 buttons first one to save and second one to show all , but I couldn't make it work
body: <p>I am trying to make a simple java program that saves data for 20 students which is the first name, last name, which term, and email
  and make 2 buttons to save data after filling it and then another button to print all data.</p>
  <p>My main problem to how to figure out using my action listener.</p>
  <p>First I made student class:</p>
  <pre><code>import java.util.Calendar;
  import java.util.GregorianCalendar;
  import java.util.Scanner;
  public class student {
      static Scanner scr = new Scanner(System.in);
      String [] [] student = new String[20][5];
      private String fornamn;
      private String efternamn;
      private String termin;
      private String username;
      private String epost;
  
      Calendar calendarObj = GregorianCalendar.getInstance();
      int month = calendarObj.get(Calendar.MONTH);
      int year = calendarObj.get(Calendar.YEAR);
  
      public student(String fornamn, String efternamn){ //constructor takes f,e
          this.fornamn = fornamn;
          this.efternamn = efternamn;
  
      }
  
      public student(){ // default constructor
  
      }
  
  
      public void setFornamn(String fornamn ) {
          this.fornamn = fornamn;
      }
      public void setEfternamn (String efternamn ) {
          this.efternamn= efternamn;
      }
  
      public String getFornamn(){
          return fornamn;
      }
      public String getEfternamn(){
          return efternamn;
      }
  
      public String getTermin(){
          return termin;
      }
  
      public void setTermin(String termin) {
          this.termin = termin;
      }
  
      public String getUsername(){
          return username;
      }
      public void setUsername(String username) {
          this.username = username ;
      }
  
      public void setEpost(String epost) {
          this.epost = epost;
      }
      public String getEpost() { return epost;}
  
      int i = 0;
      public String skapaTermin() {
          if (month &lt; 6){
              termin = &quot;ht&quot;;
          } else {
              termin = &quot;vt&quot;;
          }
          return termin;
      }
  
      public String skapaUser() {
          username = termin + fornamn.substring(0,3) + efternamn.substring(0,3);
          return skapaUser();
      }
  
  
      public String skapaEpost(){
          epost = username + &quot;@du.se&quot;;
          return skapaEpost();
      }
  
  }
  </code></pre>
  <p>second  I made this GUI:</p>
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  class mysubclass implements ActionListener{
      static student obj = new student ();    
      JTextField tfFornamn; 
      JLabel lblFornamn;   
      JTextField tfEfternamn; 
      JLabel lblEfternamn; 
      JTextField tfTermin; 
      JLabel lblTermin; 
      JTextField tfUsername; 
      JLabel lblUsername; 
      JTextField tfEpost; 
      JLabel lblEpost; 
      JButton spara ;
      JTextField btnSpara ;
      JButton visaalia ;
      mysubclass() {
          JFrame frame = new JFrame(&quot;student form&quot;);
          JPanel panel = new JPanel();
          frame.setSize(400,350);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(panel);
          panel.setLayout(null);
  
          JLabel lblFornamn = new JLabel(&quot;Förnamn :&quot;); //First name
          lblFornamn.setBounds(10,10,80,35);
          panel.add(lblFornamn);
  
          JTextField tfFornamn = new JTextField(25);  //textfield for first name
          tfFornamn.setBounds(120,10,600,30);
          panel.add(tfFornamn);
  
          JLabel efternamn = new JLabel(&quot;Efternamn :&quot;); //last name 
          efternamn.setBounds(10,50,90,35);
          panel.add(efternamn);
  
          JTextField tfEfternamn = new JTextField(25); // textfield for last name
          tfEfternamn.setBounds(120,50,600,30);
          panel.add(tfEfternamn);
  
          JLabel lblTermin = new JLabel(&quot;Termin  :&quot;); //termin
          lblTermin.setBounds(10,90,90,35);
          panel.add(lblTermin);
  
          JTextField tfTermin = new JTextField(25);   //textfield termin
          tfTermin.setBounds(120,90,600,30);
          panel.add(tfTermin); 
  
          JLabel lblUsername = new JLabel(&quot;Username :&quot;); // username
          lblUsername.setBounds(10,130,90,35);
          panel.add(lblUsername);
  
          JTextField tfUsername = new JTextField(25);   //textfield username
          tfUsername.setBounds(120,130,600,30);
          panel.add(tfUsername); 
  
          JLabel lblEpost = new JLabel(&quot;Epost :&quot;); //email
          lblEpost.setBounds(10,170,90,35);
          panel.add(lblEpost);
  
          JTextField tfEpost = new JTextField(25);   //textfield email
          tfEpost.setBounds(120,170,600,30);
          panel.add(tfEpost); 
  
          JButton spara = new JButton(&quot;Save&quot;);
          spara.setBounds(10,210,120,30);
          panel.add(spara);
          spara.addActionListener(this);
  
          JTextField btnSpara = new JTextField(25);   //textfield save button
          btnSpara.setBounds(150,210,600,130);
          panel.add(btnSpara); 
  
          JButton visaalia  = new JButton(&quot;show all&quot;);
          visaalia.setBounds(10,280,120,30);
          panel.add(visaalia);
          visaalia.addActionListener(this);
  
          frame.setResizable(true); 
          frame.setVisible(true);
  
  
  
      }
      public void actionPerformed(ActionEvent e) {
          if(e.getSource() == spara) {
              obj.setFornamn(tfFornamn.getText()); //encapsulation
              obj.setEfternamn(tfEfternamn.getText());
              obj.setTermin(tfTermin.getText());
              obj.setUsername(tfUsername.getText());
              obj.setEpost(tfEpost.getText());
              for(int i = 0 ; i &lt;= obj.student.length;i++) {
                  obj.student [i][0] = obj.getFornamn();
                  obj.student [i][1] = obj.getEfternamn();
                  obj.student [i][2] = obj.getTermin();
                  obj.student [i][3] = obj.getUsername();
                  obj.student [i][4] = obj.getEpost();
              }
          }
          if(e.getSource() == visaalia) {
              for(int i = 0 ; i &lt;= obj.student.length;i++) {
                  System.out.println(&quot;hi&quot;);
              }
          }
  
  
      }
  }
  </code></pre>
  <p>Then I just called it:</p>
  <pre><code>public class Main {
      public static void main(String[] args) {
          new mysubclass ();
      }
  
  }
  </code></pre>