Kalkulator - sposób na skrócenie drabinki ifów

0

Pytanie czy można to w jakiś inny(krótszy) prosty sposób zapisać ?

 
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("1")){
			line += "1";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("2"))
		{
			line += "2";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("2"))
		{
			line += "2";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("3"))
		{
			line += "3";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("4"))
		{
			line += "4";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("5"))
		{
			line += "5";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("6"))
		{
			line += "6";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("7"))
		{
			line += "7";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("8"))
		{
			line += "8";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("9"))
		{
			line += "9";
			jtfField.setText(line);
		}
		else if(e.getActionCommand().equals("0"))
		{
			line += "0";
			jtfField.setText(line);
		}
	}
1

A nie dałoby się:

line += e.getActionCommand();
jtfField.setText(line);

? o_O

Z takim copy-paste skillem to nie wróżę ci kariery programisty...

1 użytkowników online, w tym zalogowanych: 0, gości: 1