Tuesday, March 17, 2009

CoLor CycLe

ExerCise #2: CoLor Cycle

//ProgrammerName: Reuben D. matiga
//ProgramName: CoLor CycLe 
//Purpose: To Learned more in java
//Date: March 17,2009
//Instructor: Dony Dongiapon


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class ButtonDemo extends JPanel implements ActionListener {

 private static boolean USE_CROSS_PLATFORM_UI = false;
 
 int buttonLabelIndex = 0;
 String buttonLabels[] = { "yellow", "red", "black", "pink" };
 Color buttonColors[] = { Color.YELLOW, Color.RED, Color.BLACK, Color.PINK,};
 
 JButton button;
 
 public ButtonDemo() {
  super(new BorderLayout());
  
  button = new JButton(buttonLabels[buttonLabelIndex]);
 
  if(USE_CROSS_PLATFORM_UI) {
  button.setBackground(buttonColors[buttonLabelIndex]);
  } else {
  button.setForeground(buttonColors[buttonLabelIndex]);
  }
  
  button.addActionListener(this);
 
  
  this.add(button, BorderLayout.CENTER);
  
  this.setBorder(BorderFactory.createEmptyBorder(30,30,30,30));
 }
 
 public void actionPerformed(ActionEvent e) {
  buttonLabelIndex = ++buttonLabelIndex < frame =" new" contentpane =" new">

No comments:

Post a Comment