View Single Post
Old 23-02-2005, 22:58   #1
StErMiNeiToR
Bannato
 
L'Avatar di StErMiNeiToR
 
Iscritto dal: Jul 2002
Città: Lucca
Messaggi: 966
[Java] Entra in un if dove non dovrebbe entrare -.-'

Codice:
import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

/*
 * 
 *  Program created and coded by `StErMi
 *  www.tdoportal.it
 *  mail: [email protected]
 *  for bugs or info contact me.
 * 
 * 
 */

public class interfaccia extends Frame implements ActionListener
{
	int valuta = 0;
	JTextField importo = new JTextField("");
	JLabel conv = new JLabel("");
	JFrame f = new JFrame("Euro Convertitore");
	JPanel p = new JPanel();
	JPanel p2 = new JPanel();
	JRadioButton euro = new JRadioButton("€");
	JRadioButton lire = new JRadioButton("£");
	JButton converti = new JButton("Converti");
	JButton riavvia = new JButton ("Riavvia");
	ButtonGroup group = new ButtonGroup();
	
	
	public interfaccia()
	{
		group.add(euro);
		group.add(lire);
		
		
		
		// setto i layout
		f.setLayout(new BorderLayout());
		f.setSize(250,250);
		p.setLayout(new GridLayout(4,2,10,10));
		f.getContentPane().add(p, "West");
		
		// aggiungo gli oggetti
		p.add( new JLabel("Importo: "));
		p.add(importo);
		p.add(euro);
		p.add(lire);
		p.add(converti);
		p.add(riavvia);
		p.add( new JLabel("Convertito: "));
		p.add(conv);

		// azioni -> bottone
		converti.addActionListener(this);
		euro.addActionListener(this);
		lire.addActionListener(this);
		riavvia.addActionListener(this);
		
		// proprietà finistra
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
	}

	public static void main(String[] args) throws IOException
	{
		interfaccia main = new interfaccia();
		
	}
	public void	actionPerformed (ActionEvent e  )
	{
		double val = 0;
		String v = "";
		String bottone = "";
		bottone = e.getActionCommand();
		
		if ( euro.isSelected() ); {
			valuta = 2;
		}
		
		if ( lire.isSelected()) {
			valuta = 1;
		}
		if ( !( euro.isSelected() ) && !( lire.isSelected() ) ) {
			conv.setText("Scegli una valuta");
			valuta = 0;
		}
		if  ( bottone.equals("Converti") ) {
			if ( ( valuta != 0 ) && ( importo.getText() != "" ) ) {
			v = importo.getText();
			val = Integer.parseInt(v);
			if ( valuta == 1 ) {
				val *= 1936.27;
				conv.setText( "" + val + " £" );
			} else if ( valuta == 2 ) {
				val /= 1936.27;
				conv.setText( "" + val + " €" );
			}
		}
		}
		
		if ( bottone.equals("Riavvia") ) {
			conv.setText("");
			importo.setText("");
		}
	}
}
Come mai entra qua? if ( ( valuta != 0 ) && ( importo.getText() != "" ) )

provate a non immettere nulla nella casella, a selezionare euro o lire e poi a convertire
StErMiNeiToR è offline   Rispondi citando il messaggio o parte di esso