Showing posts with label applet. Show all posts
Showing posts with label applet. 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.



Sunday, December 22, 2013

How to Create a Basic Java Applet in Eclipse

Creating an Applet in eclipse does not need any HTML code in extra. Eclipse serves for this type of services to create and play a applet in eclipse.
To create an Applet we basically need two packages i.e.
java.applet.*; 
java.awt.*;
This above packages are imported into the Program.

Friday, January 11, 2013

EXECUTE COMMAND’S AND APPLICATION IN APPLET THROUGH SYSTEM CALL


Some time it’s become very difficult to access any application or to execute commands in java applet. And many of us don’t know how to do this, so I am going to explain how to access or execute any command in Applet. Consider the following program, when you execute it, it will directly open a Firefox application, and you can also replace it with any commands of Linux or windows.

import java.awt.*;                                                              // Packages
import java.io.IOException;
import java.io.InputStream.*;
import java.awt.event.*;
import java.applet.*;
public class Firefox extends Applet
{
            String command="firefox";
   public void init()
   {
              // Construct the button
                  Button browser = new Button("Browser");
             // add the button to the layout
                 this.add(browser);
             // specify that action events sent by this
                   browser.addActionListener(new BeepAction());
              try
             {
                        Runtime.getRuntime().exec(command);
             }
              catch (IOException e)
             {
                        e.printStackTrace();
             }
      }
}

If you don’t have any idea about Applet programming then just follow the following link and just downloads PDF files as per your requirement.

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.
Prints the throwable and the throwable’s call trace. The call stack shows the sequence of method calls that brought you to the point at which exception was thrown.

The first version prints to standard error, the second prints to a stream of your choice. If you’re working under Windows, you can’t redirect standard error so you might want to use the second version and send the results to System.out; that way the output can be redirected any way you want.