How to Get an Image in Java
Java software is a tool available to web developers that allows users to create customize, detailed web pages for viewing on the Internet. Adding images will increase the aesthetic appeal of your website and encourage viewers to come back multiple times. Adding an image using your Java software is a fairly straightforward and quick process.
Instructions
-
-
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.graphics.Image;
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);
button.setImage(image);
button.setText("button");shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
-
1