Constructor call not calling
I am trying to call a constructor for a self-designed class. However, when I use new TextAreaUI, nothing happens. The println statement at the beginning of the constructor does not work either... any ideas?
TextAreaUI class:
Code:
import javax.swing.*;
import java.awt.event.*;
public class TextAreaUI extends JPanel implements ActionListener{
private static final long serialVersionUID = 1L;
private ScrollableJTextArea allMessages = new ScrollableJTextArea(), newMessages = new ScrollableJTextArea();
private JButton send = new JButton("Send");
public TextAreaUI(){
[color=red][b]System.out.println("TAUI construct");[/b]//Never prints[/color]
setLayout(new SpringLayout());
System.out.println("Layout");
JPanel bottomPanel = new JPanel(new SpringLayout());
bottomPanel.add(newMessages);
bottomPanel.add(send);
System.out.println("BPanel");
SpringUtilities.makeCompactGrid(bottomPanel, 1, 2, 0, 0, 0, 0);
JPanel topPanel = new JPanel();
topPanel.add(allMessages);
add(topPanel);
add(bottomPanel);
System.out.println("Added");
SpringUtilities.makeCompactGrid(this, 2, 1, 4, 4, 4, 4);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == send){
if(newMessages.getText().length() != 0){
allMessages.append("\n\n"+newMessages.getText());
newMessages.setText("");
}
}
}
}
The class calling the constructor
Code:
import javax.swing.*;
import graphics.images.Movement;
public class MainUI extends JFrame{
private static final long serialVersionUID = 1L;
private JPanel panel = new JPanel();
public MainUI(){
System.out.println("Checkpoint: Constructor call");
TextAreaUI txtPanel;
System.out.println("Checkpoint: txtPanel allocated");
[b][color=red]txtPanel = new TextAreaUI();[/color][/b][color=red]//BLOCKS[/color]
System.out.println("Checkpoint: txtPanel initialized");
panel.add(txtPanel);
System.out.println("Checkpoint: panel setup");
setContentPane(panel);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args){
new MainUI();
}
}
Seems to be a very strange problem. Never seen anything like this.