JFrame

전영덕·2023년 2월 12일
0

Java Swing

목록 보기
1/2
  • 자바 스윙에서 기본이 되는 Frame을 만들어보자.
    메인 메서드에서 바로 Frame을 만들 수 있지만 앞으로도 계속 프레임 클래스를 호출할 것이므로 처음부터 빼놓자.
public class Main01 {
	public static void main(String[] args) {
		new Myframe();
	}
}
  • Frame Class
package learningSwingByYoutube;

import java.awt.Color;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class Myframe extends JFrame{
	public Myframe() {
		this.setTitle("Jthis title goes here"); 				//5. sets title of this
		this.setSize(420, 420); 								//3. sets the X-dimension and y-dimension of this
		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); 		//6. exit out of application. We can set do_nothing or hide_On_Close etc instead of exit on close.
		this.setResizable(true); 								//7. prevent this from being resized
		this.setVisible(true); 									//2. make this visible
		this.setLocation(300, 400);								//4. sets location of this
	//	this.setBounds(100, 200, 300, 400); 					//+a : step3 and step4 mix method
		
		ImageIcon image1 = new ImageIcon("image1.jpg");			//8. create an ImageIcon
		this.setIconImage(image1.getImage());					//9. change icon of this
		this.getContentPane().setBackground(Color.GREEN); 		//10. change color of background.  new Color(int Red, int Green, int Blue) instead of Color.Green
	}
}
  • 이부분은 프레임 좌측상단의 사진
ImageIcon image1 = new ImageIcon("image1.jpg");		
		this.setIconImage(image1.getImage());		

0개의 댓글