본문 바로가기

JAVA

(187)
채팅창 package awtSample06; public class mainClass { public static void main(String[] args) { // TODO Auto-generated method stub new WindowTest(); } } package awtSample06; import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JO..
버튼 클릭하여 새로운 창 열기2 (Singleton 사용) 2. setVisible을 false true (원하는 화면만 켜줌) //싱글턴사용 main public class mainClass { public static void main(String[] args) { SingletonClass.getInstance().one.setVisible(true); //모두 꺼놓고 메인에서 첫번째 윈도우 true로 켜짐 설정 } } SingletonClass public class SingletonClass {//실무에서는 delegete라는 명칭을 많이 씀 private static SingletonClass sc = null; WindowOne one; WindowTwo two; private SingletonClass() { one = new WindowOne()..
버튼 클릭하여 새로운 창 열기1 (Frame 새로생성) 방법 총 3개 ---------------------- window(Frame1) 에서 -> Frame 방법 1. close 후 new (새로생성) 2. setVisible을 false true (원하는 화면만 켜줌) //싱글턴사용 3. Panel 사용 Panel1 Panel2 (현상태를 유지하며 종이만 바꿈//주로씀) main package windowChange1; public class mainClass { public static void main(String[] args) { new WindowOne(); } } windowOne public class WindowOne extends Frame { public WindowOne() { setLayout(null); Button btn = new..
layout(버튼과 라벨 기본셋팅) main package awtSample03; public class mainClass { public static void main(String[] args) { new WindowTest(); } } windowTest public class WindowTest extends Frame implements WindowListener { public WindowTest() { super("Layout"); //setLayout(new FlowLayout());// 맨 위에 일렬로 배치 //setLayout(new GridLayout(3,1));//3행 1열 setLayout(null);//사용 안하고 Label위치를 잡아줌 //Label Label label1 = new Label("label 1");..
체크박스, 라디오버튼 라디오버튼은 참조 https://blog.naver.com/skykingkjs/150145068901 [자바][스윙] JRadioButton 라디오 버튼 한번에 1개만 선택 할 수 있는 것이 라디오 버튼이다. 라디오버튼은 아래의 순서로 만든다 1.라디... blog.naver.com main package awtSample07; public class mainClass { public static void main(String[] args) { new WindowTest(); } } windowTest public class WindowTest extends JFrame implements ItemListener{ Checkbox cb1,cb2,cb3,cb4,cb5,cb6;//체크박스 생성 Label l..
뷰클래스 셋팅 코드 화면 셋팅 setLayout(null); setSize(640, 480); setLocation(100, 0); setVisible(true); addWindowListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); label[] 셋팅 JLabel label[]; setLayout(null); 프론트라벨 frontLabel = new JLabel("? 승 ? 패 ? 무"); frontLabel.setBounds(70, 50, 500, 30); frontLabel.setBackground(Color.yellow); frontLabel.setHorizontalAlignment(JLabel.CENTER); frontLabel.setOpaque(true..
가위바위보 게임 프로그램 **가위 바위 보를 0,1,2 숫자로 나타내어 컴퓨터와 게임했을 때 이기고 지고 비길때의 규칙을 찾아내는 것이 관건 **게임 패키지 따로 생성 후 작성 Main package main; import view.MainView; public class mainClass { public static void main(String[] args) { new MainView(); } } view JFrame으로 상속, 액션 리스너 상속 (그냥 label은 한글깨짐 발생, swing계열은 한글깨짐 없음(JLabel)) label이 많이 필요하므로 배열로 생성 JLabel label[]; button[]도 배열. list로 잡아도 되나 추가삭제할 필요업으므로 일반 배열 frontlabel셋팅-> 게임제목 설정(?승?패..
접근제한자 정리 public public int p = 3; 전체공개, 모든 접근을 허용, 가장 넓은 의미 protected protected int p2 = 4; 같은 패키지인 경우에만 접근 허용, 다른패키지라도 상속받은 자식클래스는 사용가능 private private int i = 1; 자기자신만 접근 가능 default int k = 2; default 접근 지정자. 아무것도 쓰지 않은경우, 같은 패키지에서 자유롭게 사용가능 순서대로 public > protected > default > private