Chciałbym, żeby pola tekstowe Field i Area zamieniały się po kliknięciu w button. Co robię źle?
public class Main extends JFrame implements ActionListener
{
private static JTextField poleField;
private static JTextArea poleArea;
private JButton przycisk_ZmienPola;
static int stan;
public Main()
{
setSize(1000,600);
setTitle("Testy_3");
setLayout(null);
poleField = new JTextField("");
poleField.setBounds(100,80,40,40);
poleField.setBackground(Color.BLUE);
add(poleField);
poleArea = new JTextArea("");
poleArea.setBounds(100,80,40,40);
poleArea.setBackground(Color.RED);
add(poleArea);
przycisk_ZmienPola = new JButton ("ZMIEŃ POLA");
przycisk_ZmienPola.setBounds(250,80,120,50);
add(przycisk_ZmienPola);
przycisk_ZmienPola.addActionListener(this);
}
public static void main(String args[])
{
Main aplikacja = new Main();
aplikacja.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
aplikacja.setExtendedState(JFrame.MAXIMIZED_BOTH);
aplikacja.setVisible(true);
stan = 0;
if (stan == 0)
{
poleField.setVisible(true);
poleArea.setVisible(false);
}
else if (stan == 1)
{
poleField.setVisible(false);
poleArea.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == przycisk_ZmienPola)
{
if (stan == 0)
stan = 1;
else if (stan == 1)
stan = 0;
}
}
public JButton getprzycisk_ZmienPola()
{
return przycisk_ZmienPola;
}
public void setprzycisk_ZmienPola(JButton przycisk_ZmienPola)
{
this.przycisk_ZmienPola= przycisk_ZmienPola;
}
}