Why does this work.
But this not?
I can't understand it. To me they seem exactly the same.
Code:
import javax.swing.*;
import java.awt.*;
public class SolarSystemGUI extends JFrame {
JPanel mypanel = new JPanel();
JLabel label = new JLabel();
JLabel label2 = new JLabel();
FlowLayout layout = new FlowLayout();
public SolarSystemGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setContentPane(mypanel);
label.setText("Solar System controller:");
label2.setText("Author: ");
mypanel.add(label);
mypanel.add(label2);
mypanel.setLayout(layout);
this.pack();
this.setLocation(250, 250);
this.setSize(500, 300);
this.setTitle("Solar System v1.0");
this.setVisible(true);
}
}
But this not?
Code:
import javax.swing.*;
import java.awt.*;
public class SolarSystemGUI extends JFrame {
JPanel mypanel = new JPanel();
JLabel label = new JLabel();
JLabel label2 = new JLabel();
FlowLayout layout = new FlowLayout();
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setContentPane(mypanel);
label.setText("Solar System controller:");
label2.setText("Author: ");
mypanel.add(label);
mypanel.add(label2);
mypanel.setLayout(layout);
this.pack();
this.setLocation(250, 250);
this.setSize(500, 300);
this.setTitle("Solar System v1.0");
this.setVisible(true);
}
I can't understand it. To me they seem exactly the same.
Last edited:
I have to wonder why the people who created java don't allow you to just use \n.
Luckily the Java Course has finished for this year, so there's nothing more to learn.