Results 1 to 2 of 2
Thread: help! JPanel....
- 02-22-2011, 10:48 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
help! JPanel....
i don't know what's wrong with my codings, because nothing happens in my applet..... it turns blank.... pls... help....
here's my code
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
public class CurrencyConverter extends Applet implements ActionListener
{
Label header;
Label amountlabel;
TextField amountfield;
Label fromlabel;
Choice fromchoice;
double[] value={1.00000,43.5241,101.830,4.85908,10.1931,298 0.70,29.8823,1.45021,1.45006,5.48783,0.43355,17.96 77,5.52844,11.3770,4.40437,4.85908,1.44881,252.415 ,201.184,117.540,0.58340,1,434.32,0.52105,2.55983, 29.8823,45.3683,0.31801,11.7450,5.85440,2.91617,14 8.510,31,434.3,29.2834,76.4078,22.3162,177.516,123 .253,6.49595,0.97210,1.59249,7.85630,0.62392,76.40 78};
Button calculate;
Label exchangeratelabel;
TextField exchangeratefield;
Label calcamtlabel;
TextField calcamtfield;
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
public void init()
{
setBackground(Color.green);
panel1.setLayout(new FlowLayout(FlowLayout.CENTER));
header = new Label("Currency Conversion Calculator");
header.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel1.add(header);
panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
panel2.setLayout(new GridLayout(2,2));
amountlabel = new Label("Amount of Dollars to be Exchange");
amountlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel2.add(amountlabel);
amountfield = new TextField(15);
amountfield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel2.add(amountfield);
fromlabel = new Label("Convert From:");
fromlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel2.add(fromlabel);
fromchoice = new Choice();
fromlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel2.add(fromchoice);
fromchoice.addItem("United States US Dollar (USD)");
fromchoice.addItem("Philippines Philippine Peso (PHP)");
fromchoice.addItem("Albania Albanian Lek (ALL)");
fromchoice.addItem("Andorra Andorran Franc (ADF)");
fromchoice.addItem("Austria Austrian Schilling (ATS)");
fromchoice.addItem("Belarus Belarusian Ruble (BYR)");
fromchoice.addItem("Belgium Belgian Franc (BEF)");
fromchoice.addItem("Bosnia Bosnia Mark (BAM)");
fromchoice.addItem("Bulagria Bulgarian Lev (BGN)");
fromchoice.addItem("Cyprus Cypriot Pound (CYP)");
fromchoice.addItem("Czech Republic Czech Koruna (CZK)");
fromchoice.addItem("Denmark Danish Krone (DKK)");
fromchoice.addItem("Estonia Estonian Kroon (EEK)");
fromchoice.addItem("Findland Finnish Markka (FIM)");
fromchoice.addItem("Germany German Mark (DEM)");
fromchoice.addItem("Greece Greek Drachma (GRD)");
fromchoice.addItem("Hungary Hungarian Forint (HUF)");
fromchoice.addItem("Iceland Iceland Krona (ISK)");
fromchoice.addItem("Ireland Irish Punt (IEP)");
fromchoice.addItem("Italy Italian Lira (ITL)");
fromchoice.addItem("Latvia Latvian Lats (LVL)");
fromchoice.addItem("Lithuania Lithuanian Litas (LTL)");
fromchoice.addItem("Luxemburg Luxembourg Franc (LUF)");
fromchoice.addItem("Macedonia Macedonian Denar (MKD)");
fromchoice.addItem("Malta Maltese Lira (MTL)");
fromchoice.addItem("Moldova Moldovan Leu (MDL)");
fromchoice.addItem("Norway Norwegian Kroner (NOK)");
fromchoice.addItem("Poland Polish Zloty (PLN)");
fromchoice.addItem("Portugal Portuguese Escudo (PTE)");
fromchoice.addItem("Romania Romanian Lei (ROL)");
fromchoice.addItem("Russia Russian Rouble (RUB)");
fromchoice.addItem("Serbia Serbian Dinar (RSD)");
fromchoice.addItem("Slovakia Slovak Koruna (SKK)");
fromchoice.addItem("Slovenia Slovenian Tolar (SIT)");
fromchoice.addItem("Spain Spanish Peseta (ESP)");
fromchoice.addItem("Sweden Swedish Krona (SEK)");
fromchoice.addItem("Switzerland Swiss Franc (CHF)");
fromchoice.addItem("Turkey Turkish Lira (TRY)");
fromchoice.addItem("Ukraine Ukraine Hryvnia (UAH)");
fromchoice.addItem("United Kingdom British Pound (GBP)");
fromchoice.addItem("Yugoslavia Yugoslav Dinar (YUN)");
panel3.setLayout(new FlowLayout(FlowLayout.CENTER));
calculate = new Button("Calculate");
calculate.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel3.add(calculate);
calculate.addActionListener(this);
panel4.setLayout(new FlowLayout(FlowLayout.CENTER));
panel4.setLayout(new GridLayout(2,2));
exchangeratelabel = new Label("Exchange Rate");
exchangeratelabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel4.add(exchangeratelabel);
exchangeratefield = new TextField(15);
exchangeratefield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel4.add(exchangeratefield);
calcamtlabel = new Label("Calculated Amount");
calcamtlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel4.add(calcamtlabel);
calcamtfield = new TextField(15);
calcamtfield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
panel4.add(calcamtfield);
}
public void actionPerformed(ActionEvent e)
{
double cal,total;
int actval = fromchoice.getSelectedIndex();
total = value[actval];
int af = Integer.parseInt(amountfield.getText());
cal=af*total;
exchangeratefield.setText(""+total);
calcamtfield.setText(""+cal);
}
}
-
Were do you add any components to the JApplet itself, or more accurately, its contentPane?
Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Much luck!Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
Similar Threads
-
Jpanel in
By archanaanbu in forum Java AppletsReplies: 1Last Post: 02-11-2011, 05:10 PM -
Placing a new JPanel over a paint overriden JPanel
By Tanshaydar in forum AWT / SwingReplies: 4Last Post: 12-08-2010, 06:00 PM -
Need to Save a data to file from JPanel and read the data back to Jpanel
By yashrajsen in forum AWT / SwingReplies: 1Last Post: 11-09-2010, 09:28 AM -
.add to a JPanel
By harrier in forum NetBeansReplies: 11Last Post: 07-13-2010, 10:24 AM -
I need some help with JPanel
By bantes in forum AWT / SwingReplies: 7Last Post: 11-03-2009, 07:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks