Witam, mam mały problem. Tworzę okienko w swingu z polami uztykownik i hasło takie do logowania oraz 2 przyciski. Chodzi o to, żeby jak kliknę przycisk Zaloguj to pojawiła się nowa etykieta w bieżącym oknie. Próbuję to zrobić w actionPerformed dla przycisku Zaloguj ale nie widać żadnej reakcji :/
nie dziala ani sposób " frame.getContentPane().add(new JLabel("blee"), a nie też
"SwingUtilities.invokeLater(new Runnable(){
public void run(){
jakies operacja na frame
Moj kod :
import javax.swing.*;
import java.util.concurrent.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Start implements ActionListener{
private Socket socket=null;
private static JFrame frame;
private static Start obiekt;
private JTextField user,pass;
SpringLayout layout=new SpringLayout();
public void logowanie() {
JFrame.setDefaultLookAndFeelDecorated(false);
user=new JTextField(10);
pass=new JTextField(10);
JLabel userLabel=new JLabel("Użytkownik");
JLabel passLabel=new JLabel("Hasło");
JButton zalogujB=new JButton("Zaloguj");
JButton anulujB=new JButton("Anuluj");
Color tlo=new Color(200,228,237);
frame=new JFrame("prog");
frame.setSize(360, 150);
frame.setLocationRelativeTo(null);
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(tlo);
frame.setLayout(layout);
frame.setMinimumSize(new Dimension(300,100));
user.setBackground(tlo);
pass.setBackground(tlo);
Container content=frame.getContentPane();
String lewo=SpringLayout.WEST;
String prawo=SpringLayout.EAST;
String gora=SpringLayout.NORTH;
String dol=SpringLayout.SOUTH;
layout.putConstraint(lewo, userLabel,20,lewo, content);
layout.putConstraint(gora, userLabel, 20, gora, content);
layout.putConstraint(gora, passLabel, 10, dol, userLabel);
layout.putConstraint(prawo, passLabel, 0, prawo, userLabel);
layout.putConstraint(lewo, user, 10, prawo, userLabel);
layout.putConstraint(lewo, pass, 10, prawo, passLabel);
layout.putConstraint(gora, user, 0, gora, userLabel);
layout.putConstraint(gora, pass, 0, gora, passLabel);
layout.putConstraint(prawo, anulujB, -10, prawo, content);
layout.putConstraint(dol, anulujB, -6, dol, content);
layout.putConstraint(prawo, zalogujB, -10, lewo, anulujB);
layout.putConstraint(gora, zalogujB, 0, gora,anulujB );
user.setBorder(BorderFactory.createLineBorder(tlo.darker()));
pass.setBorder(BorderFactory.createLineBorder(tlo.darker()));
frame.getContentPane().add(userLabel);
frame.getContentPane().add(passLabel);
frame.getContentPane().add(user);
frame.getContentPane().add(pass);
frame.getContentPane().add(anulujB);
frame.getContentPane().add(zalogujB);
frame.setVisible(true);
anulujB.setActionCommand("anuluj");
zalogujB.setActionCommand("zaloguj");
anulujB.addActionListener(this);
zalogujB.addActionListener(this);
}
public static void main(String[] args) throws Exception{
obiekt=new Start();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
obiekt.logowanie();
}
});
System.out.println("jestem w mainie !");
}
public void actionPerformed(ActionEvent e) {
String komenda =e.getActionCommand();
if(komenda=="anuluj") {
System.exit(0);
}
else if(komenda=="zaloguj") {
try {
********* tutaj chcialbym wstawic etykietke np "trwa laczenie" .... **************
TimeUnit.SECONDS.sleep(3);
socket =Conection.polacz(user.getText(),pass.getText());
if(socket!=null)System.out.println("polaczono z powodzeniem");
else System.out.println("polaczenie nieudane");
}
catch(Exception ee) {
System.out.println(ee.getMessage());
}
}
}
}