JTextField in UI Designer


I am doing a GUI assignment for my introductory computer science course at my University, and I ran into IDEA’s UI Designer.  I figured out how to customize the UI itself, but now I am running into trouble configuring the listeners.

Here is my code so far:


import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class test
{
     private JPanel panel1;
     private JList list1;
     private ListModel aModel;
     private JTextField textField1;
     private JButton addButton;
     private JButton removeButton;

     public test()
     {
          aModel = list1.getModel();
          addButton.addMouseListener(new MouseAdapter()
          {
               /**
                * {@inheritDoc}
                */
               @Override
               public void mouseClicked(MouseEvent e)
               {
                    //aModel.addElement (String<textField1>); <<This is where I want to add the text inside textField1
                    addButton.setText("Finished");

               }
          });
          textField1.addActionListener(new ActionListener()
          {
               /**
                * Invoked when an action occurs.
                */
               public void actionPerformed(ActionEvent e)
               {
                    //This just needs to keep track of the current text and then send it to the Addbutton listener if it is clicked.
               }
          });
     }

What my course has said so far is that you need to make a special nested class to “handle” all events that occur in the GUI.  But what the GUI designer does is just provide a method which overrides the specific event which I’m dealing with.

Can anyone direct me to some kind of documentation on this (ideally intended for beginners like me) that explains the process of making a functional GUI with listeners achieved through the IDEA GUI Designer?


Thanks.

1 comment
Comment actions Permalink

Ok, so I finally figured out the missing step I wasn't taking: I, of course, couldn't run the program because there was no main method.  You need to press ALT + INS and then select main method.  It does it all for you!

But the question still remains: how do I get the components to communicate with eachother?  Are the listeners you make with the GUI Designer different from the conventional listener which requires the instantiation of the listener class?

0

Please sign in to leave a comment.