/*
"What are AWT and Swing used for?"
the two GUI (Graphical User Interface) packages that provide good libraries!
Swing > AWT, but Swing is based on AWT so we need to call AWT anyways.
-> bc Swing has more stuff + isn't OS-based so it looks same on both Windows and Mac
cannot mix-use Swing and AWT components (buttons, windows, panels, labels, etc)
* try to avoid using the Main method to create panels, pls make a new frame class
* "frame class"
* public class nameOfClass extends JFrame { public nameOfClass() {constructor stuff} }
* Containers: JFrame, JPanel
* Components: JButton, JLabel
*/
import java.awt.*;
// AWT (Abstract Windowing Toolkit) = heavy weight components based on OS
import javax.swing.*;
// Swing = light weight components not based on OS
// components start with J (JButton, JWindows) to not confuse with AWS
public class Main extends JFrame{
// parent function is JFrame, meaning Main will take on everything JFrame alr has.
// Main can also be called anything else.
/* 1. Container name (c) = getContentPane(); <- creates a panel
* 2. call on name (c) and use different set methods
* 3. JButton name (btn) = new JButton();
* 4. call on name (btn) and use different set methods
* 5. now show your artwork!! {setTitle("--"), setSize(00, 00), setVisible(true)}
*/
Main(){
// constructor for the Class named Main
super();
// the command for making a new frame!
Container c = getContentPane();
// Three parts to a JFrame: Menu Bar, Content Pane, Frame
// Content Panes are created with a JFrame, and are Container types
c.setLayout(new GridLayout());
c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout());
JButton btn = new JButton("ok");
btn.setBackground(Color.red);
btn.setForeground(Color.white);
// btn.setSize(200, 300); <= usable only for FlowLayout
JLabel la = new JLabel("HELLO");
c.add(btn);
c.add(la);
c.add(new JButton("cancel"));
setSize(500, 300);
setVisible(true);
}
public static void main(String[] args) {
new Main();
// java only uses Main method!! call on Main() the constructor.
}
}
// A REVIEW OF INHERITANCE!!!
//class A{
// public A() {
// System.out.println("con A");
// }
//}
//
//class B extends A{
// public B() {
// super();
// System.out.println("con B");
// }
//}
//
//class Main{
// public static void main(String[] args) {
// B obj = new B();
// }
//}
"Top Level Container = 최상위 컨테이너"
JFrame, JDialog, JApplet
= can be displayed on screen while not being attached to another container/component!