"κ°μ ν: λͺ
ν JAVAESSENTIAL(ν©κΈ°ν)"κ΅μ¬μ μλ‘λ λ¬Έμ λ€μ νμ΄μ μ¬λ¦½λλ€. λ¬Έμ μ λ²νΈλ§ νκΈ°νκ³ λ΅μλ§ μ λ ννλ‘ μ λ‘λ νκ³ μμ΅λλ€. κ°μΈ νμ΄μ΄λ―λ‘ μ€λ΅μ΄ μμ μ μμΌλ©° μ€λ΅ λ°κ²¬ μ λκΈ λ¨κ²¨μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€π - #μ΄ νμλ 건 μμ§ νμ§ λͺ»ν λ¬Έμ or ν·κ°λ¦¬λ λ¬Έμ μ λλ€! μΆνμ λ€μ νμ΄μ μ¬λ¦΄ μμ μ΄μμ! -ujeyhx- |
πμ€μ΅λ¬Έμ
1)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("Let's study java");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,200);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
2)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("BorderLayout Practice");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new BorderLayout(50,5)); //μνμμ§ κ°κ²©
c.add(new JButton("Center"),BorderLayout.CENTER);
c.add(new JButton("South"),BorderLayout.SOUTH);
c.add(new JButton("North"),BorderLayout.NORTH);
c.add(new JButton("East"),BorderLayout.EAST);
c.add(new JButton("West"),BorderLayout.WEST);
setSize(500,300);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
3)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("FlowLayout Practice");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("100 + 200"));
c.add(new JButton("="));
c.add(new JLabel("300"));
setSize(400,100);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
4)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("Ten Color");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new GridLayout(1,10));
Color [] cl = {Color.RED, Color.ORANGE, Color.YELLOW,
Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA, Color.GRAY,
Color.PINK, Color.LIGHT_GRAY};
for(int i=0; i<10; i++) {
JButton btn = new JButton(Integer.toString(i));
btn.setOpaque(true); //λ°°κ²½μ 보μ΄κ² μ€μ
btn.setBackground(cl[i]);
c.add(btn);
}
setSize(500,300);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
5)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("4x4");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new GridLayout(4,4));
JLabel [] la = new JLabel[16];
Color [] color = {Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN,
Color.CYAN, Color.BLUE, Color.MAGENTA, Color.GRAY,
Color.PINK, Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY,
Color.BLACK, Color.ORANGE, Color.BLUE,Color.MAGENTA};
for(int i=0; i<=15; i++) {
la[i] = new JLabel(Integer.toString(i));
la[i].setOpaque(true); //λ°°κ²½μ 보μ΄κ² μ€μ
la[i].setBackground(color[i]);
c.add(la[i]);
}
setSize(500,300);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
6)
import javax.swing.*;
import java.awt.*;
public class TEST2 extends JFrame {
public TEST2() {
setTitle("Rd");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
for(int i=0; i<20; i++) {
JLabel la = new JLabel(Integer.toString(i));
int x = (int)(Math.random()*220) +30;
int y = (int)(Math.random()*220) +30;
la.setLocation(x,y);
la.setSize(20,20);
la.setForeground(Color.MAGENTA);
c.add(la);
}
setSize(300,400);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}
7) κΈ°λ₯ ꡬνμ λ°λ‘ μ νκ³ , λ μ΄μμλ§ λ§λ€μμ΅λλΉ π©
import javax.swing.*;
import java.awt.*;
class TopPanel extends JPanel {
public TopPanel () {
setLayout(new FlowLayout());
add(new JButton("μλ‘λ°°μΉ"));
add(new JButton("μ’
λ£"));
}
}
class CenterPanel extends JPanel {
public CenterPanel () {
setLayout(null);
for(int i=0; i<10; i++) {
JLabel la = new JLabel("*");
int x = (int)(Math.random()*220) +30;
int y = (int)(Math.random()*220) +30;
la.setLocation(x,y);
la.setSize(20,20);
la.setForeground(Color.MAGENTA);
add(la);
}
}
}
class BottomPanel extends JPanel {
public BottomPanel () {
setLayout(new FlowLayout());
add(new JButton("λ³κ°μ μμ "));
add(new JTextField(12));
}
}
public class TEST2 extends JFrame {
public TEST2() {
setTitle("3κ°μ ν¨λ");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new TopPanel(), BorderLayout.NORTH);
add(new CenterPanel(), BorderLayout.CENTER);
add(new BottomPanel(), BorderLayout.SOUTH);
setSize(300,400);
setVisible(true);
}
public static void main (String[] args) {
new TEST2();
}
}