안드로이드 개발 질문/답변
(글 수 45,052)
아래와 같이 10개의 클래스를 생성해 10개까지의 프레임(창)이 뜨도록 했는데요
연속적으로 띄워줄수 있도록 해주고 싶기도 하고
되게 비효율적여 보여서요 다른 효과적인 방법이 없을까요?
메시지를 받으면 그 메시지를 JLabel에 넣어서 뛰워주는 걸 하고 있거든요 좀 알려주세요 ^^ 부탁드리겠습니다
public class Frame extends JFrame{ //중복 Method 들어있는 클래스
//JFC(Swing)을 사용 Window 구현
ImageIcon icon; //이미지 아이콘
public Frame(String title){
super(title);
}
/*
public void FrameObject(String str){
Frame1 window1 = new Frame1(str);
Frame2 window2 = new Frame2(str);
Frame3 window3 = new Frame3(str);
Frame4 window4 = new Frame4(str);
Frame5 window5 = new Frame5(str);
Frame6 window6 = new Frame6(str);
Frame7 window7 = new Frame7(str);
Frame8 window8 = new Frame8(str);
Frame9 window9 = new Frame9(str);
Frame10 window10 = new Frame10(str);
}
*/
public void init(String str){
icon = new ImageIcon("1.png"); //이미지아이콘 객체 선언
this.setIconImage(icon.getImage()); //이미지아이콘 셋
Container con = this.getContentPane();
JLabel output = new JLabel(str,JLabel.CENTER);
output.setFont(new Font("맑은고딕", Font.BOLD, 20)); // 글씨체 설정
con.add(output); //JLabel 붙임
con.setBackground(Color.PINK);
//화면 X,Y좌표 중간에 Window 출력하기 위한 좌표 설정 변수
//Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
//Dimension frm = this.getSize();
//int xpos = (int)(screen.getWidth() / 2 - frm.getWidth() / 2);
//int ypos = (int)(screen.getHeight() / 2 - frm.getHeight() / 2);
this.setSize(300,200);
this.setResizable(true); //Frame 크기 변경 불가
this.setVisible(true); //Frame 보임
/*try{ //Thread 2초 지연줌
Thread.sleep(2000);
}catch(InterruptedException e){}*/
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//프레임 X버튼 눌렀을때 구현되어있는 정상 종료
}
}
class Frame1 extends Frame{ //1번째 JFrame 클래스
public Frame1(String title){ //생성자 Window 이름 받아서 보여줌
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(50,50);
}
}
class Frame2 extends Frame{ //2번째 JFrame 클래스
public Frame2(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(400,50);
}
}
class Frame3 extends Frame{ //3번째 JFrame 클래스
public Frame3(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(750,50);
}
}
class Frame4 extends Frame{ //4번째 JFrame 클래스
public Frame4(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(50,300);
}
}
class Frame5 extends Frame{ //5번째 JFrame 클래스
public Frame5(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(400,300);
}
}
class Frame6 extends Frame{ //6번째 JFrame 클래스
public Frame6(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(750,300);
}
}
class Frame7 extends Frame{ //7번째 JFrame 클래스
public Frame7(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(50,550);
}
}
class Frame8 extends Frame{ //8번째 JFrame 클래스
public Frame8(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(400,550);
}
}
class Frame9 extends Frame{ //9번째 JFrame 클래스
public Frame9(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(750,550);
}
}
class Frame10 extends Frame{ //10번째 JFrame 클래스
public Frame10(String title){
super(title);
}
public void init(String str){
super.init(str);
this.setLocation(1050,550);
}
}




메쏘드로 구현해 보세요
Frame window1 = createFrame("첫번째", 50, 50);
:
:
Frame window10 = createFrame("열번째", 1050, 550);
public Frame createFrame(String str, int x, int y){
Frame frame = new Frame(str);
frame.setLocation(x, y);
return frame;
}