The Student Room Group

Applet help in creating a currency converter plsss

hello so i'm having a hard time with applets at the moment and don't know how to do this problem, the question is

Produce an applet that includes three JTextFields and three JLabels and a JButton The labels should state ‘Euros input’, ‘Stirling input’ and ‘currency conversion’. The JButton should read either of the JTextFields, provide the appropriate conversion and out put the results as Euro or £ Stirling.

we are told to use the program bluej to create the program, as it has a template with it, here is the template:

import java.awt.*;
import javax.swing.*;

/**
* Class example - write a description of the class here
*
* @author (your name)
* @version (a version number)
*/
public class example extends JApplet
{
// instance variables - replace the example below with your own
private int x;

/**
* Called by the browser or applet viewer to inform this JApplet that it
* has been loaded into the system. It is always called before the first
* time that the start method is called.
*/
public void init()
{
// this is a workaround for a security conflict with some browsers
// including some versions of Netscape & Internet Explorer which do
// not allow access to the AWT system event queue which JApplets do
// on startup to check access. May not be necessary with your browser.
JRootPane rootPane = this.getRootPane();
rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

// provide any initialisation necessary for your JApplet
}

/**
* Called by the browser or applet viewer to inform this JApplet that it
* should start its execution. It is called after the init method and
* each time the JApplet is revisited in a Web page.
*/
public void start()
{
// provide any code requred to run each time
// web page is visited
}

/**
* Called by the browser or applet viewer to inform this JApplet that
* it should stop its execution. It is called when the Web page that
* contains this JApplet has been replaced by another page, and also
* just before the JApplet is to be destroyed.
*/
public void stop()
{
// provide any code that needs to be run when page
// is replaced by another page or before JApplet is destroyed
}

/**
* Paint method for applet.
*
* @param g the Graphics object for this applet
*/
public void paint(Graphics g)
{
// simple text displayed on applet
g.setColor(Color.white);
g.fillRect(0, 0, 200, 100);
g.setColor(Color.black);
g.drawString("Sample Applet", 20, 20);
g.setColor(Color.blue);
g.drawString("created by BlueJ", 20, 40);
}

/**
* Called by the browser or applet viewer to inform this JApplet that it
* is being reclaimed and that it should destroy any resources that it
* has allocated. The stop method will always be called before destroy.
*/
public void destroy()
{
// provide code to be run when JApplet is about to be destroyed.
}


/**
* Returns information about this applet.
* An applet should override this method to return a String containing
* information about the author, version, and copyright of the JApplet.
*
* @return a String representation of information about this JApplet
*/
public String getAppletInfo()
{
// provide information about the applet
return "Title: \nAuthor: \nA simple applet example description. ";
}


/**
* Returns parameter information about this JApplet.
* Returns information about the parameters than are understood by this JApplet.
* An applet should override this method to return an array of Strings
* describing these parameters.
* Each element of the array should be a set of three Strings containing
* the name, the type, and a description.
*
* @return a String[] representation of parameter information about this JApplet
*/
public String[][] getParameterInfo()
{
// provide parameter information about the applet
String paramInfo[][] = {
{"firstParameter", "1-10", "description of first parameter"},
{"status", "boolean", "description of second parameter"},
{"images", "url", "description of third parameter"}
};
return paramInfo;
}
}


the thing is i have a hard time starting since i don't know what to include, and im pretty sure i don't need all the stuff used on the template.


so far after trying for a while i got up to this part,

import java.awt.*;
import javax.swing.*;
import javax.swing.JApplet;
public class exercise1 extends JApplet
{
// instance variables - replace the example below with your own
private JFrame aFrame;
private JTextField aText1;
private JTextField aText2;
private JTextField aText3;
private JLabel aLabel1;
private Jlabel aLabel2;
private JLabel aLabel3;
private JButton aButton;
private Container con;

/**
* Called by the browser or applet viewer to inform this JApplet that it
* has been loaded into the system. It is always called before the first
* time that the start method is called.
*/
public void init()
{
container = this.getContainerPane();
container.SetLayout(new FlowLayout)();
aLabel1 = new JLabel("EUROS");
aLabel2 = new JLabel("POUNDS");
aLabel3 = new JLabel(Conversion");
aText1 = new JTextField(10);
aText2 = new JTextField(10);
aText3 = new JTextField(10);
aButton = new Jbutton("Convert amount")
aButton1.addActionListener(new ActionListener)();

}


but im not sure if its right
Reply 1
any help?? seriously need some ... :frown:

Quick Reply

Latest

Trending

Trending