Showing posts with label JPanel. Show all posts
Showing posts with label JPanel. Show all posts

Sunday, March 16, 2014

How to change image on JPanel on action Command button

Welcome to itsitrc blogspot .

This article is for Java Applet .


Problem :



How to change image on JPanel on action Command button ?


Answer :



To satisfy this output we have step by step code described below.
To carry out this code you need to save images in your bin folder inside your workspace and just for example you need have .jpg extension images.
Save it as :
"1.jpg ",  "2jpg" ... so on just for testing issue....!

Tuesday, March 11, 2014

How to set Image to JPanel in java

How to set image in JPanel or Panel in java Applet using Eclipse



For carrying out the most simplest way to add image in a JPanel in java applet follow the below steps :

1.Save the Image in bin folder, where your Project is stored in Workspace.

2.Confirm and check the exact type of Image file for Example it can be .jpg or .jpeg or so on...

3.Open your notepad or if you're using java eclipse or any other java working environment.

4.You need to include basic two packages i.e."  java.awt.*;  " and " javax.swing.*; ".

5.extend the JApplet class to get the GUI.

6.You need to declare, initialize and add JLabel. Here JLabel will contain image and this JLabel will be added to a JPanel. Now here JPanel is initialized and added to a container , which is on JApplet.