• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Looking for a guidance for teaching GUI

Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

/* 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 */
ventana = new JFrame("Aplicaci�n Swing con eventos");
panel = new JPanel(new GridLayout(0, 1));
boton = new JButton("Soy un Bot�n");
etiqueta = new JLabel("N�mero de clics: " + contaClics);

/*Step 5 */
ventana.add(panel); /* Java 5.0 only */

/* Step 6 */
}//cierra crearGUI

/* Step 7*/
public void actionPerformed(ActionEvent evento){
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
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
He baked a muffin that stole my car! And this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic