Results 1 to 1 of 1
  1. #1
    eiramae is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Question pls... help.... alignment....

    how to center the button "Calculate" and align the Label and TextField......... pls... help....
    here's my code

    Java 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,2980.70,29.8823,1.45021,1.45006,5.48783,0.43355,17.9677,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,148.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.4078};
    
    	Button calculate;
    
    	Label exchangeratelabel;
    	 TextField exchangeratefield;
    
    	Label calcamtlabel;
    	 TextField calcamtfield;
    
    
    	public void init()
    	{
    	setLayout(new FlowLayout(FlowLayout.CENTER));
    	setBackground(Color.green);
    
    	header = new Label("Currency Conversion Calculator");
    	header.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(header);
    
    
    	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));
    	add(amountlabel);
    
    	amountfield = new TextField(15);
    	amountfield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(amountfield);
    		
    	fromlabel = new Label("Convert From:");
    	fromlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(fromlabel);
    
    	fromchoice = new Choice();
    	fromlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	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)");
    
    	calculate = new Button("Calculate");
    	calculate.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(calculate);
    	calculate.addActionListener(this);
    
    	exchangeratelabel = new Label("Exchange Rate");
    	exchangeratelabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(exchangeratelabel);
    
    	exchangeratefield = new TextField(15);
    	exchangeratefield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	add(exchangeratefield);
    
    	calcamtlabel = new Label("Calculated Amount");
    	calcamtlabel.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));	
    	add(calcamtlabel);
    
    	calcamtfield = new TextField(15);
    	calcamtfield.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 12));
    	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);
    		
    
    	}
    }
    Attached Thumbnails Attached Thumbnails pls... help.... alignment....-output2.jpg  

Similar Threads

  1. Alignment in GridLayout
    By Zamereon in forum AWT / Swing
    Replies: 2
    Last Post: 02-27-2011, 12:49 PM
  2. Help with alignment
    By firecat318 in forum AWT / Swing
    Replies: 3
    Last Post: 05-25-2010, 04:01 AM
  3. Alignment using BoxLayout
    By tiptoe in forum AWT / Swing
    Replies: 4
    Last Post: 01-23-2010, 08:15 PM
  4. Label Alignment Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:49 PM
  5. alignment of textfield in awt
    By nitinborge5 in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 12:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •