Kamis, 08 Maret 2012

Simple project with SWT and Swing :)

            Program SWT:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
 
public class HelloWorld 
{
   public static void main (String[] args) 
  {
      Display display = new Display();
      Shell shell = new Shell(display);
      Label label = new Label(shell, SWT.NONE);
      label.setText("Hello World");
      label.pack();
      shell.pack();
      shell.open();
      while (!shell.isDisposed()) 
      {
         if (!display.readAndDispatch()) display.sleep();
      }
      display.dispose();
   }
}
            Program Swing:
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
 
public class SwingExample implements Runnable {
    @Override
    public void run() {
        // Create the window
        JFrame f = new JFrame ("Hello, World!");
        // Sets the behaviour for when the window is closed
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // add a label and a button
        f.getContentPane().add(new JLabel("Hello, world!"));
        f.getContentPane().add(new JButton("Press me!"));
        // arrange the components inside the window
        f.pack();
        //By default, the window is not visible. Make it visible.
        f.setVisible(true);
    }
 
    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(se);
    }
}       

Tidak ada komentar:

Posting Komentar