자바

 

http://www.eclipse.org/windowbuilder/download.php

 

 

 

 

 

class ImageLabelTest

 

package java12;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;

public class ImageLabelTest extends JFrame {

	private JPanel contentPane;
	private JLabel label;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ImageLabelTest frame = new ImageLabelTest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ImageLabelTest() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 552, 448);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		label = new JLabel("이미지를 보려면 아래 버튼을 누르세요");
		label.setBounds(25, 10, 304, 127);
		contentPane.add(label);
		
		JButton button = new JButton("이미지 레이블");
		button.setIcon(new ImageIcon(ImageLabelTest.class.getResource("/java12/spider.png")));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//label.setText("버튼을 눌렀습니다.");
				// getClass() 현재 클래스의 정보
				// getClass().getResource() 현재 클래스와 같은 디렉토리에 있는 리소스
				ImageIcon spider=new ImageIcon(getClass().getResource("/java12/spider.png"));
				label.setIcon(spider);// 라벨의 아이콘 설정
				label.setText(null); // 라벨의 텍스트를 null 로 변경
				
			}
		});
		button.setBounds(104, 277, 350, 123);
		contentPane.add(button);
	}
	
	
	
	
}

 

 

 

 

class CheckboxPanel

 

 

package java12;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

public class CheckboxPanel extends JFrame {

	private JPanel contentPane;
	private JLabel lblApple;
	private JLabel lblGrape;
	private JLabel lblOrange;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CheckboxPanel frame = new CheckboxPanel();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CheckboxPanel() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 786, 581);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JCheckBox apple = new JCheckBox("사과");
		apple.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				//라벨에 표시할 아이콘
				ImageIcon icon=new ImageIcon(getClass().getResource("/java12/1493241241_Apple.png"));
				
				if(e.getStateChange()==ItemEvent.DESELECTED){
					lblApple.setIcon(null);//체크되지 않은 상태
					lblApple.setText("사과");
				}else{
					lblApple.setIcon(icon); //체크 상태
					lblApple.setText("");
				}
				
			}
		});
		apple.setBounds(24, 53, 115, 23);
		contentPane.add(apple);
		
		JCheckBox grape = new JCheckBox("포도");
		grape.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				
				//라벨에 표시할 아이콘
				ImageIcon icon=new ImageIcon(getClass().getResource("/java12/1493241250_Grape.png"));
				
				if(e.getStateChange()==ItemEvent.DESELECTED){
					lblGrape.setIcon(null);//체크되지 않은 상태
					lblGrape.setText("포도");
				}else{
					lblGrape.setIcon(icon); //체크 상태
					lblGrape.setText("");
				}
				
			}
		});
		grape.setBounds(24, 129, 65, 23);
		contentPane.add(grape);
		
		JCheckBox orange = new JCheckBox("오렌지");
		orange.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				//라벨에 표시할 아이콘
				ImageIcon icon=new ImageIcon(getClass().getResource("/java12/1493241281_Orange.png"));
				
				if(e.getStateChange()==ItemEvent.DESELECTED){
					lblOrange.setIcon(null);//체크되지 않은 상태
					lblOrange.setText("오렌지");
				}else{
					lblOrange.setIcon(icon); //체크 상태
					lblOrange.setText("");
				}
			}
		});
		orange.setBounds(24, 226, 115, 23);
		contentPane.add(orange);
		
		lblApple = new JLabel("사과");
		lblApple.setBounds(120, 10, 156, 300);
		contentPane.add(lblApple);
		
		lblGrape = new JLabel("포도");
		lblGrape.setBounds(344, 10, 166, 300);
		contentPane.add(lblGrape);
		
		lblOrange = new JLabel("오렌지");
		lblOrange.setBounds(599, 29, 148, 262);
		contentPane.add(lblOrange);
	}
}

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

The greatest wealth is contentment with a little. (가장 큰 부자는 작은 것에 만족하는 것이다.)

댓글 ( 0)

댓글 남기기

작성
  •    
  •