Technology Programming

How to Get an Image in Java

    • 1). Open your Java software and allow the program to fully load. Enter the following code into the area above where you want the image to appear:

      public Image getImage()
      public void setImage(Image image)

    • 2). Enter the following code into the area below where you want the image to appear on the page:

      import org.eclipse.swt.SWT;
      import org.eclipse.swt.layout.FillLayout;
      import org.eclipse.swt.widgets.Button;
      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Shell;

      public class ButtonImageAdd {

      public static void main(String[] args) {
      final Display display = new Display();
      Shell shell = new Shell(display);

      shell.setLayout(new FillLayout());

    • 3). Enter in the file name of the image you want to add to the web page in place of "your.File.gif" in the code listed below:

      Image image = new Image(display, "yourFile.gif");

    • 4). Enter in the remainder of the code for the image to appear on-screen as follows:

      Button button = new Button(shell, SWT.PUSH);

      while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {

Leave a reply