Tô botando um código e tenho algumas dúvidas sobre ele:
import javax.swing.JFrame;
import java.awt.Color;
import javax.swing.JButton;
public class Janela extends JFrame {
private JButton btnOK ;
public Janela() {
//super("Janela Tela");
this.setTitle("Janela Tela");
this.getContentPane().setLayout(null);
this.setSize(340,220);
this.setLocationRelativeTo(null);
this.getContentPane().setBackground(Color.RED);
this.btnOK = new JButton("OK");
btnOK.setBounds(100,100,55,25);
this.getContentPane().add(btnOK);
}
public static void main(String[] args) {
Janela j = new Janela();
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setVisible(true);
}
}
//super("Janela Tela");
this.setTitle("Janela Tela");
Eu sei que esse this ai na frente não precisa pois está implicitamente, mas
ele se refere á quem, à JFrame. à Janela, ou quando ela é instanciada com JFrame J = new Janela(); ?
this.setTitle("Janela Tela");
this.getContentPane();
//this.add(btnOK);
private JLabel l1;
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.btnOK = new JButton("OK");
this.btnOK.addActionListener(this);
Vamos supor que minha Janela esteja implementando um ActionListener,
essa ordem de hierarquia,pois Janela herda de JFrame e implementa ActionListener, quem é pai de quem?
Eu ouvi falar que o this se refere á superclasse,e ntão esses this se referem por exemplo á JFrame?
public void actionPerformed(ActionEvent e){
Object o =e.getSource();
if (e.getSource().equals(btnOK)) {
System.out.println("Chamou....: OK");
new Janela().show();
}
else
if ( o.equals(btnCancel)){
System.out.println("Chamou....: CANCEL");
System.exit(0);
}
}
Eu acho que chega por enquanto! hehehe
Se alguém puder me ajudar, esses pequenos detalhes é que tá pegando.
Valeu!!!