Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.191.154.132
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/ndlutz/CS 202/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/ndlutz/CS 202/rwb.java
//		Author: 		Nathan Lutz
//		Filename:		rwb.java
//		Instructor: 	Dr. Wang
//		Class: 		    CS202 and Java
//		Due Date: 		April 16, 2008
//		Goal:			Write the code for an applet that has three buttons labeled Red, White, and Blue. When a button is clicked, the background of the applet changes to the color named on the button.

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

public class rwb extends JApplet implements ActionListener
{
	public void init()
	{
		Container contentPane = getContentPane();
		contentPane.setBackground(Color.WHITE);
		contentPane.setLayout(new  FlowLayout());
		JButton redButton = new JButton("Red");
		contentPane.add(redButton);
		redButton.addActionListener(this);
		JButton whiteButton = new JButton("White");
		contentPane.add(whiteButton);
		whiteButton.addActionListener(this);
		JButton blueButton = new JButton("Blue");
		contentPane.add(blueButton);
		blueButton.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		Container contentPane = getContentPane();

		if (e.getActionCommand().equals("White"))
			contentPane.setBackground(Color.WHITE);
		else if (e.getActionCommand().equals("Red"))
			contentPane.setBackground(Color.RED);
        else if (e.getActionCommand().equals("Blue"))
			contentPane.setBackground(Color.BLUE);
		else
			System.out.println("Error in Button interface.");
	}
}

Stv3n404 - 2023