tutti le classi di Swing derivano da Component, e a un Component puoi attaccarci un MouseListener... ergo, puoi usare una JLabel
Per esempio:
codice:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Andrea
*/
public class ClickMeJLabel extends JFrame {
private class MyJLabel extends JLabel {
private final String label;
public MyJLabel(String lab) {
super(lab);
this.label = lab;
this.addMouseListener(new MouseAdapter() {
public void mouseClicked (MouseEvent me) {
System.out.println(label);
}
});
}
}
/** Creates a new instance of ClickMeJLabel */
public ClickMeJLabel() {
super("Test JLabel con Click");
this.getContentPane().setLayout(new GridLayout(2,1));
this.getContentPane().add(new MyJLabel("Cazzone uno"));
this.getContentPane().add(new MyJLabel("Cazzone due"));
this.setSize(200,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args) {
new ClickMeJLabel();
}
}
che dovrebbe stamparti l'etichetta della JLabel
Per l'altra domanda: exec di Runtime!?