import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;


public class Vaihda extends JFrame {

    JLabel teksti;
    JButton painike;
    String kylla;
    String ei;

    public Vaihda(String k, String e) {
	super("Vaihda");
	this.kylla = k;
	this.ei = e;
	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
		    System.out.println("Nyt mä lähden pois!");
		    System.exit(0);
		}
	    });
	teksti = new JLabel(kylla, JLabel.CENTER);
	teksti.setForeground(Color.red);
	teksti.setBackground(Color.blue);
	getContentPane().add(teksti, BorderLayout.CENTER);
	painike = new JButton("Vaihda");
	getContentPane().add(painike, BorderLayout.SOUTH);
	
	painike.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    if (teksti.getText().equals(kylla)) {
			teksti.setText(ei); 
		    } else {
			teksti.setText(kylla);
		    }
		    Color tmp = teksti.getForeground();
		    teksti.setForeground(teksti.getBackground());
		    teksti.setBackground(tmp);
		}});

	JLabel kuva = new JLabel(new ImageIcon("mtv3_logo.gif"));
	getContentPane().add(kuva, BorderLayout.NORTH);
	pack();
	show();
    }

    public static void main(String[] args) {
	new Vaihda(args[0], args[1]);
    }

}
