본문 바로가기

전체 글

(195)
#02 - 버튼배열 생성(계산기 프로그램) 계산기 만들기 소스코드 public class JavaExam { public static void main(String[] args) { new P02_Button(); } } class P02_Button{ // JFrame을 상속받지 않은 예제 JLabel label; JButton[] button; public P02_Button() { run(); } private void run() { JFrame frame = new JFrame(); JPanel panel_t = new JPanel(); JPanel panel_c = new JPanel(); label = new JLabel(); label.setFont(new Font("굴림", Font.BOLD, 15)); panel_t.setPref..
#02 - 버튼 생성하기(JPanel / JButton / JLabel) 모든내용은 아래에서 위로 배열을 사용하여 버튼 이벤트 생성 public class JavaExam { public static void main(String[] args) { new P02_Button(); } } class P02_Button{ public P02_Button() { run(); } private void run() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JButton[] button = new JButton[10]; for(int i=0; i { // JOptionPane.showMessageDialog(null, "클릭"); // }); // 버튼 컴포넌트를 패널(컨테이너)에 붙이기 panel.add(button);..
#01 - 시작하기(JFrame) JFrame을 상속받은 경우 public class JavaExam { public static void main(String[] args) { new P01_Frame(); } } class P01_Frame extends JFrame{ public P01_Frame() { run(); } private void run() { setTitle("예제1"); setBounds(100, 100, 300, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } JFrame을 상속받지 않고 사용한 경우 public class JavaExam { public static void main(String[] args) { new P01..
랜덤뽑기 로또 출력하기 import random def printLotto(num_list): lotto = [] lotto = random.sample(num_list, 6) lotto.sort() for n in range(6): print(f'{lotto[n]:>02}', end=" ") #print(f'{str(lotto[n]).zfill(2)}', end=" ") print() numbers= list(range(1,46)) for i in range(5): printLotto(numbers) A-D가운데 하나 뽑고, 가~아 에서 2개 뽑아 출력하기 import random member1 = set(["A","B","C","D"]) member2 = set(["가","나","다","라","마","바","..
GUI #2 import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class JavaExam4 { public static void main(String[] args) { new GraphicDrawEx(); } } class GraphicDrawEx extends JFrame{ private MyPanel myPanel = new MyPanel(); public GraphicDrawEx() { run(); } private void run() { setContentPane(..
GUI public class JavaExam { public static void main(String[] args) { new P07_ComboBox(); } } class P07_ComboBox extends JFrame{ public P07_ComboBox() { run(); } private void run() { JPanel panel = new JPanel(); String[] items = new String[] {"빨강","주황","노랑","초록","파랑","남색","보라"}; JComboBox combo = new JComboBox(items); combo.addActionListener(new ActionListener() { public void actionPerformed(ActionEv..
CSV파일 처리 CSV파일 처리 더보기 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class JavaExam { public static void main(String[] args) { CSVReader csvReader = new C..
lilyPad_v220721 1. 전체 LED 깜빡이기 const long interval = 200; //깜빡임 시간지정 int ledArr[] = {A4,A3,A2,11,10,9}; //깜빡임 LED지정 int ledSize = sizeof(ledArr)/sizeof(ledArr[0]); unsigned long previousMillis = 0; int sys_cnt = 0; void setup() { for(int i=0; i= interval) { previousMillis = currentMillis; led_blink(); } } void led_blink() { if(sys_cnt%2 == 0) led_all_on(); else led_all_off(); sys_cnt++; } void led_all_on() { fo..