I find this weird, since I was just following a tutorial and his worked fine. We have the same exact code..
I tried this source code on another computer but still didn't work.
main class:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class swingJava {
public static void main(String[] args){
JFrame frame = new JFrame("Hello World!");
SwingUtilities.invokeLater(new Runnable() {
public void run(){
frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
Here's the mainframe class.
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class MainFrame extends JFrame{
public MainFrame(String title){
super(title);
// Set layout manager
setLayout(new BorderLayout());
// Create Swing Component
JTextArea textArea = new JTextArea("test");
JButton button = new JButton("Click me");
// Add Swing Componenents to content pane
Container c = getContentPane();
c.add(textArea, BorderLayout.CENTER);
c.add(button, BorderLayout.SOUTH);
}
}
Here's the tutorial I followed https://www.youtube.com/watch?v=svM0SBFqp4s