import java.awt.*;
import javax.swing.*;
class Challenge9 extends JFrame{
Challenge9(){
setTitle("Open Challenge9");
setDefaultCloseOperation(3);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(new NorthPanel(), BorderLayout.NORTH);
c.add(new CenterPanel(), BorderLayout.CENTER);
setSize(400, 500);
setVisible(true);
}
class NorthPanel extends JPanel{
NorthPanel(){
setBackground(Color.GRAY);
setLayout(new FlowLayout());
add(new JButton("Open"));
add(new JButton("Read"));
add(new JButton("Close"));
}
}
class CenterPanel extends JPanel{
CenterPanel(){
String text[] = {"Hello", "Java", "Love"};
setBackground(Color.lightGray);
setLayout(null);
int x, y;
for(int i = 0; i < text.length; i++){
x = (int)(Math.random()*350);
y = (int)(Math.random()*450);
JLabel label = new JLabel(text[i]);
label.setSize(50, 10);
label.setLocation(x, y);
add(label);
}
}
}
public static void main(String args[]){
new Challenge9();
}
}
'대학교 수업 > Java 프로그래밍' 카테고리의 다른 글
[Java] 명품 자바 프로그래밍 10장 실습문제 (0) | 2022.10.11 |
---|---|
[Java] 명품 자바 프로그래밍 10장 Open Challenge (0) | 2022.10.11 |
[JAVA] 명품 자바 프로그래밍 11장 실습문제 (0) | 2022.10.05 |
[JAVA] 명품 자바 프로그래밍 9장 실습문제 (0) | 2022.10.03 |
[JAVA] 명품 자바 프로그래밍 7장 실습문제 (0) | 2022.06.14 |