Reputation:
Here is my code. I have tried to keep it very simple.
public class GUI_ADV extends JFrame {
public static void main(String[] args) {
NewClass abc = new NewClass();
abc.setLayout(new FlowLayout());
abc.setSize(250,450);
abc.setDefaultCloseOperation(EXIT_ON_CLOSE);
abc.setVisible(true);
}
}
And the other class:
public class NewClass extends JFrame {
public void NewClass() {
JPanel cp = new JPanel();
JTextArea ta = new JTextArea("text",5, 20);
JScrollPane jp = new JScrollPane( ta );
cp.add( jp );
//message.setLineWrap(true);
//message.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(ta,5,5);
//setLayout(new FlowLayout());
//because it is done in main class
cp.add(scroll);
add(cp);
//setVisible(true);
//Its done in main class
}
}
It is not working. It comes blank with the title bar and the empty window.
Upvotes: 1
Views: 54
Reputation: 60045
The constructor should not be void or return any thing, else it will be considered like a method and not a constructor :
public void NewClass() {
// ^^-------------------------mistake
Instead you have to use:
public NewClass() {
Upvotes: 2