Hack4life
09-08-2010, 09:06
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:
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();
}
});
}
}
(non capisco perchè usa runnable...)
Questo: (PARTE DI 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:
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);
}
}
Perchè il codice del tutorial dell' Oracle usa Runnable?
Non credete che il secondo sia piuttosto scomodo?
Secondo voi qual' è quello meglio strutturato?
Ah, oggi vado ad ordinare questo (http://www.librinformatica.it/4147-java---sviluppare-applicazioni-grafiche-e-programmare-in-rete-9788820339081.html) cosa ne pensate?
Spiega bene le swing?
In quale di questi modi più o meno?
Grazie!
Studiando swing, e leggendo guide diverse, mi sono accorto che c'è della differenza di programmazione.
Uno, quello che c'è sul tutorial della oracle:
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();
}
});
}
}
(non capisco perchè usa runnable...)
Questo: (PARTE DI 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:
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);
}
}
Perchè il codice del tutorial dell' Oracle usa Runnable?
Non credete che il secondo sia piuttosto scomodo?
Secondo voi qual' è quello meglio strutturato?
Ah, oggi vado ad ordinare questo (http://www.librinformatica.it/4147-java---sviluppare-applicazioni-grafiche-e-programmare-in-rete-9788820339081.html) cosa ne pensate?
Spiega bene le swing?
In quale di questi modi più o meno?
Grazie!