| Author |
Looking for a guidance for teaching GUI
|
Enrique Villamizar
Ranch Hand
Joined: Jul 30, 2005
Posts: 87
|
|
I�m a �novel java teacher� from Colombia (ENGLISH ISN'T MY FIRST LANGUAGE) trying to design my own approach for teaching how to create GUI applications using Swing. My idea is to determine a sequence of easy to follow steps for my students. I�m reading the tutorial �Creating a GUI with JFC/Swing� from Sun Microsystems but its methodology is not yet clear to me. So these are the steps that I want to share to all you in the hope you can help me. 1.Import the pertinent packages. 2.In the class declaration implement the appropriate interfaces or extends a class that implements a listener interface. 3.Declare all the class� members. 4.Create and setup the objects you�ve already declared. 5.Add the components down-to-top (first group components in low level containers -e.g. JPanel - then add them to the top level - JFrame, JDialog, JApplet-). 6.Register the instances of the event handler class ones as listener on one o more components. (Steps 4-5-6 in the constructor method). 7.Write the code, in the vent handler class, that implements the methods in the listener interface. 8.Following Sun recommendation: �Be thread-safe� What do you think about it? Am I correct (wrong)? How can I improve the guidance? What happens if the exercises become progressively more difficult? Thanks in advance for your cooperation. EXAMPLE: /* Step 1 */ import javax.swing.*; import java.awt.*; import java.awt.event.*; /* Step 2 */ public class EventosSwing implements ActionListener{ /* Step 3 */ private static int contaClics; /* Contador de clics */ private JFrame ventana; private JPanel panel; private JButton boton; private JLabel etiqueta; /* Steps 4 -5 � 6 in the Constructor */ EventosSwing() { /* Step 4 */ JFrame.setDefaultLookAndFeelDecorated(true); ventana = new JFrame("Aplicaci�n Swing con eventos"); ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel = new JPanel(new GridLayout(0, 1)); panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30)); boton = new JButton("Soy un Bot�n"); etiqueta = new JLabel("N�mero de clics: " + contaClics); /*Step 5 */ panel.add(boton); panel.add(etiqueta); ventana.add(panel); /* Java 5.0 only */ ventana.pack(); ventana.setVisible(true); /* Step 6 */ boton.addActionListener(this); }//cierra crearGUI /* Step 7*/ public void actionPerformed(ActionEvent evento){ contaClics++; etiqueta.setText("N�mero de clics: " + contaClics); }//cierra el m�todo actionPerformed() public static void main(String[] args) { /* Step 8 */ javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { new EventosSwing(); } }); }//cierra main }//cierra la clase
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4695
|
|
Spiral Learning I would start with coding the basic applet with only a button that doesn't do anything & have the class test it to see early on that they are accomplishing something. After that, you can iteratively add functionality such as events, listeners, and "business logic". Every time the students write a few lines of code they should be able to see the results to really understand what the code does.
|
A good workman is known by his tools.
|
 |
Enrique Villamizar
Ranch Hand
Joined: Jul 30, 2005
Posts: 87
|
|
|
Thanks Marc for your gently reply. I forgot to mention that the students I going to teach to, have some basic Java knowledge and the course is about GUI. You�re right, it�s better to go slower, but I need a sequence of steps that my students can follow in order to create interactive GUI with Swing. The Passionate link is great, (Is Kathy Sierra the girl on the picture in the �about page�? if so, she's young and very beautiful), I found very useful information for improving the way we teach and the way we learn, THANKS ONCE AGAIN.
|
 |
 |
|
|
subject: Looking for a guidance for teaching GUI
|
|
|