Swing (Java): Difference between revisions

Content deleted Content added
Exoad (talk | contribs)
fix the incoherent descriptive nature of the hello world example code snippet
Exoad (talk | contribs)
m fix bad code examples for swing especially by putting everything in a run() instead of a init constructor
Line 138:
public class SwingExample implements Runnable {
 
public void runSwingExample() {
@Override
public void run() {
// Create the window
JFrame f = new JFrame("Hello, !");
Line 148 ⟶ 147:
// Add a label and a button
f.add(new JLabel("Hello, world!"));
f.add(new JButton("Press me!"));
}
 
@Override
public void run() {
// Arrange the components inside the window
f.pack();
Line 156 ⟶ 159:
public static void main(String[] args) {
SwingExample se = new SwingExample();
// Schedules the application to be run at the correct time in the event queue.
SwingUtilities.invokeLater(senew SwingExample());
}