55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JList;
|
|
import javax.swing.SwingUtilities;
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args) {
|
|
List<Lavoratore> lavoratori = new ArrayList<>();
|
|
lavoratori.add(new Lavoratore("Marco", "Rossi"));
|
|
lavoratori.add(new Lavoratore("Laura", "Bianchi"));
|
|
lavoratori.add(new Lavoratore("Alessandro", "Verdi"));
|
|
lavoratori.add(new Lavoratore("Francesco", "Esposito"));
|
|
lavoratori.add(new Lavoratore("Luca", "Romano"));
|
|
|
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
|
JFrame frame = new JFrame("Ciso mondo");
|
|
|
|
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS));
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
List<String> nomi = new ArrayList<>();
|
|
|
|
for(Lavoratore lavoratore : lavoratori) {
|
|
nomi.add(lavoratore.nome + " " + lavoratore.cognome);
|
|
}
|
|
|
|
JList<String> lista = new JList<>(nomi.toArray(new String[0]));
|
|
frame.add(lista);
|
|
|
|
|
|
|
|
frame.setSize(400, 400);
|
|
frame.setVisible(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
public static class Lavoratore {
|
|
public String nome;
|
|
public String cognome;
|
|
|
|
public Lavoratore(String nome, String cognome) {
|
|
this.nome = nome;
|
|
this.cognome = cognome;
|
|
}
|
|
}
|
|
}
|