MapleStory Finger Point

🟀 JAVA/πŸ“šλͺ…ν’ˆ JAVA_ESSENTIAL

#[λͺ…ν’ˆ JAVA ESSENTIAL] CH10 μ‹€μŠ΅λ¬Έμ œ

HYEJU01 2022. 4. 17. 16:52
"κ°œμ •νŒ: λͺ…ν’ˆ JAVAESSENTIAL(ν™©κΈ°νƒœ)"κ΅μž¬μ— 수둝된 λ¬Έμ œλ“€μ„ ν’€μ–΄μ„œ μ˜¬λ¦½λ‹ˆλ‹€.
문제의 번호만 ν‘œκΈ°ν•˜κ³  λ‹΅μ•ˆλ§Œ μ λŠ” ν˜•νƒœλ‘œ μ—…λ‘œλ“œ ν•˜κ³ μžˆμŠ΅λ‹ˆλ‹€.
개인 ν’€μ΄μ΄λ―€λ‘œ μ˜€λ‹΅μ΄ μžˆμ„ 수 있으며 μ˜€λ‹΅ 발견 μ‹œ λŒ“κΈ€ λ‚¨κ²¨μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€πŸ˜Š
-
#이 ν‘œμ‹œλœ 건 아직 풀지 λͺ»ν•œ 문제 or ν—·κ°ˆλ¦¬λŠ” λ¬Έμ œμž…λ‹ˆλ‹€!
좔후에 λ‹€μ‹œ ν’€μ–΄μ„œ 올릴 μ˜ˆμ •μ΄μ—μš”!

-ujeyhx-

 

 

πŸ”Žμ‹€μŠ΅λ¬Έμ œ

 

 

1) 이미지 ν™•μž₯μžκ°€ 쀑간에 PNG κ°€ κ»΄μžˆμ–΄μ„œ κ·Έλƒ₯ ν•˜λ‚˜ν•˜λ‚˜ μ½”λ”©ν–ˆμŠ΅λ‹ˆλ‹€ 

ν™•μž₯자 ν†΅μΌμ‹œμΌœμ„œ λ°°μ—΄λ‘œ 돌리면 κΉ”λ”ν•œ μ½”λ“œκ°€ λ˜κ² μ§€μš” !!

 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class TEST2 extends JFrame {
	
	public TEST2 () {
		super("test");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container c = getContentPane();
		c.setLayout(new GridLayout(1,4));
		
		ImageIcon img1 = new ImageIcon("images/images.jpg");
		ImageIcon img2 = new ImageIcon("images/images (1).jpg");
		ImageIcon img3 = new ImageIcon("images/IMG_1611.jpg");
		ImageIcon img4 = new ImageIcon("images/λ‹€μš΄λ‘œλ“œ.png");
		JLabel la1 = new JLabel(img1);
		JLabel la2 = new JLabel(img2);
		JLabel la3 = new JLabel(img3);
		JLabel la4 = new JLabel(img4);
		
		
		c.add(la1);
		c.add(la2);
		c.add(la3);
		c.add(la4);

		setSize(400,300);
		setVisible(true);

	}
		
	
	static public void main(String[] arg) {
		new TEST2(); // μŠ€μœ™ ν”„λ ˆμž„ 생성
	}
	
	
}

햄깅이

 


 

2)

 

import javax.swing.*;


public class TEST2 extends JFrame {
	
	public TEST2 () {
		super("test");
		createMenu();
		setSize(400,300);
		setVisible(true);
		
		

	}
	
	private void createMenu() {
		JMenuBar mb = new JMenuBar();
		JMenu sM1 = new JMenu("파일");
		JMenu sM2 = new JMenu("νŽΈμ§‘");
		JMenu sM3 = new JMenu("보기");
		JMenu sM4 = new JMenu("μž…λ ₯");
		
		sM3.add(new JMenuItem("ν™”λ©΄ν™•λŒ€"));
		sM3.addSeparator();
		sM3.add(new JMenuItem("μͺ½μœ€κ³½"));
		
		
		
		mb.add(sM1);
		mb.add(sM2);
		mb.add(sM3);
		mb.add(sM4);
		
		setJMenuBar(mb);
	}
		
	
	static public void main(String[] arg) {
		new TEST2(); // μŠ€μœ™ ν”„λ ˆμž„ 생성
	}
	
	
}

 


 

3)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TEST2 extends JFrame {
	private JRadioButton red = new JRadioButton("Red");
	private JRadioButton blue = new JRadioButton("Blue");

	public TEST2() {
		
		super("test");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		
		ButtonGroup g = new ButtonGroup();
		g.add(red);
		g.add(blue);
		
		c.add(red);
		c.add(blue);
		
		MyItemListener listener = new MyItemListener();
		
		red.addItemListener(listener);
		blue.addItemListener(listener);
		
		setSize(250, 100);
		setVisible(true);
		
	}

	class MyItemListener implements ItemListener {
		
		public void itemStateChanged(ItemEvent e) {
			if(e.getStateChange() != ItemEvent.SELECTED) //μ΄λ²€νŠΈλ°œμƒ, μ„ νƒλ˜μ§€μ•ŠμœΌλ©΄!
				return;
			if(e.getItem() == red) {
				getContentPane().setBackground(Color.RED);
			}
			else if(e.getItem() == blue) {
				getContentPane().setBackground(Color.BLUE);
			}
		}
		
	}
	
	public static void main(String[] args) {
		new TEST2();

	}
}


4)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TEST2  extends JFrame {
	private JCheckBox cb1 = new JCheckBox ("λ²„νŠΌ λΉ„ν™œμ„±ν™”");
	private JCheckBox cb2 = new JCheckBox ("λ²„νŠΌ 감좔기");
	JButton btn = new JButton ("test button");
	
	
	public TEST2() {
		super("test");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		
	
		
		cb1.addItemListener(new MyItemListener());
		cb2.addItemListener(new MyItemListener());

		c.add(cb1);
		c.add(cb2);
		c.add(btn);
		
		setSize(300,200);
		setVisible(true);
	}
	
private class MyItemListener implements ItemListener {

	@Override
	public void itemStateChanged(ItemEvent e) {
		if(e.getStateChange() == ItemEvent.SELECTED) {
			
			if(e.getItem() == cb1) {
				btn.setEnabled(false);
			}
			
			if (e.getItem() == cb2){
				btn.setVisible(false);
			}
			
		}
	
		if(e.getStateChange() != ItemEvent.SELECTED) {
			
			if(e.getItem() == cb1) {
				btn.setEnabled(true);
			}
			
				
			if (e.getItem() == cb2){
				btn.setVisible(true);
			}
			
		}
	}
		
}
	

	
	
	public static void main(String[] args) {
		new TEST2();

	}

}

 

 


5) #  νŒμ—…μ°½ κΈ°λŠ₯ κ΅¬ν˜„μ€ λ‚˜μ€‘μ— λ‹€μ‹œ ,,,, 곡뢀 !!!

 

import java.awt.*;
import java.awt.event.*;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.*;

public class TEST2  extends JFrame {
	private JTextArea ta = new JTextArea();
	
	public TEST2() {
		super("test");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		createMenu();
		
		Container c = getContentPane();
		c.add(new JScrollPane(ta)); //μŠ€ν¬λ‘€λ°” μ‚½μž…
		
		setSize(300,200);
		setVisible(true);
	}
	
	private void createMenu() {
		JMenu fileMenu = new JMenu("파일"); //2메뉴
		JMenuItem save = new JMenuItem("μ €μž₯"); //3λ©”λ‰΄μ•„μ΄ν…œ
		
		fileMenu.add(save);
		
 /*	save.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				
				if(ta.getText().length() == 0) {
					JOptionPane.showMessageDialog(TEST2.this, 
							"μž…λ ₯된 λ‚΄μš©μ΄ μ—†μŠ΅λ‹ˆλ‹€.",
							"Warning", JOptionPane.WARNING_MESSAGE);
					return;
				}
				
				String fileName = JOptionPane.showInputDialog(TEST2.this, 
						"μ €μž₯ν•  파일λͺ…을 μž…λ ₯ν•˜μ„Έμš”");
				
				if(fileName == null) {
					JOptionPane.showMessageDialog(TEST2.this,
							"νŒŒμΌμ„ μ €μž₯ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.",
							"Warning", JOptionPane.WARNING_MESSAGE);
					return;					
				}
				
				try {
					FileWriter fout = new FileWriter(fileName); // 파일 슀트림 μ—΄κΈ°
					String t = ta.getText(); // μž…λ ₯된 ν…μŠ€νŠΈλ₯Ό λ¬Έμžμ—΄λ‘œ μ–»μ–΄λ‚΄κΈ°
					StringTokenizer st = new StringTokenizer(ta.getText(), "\n"); // 라인 λ‹¨μœ„λ‘œ 뢄리
					while(st.hasMoreTokens()) {
						fout.write(st.nextToken()); // ν•œ 라인 μ“°κΈ°
						fout.write("\r\n"); // 라인 끝에 λ‹€μŒ μ€„λ‘œ λ„˜μ–΄κ°€λŠ” 문자 μ‚½μž…
					}
					fout.close(); // 파일 슀트림 λ‹«κΈ°
				} catch (IOException e1) {}
			}
		}); */
	
		
		
		JMenuBar mb = new JMenuBar(); //1메뉴바
		
		mb.add(fileMenu);
		
		setJMenuBar(mb); //4ν”„λ ˆμž„
	}
	
	public static void main(String[] args) {
		new TEST2();

	}

}

5)

 


6)