U E D R , A S I H C RSS

Button/진영

No older revisions available

No older revisions available



이렇게 해도 되는 건지 원... -_-;;


~cpp 

// ButtonTest.java

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

class ButtonPanel extends JPanel
implements ActionListener
{
	public ButtonPanel()
	{
		yellowButton = new JButton("Yellow");
		blueButton = new JButton("Blue");
		redButton = new JButton("Red");
		
		add(yellowButton);
		add(blueButton);
		add(redButton);
		
		yellowButton.addActionListener(this);
		blueButton.addActionListener(this);
		redButton.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent evt)
	{
		Object source = evt.getSource();
		Color color = getBackground();
		if(source == yellowButton)
			color = Color.yellow;
		else if(source == blueButton)
			color = Color.blue;
		else if(source == redButton)
			color = Color.red;
		setBackground(color);
		repaint();
	}
	
	private JButton yellowButton;
	private JButton blueButton;
	private JButton redButton;
}

class ButtonFrame extends JFrame
{
	public ButtonFrame()
	{
		setTitle("ButtonTest");
		setSize(300, 200);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		} );
		
		Container contentPane = getContentPane();
		contentPane.add(new ButtonPanel());
	}
}

public class ButtonTest
{
	public static void main(String[] args)
	{
		JFrame frame = new ButtonFrame();
		frame.show();
	}
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:40
Processing time 0.0224 sec