Os arquivos abaixo foram extraídos do Livro:

An Introduction to Graphical User Interfaces with Java Swing

 

package its.CounterGUI;

 

public class CounterDriver {

  public static void main(String[] args) {

    CounterFrame cfr = new CounterFrame();

    cfr.showIt("Counter");

  }

}

 

package its.CounterGUI;

 

import javax.swing.JFrame;

import java.awt.BorderLayout;

import its.SimpleFrame.SimpleFrame;

 

 

public class CounterFrame extends SimpleFrame{

  public CounterFrame(){

    CounterPanel counterPane = new CounterPanel();

    this.getContentPane().add(counterPane,BorderLayout.CENTER);

  }

}

 

package its.SimpleFrame;

 

import javax.swing.JFrame;

 

public class SimpleFrame extends JFrame{

  public SimpleFrame(){

    this.setSize(200,200);

    this.setLocation(200,200);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }

 

   // Makes the frame visible.

  public void showIt(){

    this.setVisible(true);

  }

 

  // Makes the frame visible and sets the title text.

  public void showIt(String title){

    this.setTitle(title);

    this.setVisible(true);

  }

 

 // Makes the frame visible and sets the title text

 // and the position of the window.

 

  public void showIt(String title,int x, int y){

    this.setTitle(title);

    this.setLocation(x,y);

    this.setVisible(true);

  }

 

 // Makes the frame invisible.

  public void hideIt(){this.setVisible(false);}

}

 

package its.CounterGUI;

 

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.JLabel;

import java.awt.BorderLayout;

import javax.swing.SwingConstants;

 

public class CounterPanel extends JPanel {

 

  private CounterModel counter;

  private JLabel valueLabel;

 

  public CounterPanel(){

    counter = new CounterModel();

 

    BorderLayout bordLay = new BorderLayout();

    this.setLayout(bordLay);

 

    JButton upButton = new JButton("Up");

    JButton downButton = new JButton("Down");

    valueLabel = new JLabel(""+counter.getValue(),SwingConstants.CENTER);

 

    this.add(upButton,BorderLayout.WEST);

    this.add(downButton,BorderLayout.EAST);

    this.add(valueLabel,BorderLayout.CENTER);

 

 

 //the listener.

  CounterListener countList = new CounterListener(this);

  upButton.addActionListener(countList);

  downButton.addActionListener(countList);

 }

 

  public void increment(){

    counter.increment();

    valueLabel.setText(""+counter.getValue());

  }

 

  public void decrement(){

    counter.decrement();

    valueLabel.setText(""+counter.getValue());

  }

}

 

package its.CounterGUI;

 

public class CounterModel {

  private int value;

 

  // The constructor initializes the counter to 0

  public CounterModel(){value = 0;}

 

  public void increment(){value++;}

 

  public void decrement(){value--;}

 

  public void reset(){value = 0;}

 

  public int getValue(){return(value);}

}

package its.CounterGUI;

 

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

 

public class CounterListener implements ActionListener{

 

private CounterPanel countPane;

 

  public CounterListener(CounterPanel counp) {

    countPane = counp;

  }

 

 // This method is called by the runtime system.

 // The programmer has to add the code to be executed

 // as a response to the event.

  public void actionPerformed(ActionEvent evt){

 

   String actionCommand = evt.getActionCommand();

   if(actionCommand.equals("Up")){

     countPane.increment();

   }

   else if(actionCommand.equals("Down")){

     countPane.decrement();

   }

   else{

     System.out.println("ERROR: Unexpected ActionCommand");

   }

 }

}

 

 

esboço:

 

Diagrama simplificado do livro

An Introduction to Graphical User Interfaces with Java Swing

 

Diagrama relacionado ao mecanismo de desenho (design pattern) observador livro

Professional Java User Interfaces

 

Diagrama simplificado do livro

Professional Java User Interfaces

UML Sequence Diagrams: Reference Visual Studio 2010

http://msdn.microsoft.com/en-us/library/dd409377.aspx
developerWorks > Rational > Technical library >

UML basics: The sequence diagram

http://www.ibm.com/developerworks/rational/library/3101.html

 

Thread estaLinha=Thread.currentThread();

System.out.println(estaLinha);

 

  ThreadGroup raiz =  

 

Thread.currentThread().getThreadGroup().getParent();

  while (raiz.getParent() != null) {

     raiz = raiz.getParent();

  }

  raiz.list();

lista de componentes do Swing

http://download.oracle.com/javase/tutorial/uiswing/components/componentlist.html

 

lista de “listeners” (além do ActionListener...)

http://download.oracle.com/javase/tutorial/uiswing/events/api.html