Frog is cry
Swing 본문
package Swing;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
import javax.swing.JFrame;
public class WindowTest {
public static void main(String[] args) {
Frame window = new Frame("제목");
window.setTitle("제목이 변경된 윈도우");
window.setBounds(1200, 200, 400, 300);
window.setBackground(Color.ORANGE);
//색상은 0 ~ 255 3개로 표현한다. 그러므로 모든 경우의 수 를 곱한 값을 랜덤으로 적는다.
window.setBackground(new Color(new Random().nextInt(16_581_376)));
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
window.dispose(); // 닫기
}
});
window.setVisible(true);
}
}
package Swing;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
public class WindowTest2 extends Frame{
public WindowTest2() {
this("제목 없는 윈도우");
}
public WindowTest2(String title) {
setTitle(title);
setBounds(1200, 400, 400, 300);
setBackground(new Color(new Random().nextInt(16_581_376)));
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dispose();
}
});
setVisible(true);
}
public static void main(String[] args) {
new WindowTest2();
new WindowTest2("제목있는 윈도우");
}
}
package Swing;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
public class WindowTest3 {
public static void main(String[] args) {
JFrame window = new JFrame("제목이 있는 윈도우");
window.setBounds(1200, 200, 400, 300);
Container con = window.getContentPane();
con.setBackground(Color.black);
// window.setBackground(Color.BLACK);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
}
package Swing;
import java.awt.Color;
import java.awt.Container;
import java.util.Random;
import javax.swing.JFrame;
public class WindowTest4 extends JFrame{
public WindowTest4() {
this("제목 없는 윈도우");
}
public WindowTest4(String title) {
Color[] arColor = {
Color.BLACK, Color.BLUE, Color.RED, Color.PINK, Color.YELLOW, Color.GREEN
};
setTitle(title);
setBounds(1200, 200, 400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane();
con.setBackground(arColor[new Random().nextInt(6)]);
setVisible(true);
}
public static void main(String[] args) {
new WindowTest4("배경색 랜덤으로 적용하기");
}
}
package Swing;
import java.awt.Color;
import java.awt.Container;
import java.text.SimpleDateFormat;
import java.util.Random;
import javax.swing.JFrame;
public class WindowTest5 extends JFrame implements Runnable{
// 현재시간 초단위로 나타내기
public WindowTest5() {}
public WindowTest5(String title) {
Color [] arColor = {
Color.BLACK, Color.CYAN, Color.GRAY, Color.MAGENTA, Color.ORANGE,
Color.RED
};
setTitle(title);
setBounds(1200, 200, 400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane();
con.setBackground(arColor[new Random().nextInt(6)]);
setVisible(true);
}
public static void main(String[] args) {
WindowTest5 window = new WindowTest5 ("제목 있는 윈도우");
Thread t = new Thread(window);
t.start();
}
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
while(true) {
setTitle(sdf.format(System.currentTimeMillis()));
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
'JAVA > 복습' 카테고리의 다른 글
시간 구하기 예제 (0) | 2020.07.30 |
---|---|
스레드 (0) | 2020.07.29 |
MVC모델(수정필요) (0) | 2020.07.29 |
컬렉션 프레임워크 (Hash) (0) | 2020.07.29 |
컬렉션 프레임워크(Array List) (0) | 2020.07.29 |
Comments