|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Jun 2010
Messaggi: 22
|
[JAVA] Diversità in swing...
Ciao a tutti.
Studiando swing, e leggendo guide diverse, mi sono accorto che c'è della differenza di programmazione. Uno, quello che c'è sul tutorial della oracle: Codice:
import javax.swing.*; public class HelloWorldSwing { private static void createAndShowGUI() { JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);. JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } Questo: (PARTE DI CODICE!) Codice:
public class Main extends JFrame { public Main() { super("Ciao"); this.getContentPane().setLayout(new GridLayout(2,1)); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } E quello che uso io: Codice:
import javax.swing.*; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("Ciao Forum!!!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("CIao a tutti!"); frame.getContentPane().add(label); frame.pack(); frame.setSize(300, 400); frame.setVisible(true); } }
|
![]() |
![]() |
![]() |
#2 | |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 691
|
Quote:
//Schedule a job for the event-dispatching thread: 1) TUTTI i componenti swing devono essere creati, acceduti etc dal solo event-dispatching thread, creato da javax.swing.SwingUtilities.invokeLater(new Runnable() nel tuo caso. E' un errore interagire con componenti dell'ui al di fuori dell event dispatching thread. 2) forse meno intuitivo, ma è il solo corretto. 3) il terzo, perchè evita freeze della gui se un task non è istantaneo etc ![]() |
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
@Hack4life: devi usare/studiare Swing?
Lo vuoi un tutorial in italiano, breve, facile da leggere che al contempo copre bene tutte le basi e pure gratis, in formato pdf con tanto di segnalibri? Lo trovi qua: Guida Rapida a Swing E ovviamente spiega bene anche quello che hai chiesto qui, propio nelle prime 4 pagine, se mi ricordo bene ![]()
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Apr 2010
Città: Frosinone
Messaggi: 416
|
comunque sul tutorial oracle c'è anche scritto un po' ovunque che l'uso di edt è l'unico modo thread safe di usare i componenti swing
su swing non c'è così tanto da dire da spenderci per comprare un libro a riguardo onestamente, e swt è pure più cool |
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Comunque, e parlo per esperienza diretta, su Swing forse non c'è tanto da dire, ma c'è "tanta roba": il libro, imprescindibile per chi volesse veramente imparare ad usare, non dico in maniera approfondita, ma almeno con completa cognizione di causa questo framework in tutte le sue parti consta di 1000 paginozze, supergiù, e non perchè gli autori sono incapaci di sintesi. Parlo ovviamente di "Java Swing", seconda edizione, O'Really. Mi interessa comunque molto la tua opinione su SWT, se hai avuto esperienza diretta di questo framework.
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Apr 2010
Città: Frosinone
Messaggi: 416
|
no no, nessun motivo particolare
![]() |
![]() |
![]() |
![]() |
#7 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Però per quanto riguarda il libro, credimi: anche se la documentazione è abbastanza esaustiva, lo è solo in forma appunto di documentazione. Se uno volesse approfondire e vedere bene tutto, il libro è davvero imprescidinbile.
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:54.