Toggle Button

import javax.swing.*;
public class FrameDemo9 extends JFrame 
{
	//Panel1 p1;
	public FrameDemo9()
	{
		super("techmyguru.com");
		setSize(500,600);
		getContentPane().add(new PanelToggleButtonDemo());
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		
	}
	public static void main(String[] args) 
	{
	new FrameDemo9();
	}

}

Download

PanelToggleButtonDemo.java

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
public class PanelToggleButtonDemo extends JPanel implements ActionListener {
	private JToggleButton red = new JToggleButton("red");
	private JToggleButton green = new JToggleButton("green");
	private JToggleButton blue = new JToggleButton("blue");
	public PanelToggleButtonDemo() {
		super();
		add(red);
		add(green);
		add(blue);
		red.addActionListener(this);
		green.addActionListener(this);
		blue.addActionListener(this);
		setBackground(Color.black);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		Color color = getBackground();
		int red = color.getRed();
		int green = color.getGreen();
		int blue = color.getBlue();

		if (e.getActionCommand() == "red") {
			if (red == 0) {
				red = 255;
			} else {
				red = 0;
			}
		}
		if (e.getActionCommand() == "green") {
			if (green == 0) {
				green = 255;
			} else {
				green = 0;
			}
		}
		if (e.getActionCommand() == "blue") {
			if (blue == 0) {
				blue = 255;
			} else {
				blue = 0;
			}
		}
		Color setCol = new Color(red, green, blue);
		setBackground(setCol);
	}
}

Download

Frame in Swing

Simple Frame
Frame with Panel
Frame Menu Event ans Color Chooser
Frame with Panel and Button
TextField and TextArea
Combobox in Frame
Change Icon of Frame
Scrollbar in Frame
Scrollbar in Frame
Add picture in Frame
Label in Frame
Toggle Buttons in frame
Radio Buttons in Frame


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code